commit e7995b670b4b89ddadee04541c1be5d11dfa50c3 Author: Michal Srb msrb@redhat.com Date: Wed Jul 23 08:06:59 2014 +0200
Implement __hash__(), __eq__() and __ne__() for Metadata classes
python/javapackages/metadata/alias.py | 21 +++++++++++++++++++ python/javapackages/metadata/artifact.py | 25 +++++++++++++++++++++++ python/javapackages/metadata/dependency.py | 25 +++++++++++++++++++++++ python/javapackages/metadata/exclusion.py | 17 +++++++++++++++ python/javapackages/metadata/skippedartifact.py | 21 +++++++++++++++++++ 5 files changed, 109 insertions(+), 0 deletions(-) --- diff --git a/python/javapackages/metadata/alias.py b/python/javapackages/metadata/alias.py index de26b0b..67b78e4 100644 --- a/python/javapackages/metadata/alias.py +++ b/python/javapackages/metadata/alias.py @@ -25,6 +25,27 @@ class MetadataAlias(object): a.extension = self.extension or None return a
+ def __hash__(self): + h = 87 + h += 15 + hash(self.groupId) + h += 25 + hash(self.artifactId) + h += 35 + hash(self.extension) + h += 45 + hash(self.classifier) + return h + + def __eq__(self, other): + if type(other) is not type(self): + return False + if (self.groupId == other.groupId and + self.artifactId == other.artifactId and + self.extension == other.extension and + self.classifier == other.classifier): + return True + return False + + def __ne__(self, other): + return not self.__eq__(other) + @classmethod def from_metadata(cls, metadata): groupId = metadata.groupId.strip() diff --git a/python/javapackages/metadata/artifact.py b/python/javapackages/metadata/artifact.py index a02bc65..463f113 100644 --- a/python/javapackages/metadata/artifact.py +++ b/python/javapackages/metadata/artifact.py @@ -80,6 +80,31 @@ class MetadataArtifact(object): def __str__(self): return self.__unicode__()
+ def __hash__(self): + h = 26 + h += 11 + hash(self.groupId) + h += 21 + hash(self.artifactId) + h += 31 + hash(self.extension) + h += 41 + hash(self.classifier) + h += 61 + hash(self.namespace) + h += 71 + hash(self.is_compat()) + return h + + def __eq__(self, other): + if type(other) is not type(self): + return False + if (self.groupId == other.groupId and + self.artifactId == other.artifactId and + self.extension == other.extension and + self.classifier == other.classifier and + self.namespace == other.namespace and + self.is_compat() == other.is_compat()): + return True + return False + + def __ne__(self, other): + return not self.__eq__(other) + def to_metadata(self): a = m.ArtifactMetadata() a.groupId = self.groupId diff --git a/python/javapackages/metadata/dependency.py b/python/javapackages/metadata/dependency.py index 31e763f..7d1fcb5 100644 --- a/python/javapackages/metadata/dependency.py +++ b/python/javapackages/metadata/dependency.py @@ -73,6 +73,31 @@ class MetadataDependency(object): def __str__(self): return self.__unicode__()
+ def __hash__(self): + h = 47 + h += 12 + hash(self.groupId) + h += 22 + hash(self.artifactId) + h += 32 + hash(self.extension) + h += 42 + hash(self.classifier) + h += 62 + hash(self.namespace) + h += 72 + hash(self.resolvedVersion) + return h + + def __eq__(self, other): + if type(other) is not type(self): + return False + if (self.groupId == other.groupId and + self.artifactId == other.artifactId and + self.extension == other.extension and + self.classifier == other.classifier and + self.namespace == other.namespace and + self.resolvedVersion == other.resolvedVersion): + return True + return False + + def __ne__(self, other): + return not self.__eq__(other) + @classmethod def from_metadata(cls, metadata): groupId = metadata.groupId.strip() diff --git a/python/javapackages/metadata/exclusion.py b/python/javapackages/metadata/exclusion.py index dda2b23..4ec563e 100644 --- a/python/javapackages/metadata/exclusion.py +++ b/python/javapackages/metadata/exclusion.py @@ -15,6 +15,23 @@ class MetadataExclusion(object): def to_metadata(self): return m.DependencyExclusion(self.groupId, self.artifactId)
+ def __hash__(self): + h = 67 + h += 13 + hash(self.groupId) + h += 23 + hash(self.artifactId) + return h + + def __eq__(self, other): + if type(other) is not type(self): + return False + if (self.groupId == other.groupId and + self.artifactId == other.artifactId): + return True + return False + + def __ne__(self, other): + return not self.__eq__(other) + @classmethod def from_metadata(cls, metadata): groupId = metadata.groupId.strip() diff --git a/python/javapackages/metadata/skippedartifact.py b/python/javapackages/metadata/skippedartifact.py index f762108..cbab0da 100644 --- a/python/javapackages/metadata/skippedartifact.py +++ b/python/javapackages/metadata/skippedartifact.py @@ -25,6 +25,27 @@ class MetadataSkippedArtifact(object): a.extension = self.artifact.extension or None return a
+ def __hash__(self): + h = 77 + h += 14 + hash(self.groupId) + h += 24 + hash(self.artifactId) + h += 34 + hash(self.extension) + h += 44 + hash(self.classifier) + return h + + def __eq__(self, other): + if type(other) is not type(self): + return False + if (self.groupId == other.groupId and + self.artifactId == other.artifactId and + self.extension == other.extension and + self.classifier == other.classifier): + return True + return False + + def __ne__(self, other): + return not self.__eq__(other) + @classmethod def from_metadata(cls, metadata): groupId = metadata.groupId.strip()
java-sig-commits@lists.fedoraproject.org