Permalink
Please sign in to comment.
Browse files
Tidied-up Entity and Attribute classes - made immutable value objects…
…, added toString.
- Loading branch information...
Showing
with
56 additions
and 16 deletions.
| @@ -1,26 +1,50 @@ | ||
| package org.monarchinitiative.owlsim.model.kb; | ||
| +import java.util.Objects; | ||
| + | ||
| /** | ||
| * @author cjm | ||
| * | ||
| */ | ||
| public class Attribute implements SimpleObject { | ||
| - private String id; | ||
| - private String label; | ||
| + private final String id; | ||
| + private final String label; | ||
| public Attribute(String id, String label) { | ||
| - super(); | ||
| this.id = id; | ||
| this.label = label; | ||
| } | ||
| + @Override | ||
| public String getId() { | ||
| return id; | ||
| } | ||
| + @Override | ||
| public String getLabel() { | ||
| return label; | ||
| } | ||
| - | ||
| + | ||
| + @Override | ||
| + public boolean equals(Object o) { | ||
| + if (this == o) return true; | ||
| + if (o == null || getClass() != o.getClass()) return false; | ||
| + Attribute attribute = (Attribute) o; | ||
| + return Objects.equals(id, attribute.id) && | ||
| + Objects.equals(label, attribute.label); | ||
| + } | ||
| + | ||
| + @Override | ||
| + public int hashCode() { | ||
| + return Objects.hash(id, label); | ||
| + } | ||
| + | ||
| + @Override | ||
| + public String toString() { | ||
| + return "Attribute{" + | ||
| + "id='" + id + '\'' + | ||
| + ", label='" + label + '\'' + | ||
| + '}'; | ||
| + } | ||
| } |
| @@ -1,34 +1,50 @@ | ||
| package org.monarchinitiative.owlsim.model.kb; | ||
| +import java.util.Objects; | ||
| + | ||
| /** | ||
| * @author cjm | ||
| * | ||
| */ | ||
| public class Entity implements SimpleObject { | ||
| - private String id; | ||
| - private String label; | ||
| + private final String id; | ||
| + private final String label; | ||
| public Entity(String id, String label) { | ||
| - super(); | ||
| this.id = id; | ||
| this.label = label; | ||
| } | ||
| - public void setId(String id) { | ||
| - this.id = id; | ||
| - } | ||
| - | ||
| - public void setLabel(String label) { | ||
| - this.label = label; | ||
| - } | ||
| - | ||
| + @Override | ||
| public String getId() { | ||
| return id; | ||
| } | ||
| + @Override | ||
| public String getLabel() { | ||
| return label; | ||
| } | ||
| - | ||
| + | ||
| + @Override | ||
| + public boolean equals(Object o) { | ||
| + if (this == o) return true; | ||
| + if (o == null || getClass() != o.getClass()) return false; | ||
| + Entity entity = (Entity) o; | ||
| + return Objects.equals(id, entity.id) && | ||
| + Objects.equals(label, entity.label); | ||
| + } | ||
| + | ||
| + @Override | ||
| + public int hashCode() { | ||
| + return Objects.hash(id, label); | ||
| + } | ||
| + | ||
| + @Override | ||
| + public String toString() { | ||
| + return "Entity{" + | ||
| + "id='" + id + '\'' + | ||
| + ", label='" + label + '\'' + | ||
| + '}'; | ||
| + } | ||
| } |
0 comments on commit
d2ecc80