From de1bb75c564e63307990024812381407504bc38e Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 20 Jan 2023 17:49:19 +0100 Subject: [PATCH] LinkedEntity is now comparable --- .../impl/properties/LinkedEntityImpl.java | 44 +++++++++++++++++++ .../reference/properties/LinkedEntity.java | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/informationsystem/types/impl/properties/LinkedEntityImpl.java b/src/main/java/org/gcube/informationsystem/types/impl/properties/LinkedEntityImpl.java index 2b67e5f..dc50bc5 100644 --- a/src/main/java/org/gcube/informationsystem/types/impl/properties/LinkedEntityImpl.java +++ b/src/main/java/org/gcube/informationsystem/types/impl/properties/LinkedEntityImpl.java @@ -117,4 +117,48 @@ public final class LinkedEntityImpl extends PropertyElementImpl implements Linke Objects.equals(description, other.description); } + + @Override + public int compareTo(LinkedEntity other) { + if (this == other) { + return 0; + } + if (other == null) { + return -1; + } + if (getClass() != other.getClass()) { + return -1; + } + + LinkedEntityImpl o = (LinkedEntityImpl) other; + + int ret = 0; + ret = source.compareTo(o.source); + if(ret != 0) { + return ret; + } + + ret = relation.compareTo(o.relation); + if(ret != 0) { + return ret; + } + + ret = target.compareTo(o.target); + if(ret != 0) { + return ret; + } + + ret = max.compareTo(o.max); + if(ret != 0) { + return ret; + } + + ret = min.compareTo(o.min); + if(ret != 0) { + return ret; + } + + return description.compareTo(o.description); + + } } diff --git a/src/main/java/org/gcube/informationsystem/types/reference/properties/LinkedEntity.java b/src/main/java/org/gcube/informationsystem/types/reference/properties/LinkedEntity.java index acf10ca..bcbbe25 100644 --- a/src/main/java/org/gcube/informationsystem/types/reference/properties/LinkedEntity.java +++ b/src/main/java/org/gcube/informationsystem/types/reference/properties/LinkedEntity.java @@ -18,7 +18,7 @@ import org.gcube.informationsystem.utils.Version; @JsonDeserialize(as=LinkedEntityImpl.class) @TypeMetadata(name = LinkedEntity.NAME, description = " A convenient type to define a Resource in terms of: mandatory/recommended ConsistsOf->Facets; suggested IsRelatedTo->Resource.", version = Version.MINIMAL_VERSION_STRING) @Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION) -public interface LinkedEntity extends PropertyElement { +public interface LinkedEntity extends PropertyElement, Comparable { public static final String NAME = "LinkedEntity"; // LinkedEntity.class.getSimpleName();