<commit_before>"""Module with all classes related to links.

Links are low level abstractions representing connections between two
interfaces.
"""

import json

from kytos.core.common import GenericEntity


class Link(GenericEntity):
    """Define a link between two Endpoints."""

    def __init__(self, endpoint_a, endpoint_b):
        """Create a Link instance and set its attributes."""
        self.endpoint_a = endpoint_a
        self.endpoint_b = endpoint_b
        super().__init__()

    def __eq__(self, other):
        """Check if two instances of Link are equal."""
        return (self.endpoint_a == other.endpoint_a and
                self.endpoint_b == other.endpoint_b)

    def as_dict(self):
        """Return the Link as a dictionary."""
        return {'endpoint_a': self.endpoint_a.as_dict(),
                'endpoint_b': self.endpoint_b.as_dict(),
                'metadata': self.metadata,
                'active': self.active,
                'enabled': self.enabled}

    def as_json(self):
        """Return the Link as a JSON string."""
        return json.dumps(self.as_dict())<commit_msg>Make links with the same endpoint equal<commit_after>"""Module with all classes related to links.

Links are low level abstractions representing connections between two
interfaces.
"""

import json

from kytos.core.common import GenericEntity


class Link(GenericEntity):
    """Define a link between two Endpoints."""

    def __init__(self, endpoint_a, endpoint_b):
        """Create a Link instance and set its attributes."""
        self.endpoint_a = endpoint_a
        self.endpoint_b = endpoint_b
        super().__init__()

    def __eq__(self, other):
        """Check if two instances of Link are equal."""
        return ((self.endpoint_a == other.endpoint_a and
                 self.endpoint_b == other.endpoint_b) or
                (self.endpoint_a == other.endpoint_b and
                 self.endpoint_b == other.endpoint_a))


    def as_dict(self):
        """Return the Link as a dictionary."""
        return {'endpoint_a': self.endpoint_a.as_dict(),
                'endpoint_b': self.endpoint_b.as_dict(),
                'metadata': self.metadata,
                'active': self.active,
                'enabled': self.enabled}

    def as_json(self):
        """Return the Link as a JSON string."""
        return json.dumps(self.as_dict())
{'fraction_non_alphanumeric': 0.10822147651006711, 'fraction_numerical': 0.0, 'mean_word_length': 2.5073529411764706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4357443', 'n_tokens_mistral': 654, 'n_tokens_neox': 632, 'n_words': 201}