@Test public void compareTo() { EntityReference reference = new EntityReference("f", EntityType.DOCUMENT, new EntityReference("e", EntityType.SPACE, new EntityReference("d", EntityType.WIKI))); EntityReference reference2 = new EntityReference("c", EntityType.DOCUMENT, new EntityReference("b", EntityType.SPACE, new EntityReference("a", EntityType.WIKI))); EntityReference reference3 = new EntityReference("c", EntityType.DOCUMENT, new EntityReference("a", EntityType.SPACE, new EntityReference("a", EntityType.WIKI))); EntityReference reference31 = new EntityReference("c", EntityType.DOCUMENT, new EntityReference("x", EntityType.SPACE, new EntityReference("a", EntityType.SPACE, new EntityReference("a", EntityType.WIKI)))); assertEquals(0, reference.compareTo(reference)); assertTrue(reference.compareTo(reference2) > 0); assertTrue(reference.compareTo(reference3) > 0); Map<String, Serializable> map1 = new HashMap<>(3); map1.put("param1", "a"); map1.put("param2", "b"); map1.put("param3", "c"); Map<String, Serializable> map2 = new HashMap<>(2); map2.put("param1", "a"); map2.put("param3", "c"); Map<String, Serializable> map3 = new HashMap<>(2); map3.put("param1", "b"); map3.put("param3", "c"); EntityReference reference4 = new EntityReference("c", EntityType.DOCUMENT, new EntityReference("a", EntityType.SPACE, new EntityReference("a", EntityType.WIKI)), map1); EntityReference reference5 = new EntityReference("c", EntityType.DOCUMENT, new EntityReference("a", EntityType.SPACE, new EntityReference("a", EntityType.WIKI)), map2); EntityReference reference6 = new EntityReference("c", EntityType.DOCUMENT, new EntityReference("a", EntityType.SPACE, new EntityReference("a", EntityType.WIKI)), map3); EntityReference reference61 = new EntityReference("c", EntityType.DOCUMENT, new EntityReference("x", EntityType.SPACE, new EntityReference("a", EntityType.SPACE, new EntityReference("a", EntityType.WIKI)), map3)); assertEquals(0, reference4.compareTo(reference4)); assertTrue(reference4.compareTo(reference5) > 0); assertTrue(reference4.compareTo(reference6) < 0); assertTrue(reference4.compareTo(reference61) < 0); List<EntityReference> list = new ArrayList<>(); list.add(reference); list.add(reference2); list.add(reference3); list.add(reference31); list.add(reference4); list.add(reference5); list.add(reference6); list.add(reference61); Collections.sort(list); assertSame(reference3, list.get(0)); assertSame(reference5, list.get(1)); assertSame(reference4, list.get(2)); assertSame(reference6, list.get(3)); assertSame(reference31, list.get(4)); assertSame(reference61, list.get(5)); assertSame(reference2, list.get(6)); assertSame(reference, list.get(7)); }
@Override public int compareTo(EntityReference reference) { if (reference == null) { throw new NullPointerException("Provided reference should not be null"); } if (reference == this) { return 0; } int stringCompareResult = toString().compareTo(reference.toString()); if (stringCompareResult != 0) { return stringCompareResult; } return compareParameters(reference); }
EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { @Override public int compareTo(EntityReference reference) { if (reference == null) { throw new NullPointerException("Provided reference should not be null"); } if (reference == this) { return 0; } int stringCompareResult = toString().compareTo(reference.toString()); if (stringCompareResult != 0) { return stringCompareResult; } return compareParameters(reference); } }
EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { @Override public int compareTo(EntityReference reference) { if (reference == null) { throw new NullPointerException("Provided reference should not be null"); } if (reference == this) { return 0; } int stringCompareResult = toString().compareTo(reference.toString()); if (stringCompareResult != 0) { return stringCompareResult; } return compareParameters(reference); } EntityReference(EntityReference reference);  EntityReference(EntityReference reference, EntityReference parent); protected  EntityReference(EntityReference reference, EntityReference oldReference, EntityReference newReference);  EntityReference(String name, EntityType type);  EntityReference(String name, EntityType type, EntityReference parent); @Unstable  EntityReference(String name, EntityType type, Map<String, Serializable> parameters);  EntityReference(String name, EntityType type, EntityReference parent, Map<String, Serializable> parameters); @Unstable  EntityReference(EntityReference reference, Map<String, Serializable> parameters); }
EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { @Override public int compareTo(EntityReference reference) { if (reference == null) { throw new NullPointerException("Provided reference should not be null"); } if (reference == this) { return 0; } int stringCompareResult = toString().compareTo(reference.toString()); if (stringCompareResult != 0) { return stringCompareResult; } return compareParameters(reference); } EntityReference(EntityReference reference);  EntityReference(EntityReference reference, EntityReference parent); protected  EntityReference(EntityReference reference, EntityReference oldReference, EntityReference newReference);  EntityReference(String name, EntityType type);  EntityReference(String name, EntityType type, EntityReference parent); @Unstable  EntityReference(String name, EntityType type, Map<String, Serializable> parameters);  EntityReference(String name, EntityType type, EntityReference parent, Map<String, Serializable> parameters); @Unstable  EntityReference(EntityReference reference, Map<String, Serializable> parameters); final String getName(); final EntityReference getParent(); final EntityType getType(); final Map<String, Serializable> getParameters(); @Transient EntityReference getRoot(); @Transient List<EntityReference> getReversedReferenceChain(); int size(); EntityReference extractReference(EntityType type); EntityReference extractFirstReference(EntityType type); EntityReference replaceParent(EntityReference oldParent, EntityReference newParent); EntityReference replaceParent(EntityReference newParent); EntityReference appendParent(EntityReference newParent); EntityReference removeParent(EntityReference oldParent); boolean hasParent(EntityReference expectedParent); @Override String toString(); @Override boolean equals(Object obj); boolean equals(EntityReference otherReference, EntityType to); boolean equals(EntityReference otherReference, EntityType from, EntityType to); boolean equalsNonRecursive(EntityReference otherReference); @Override int hashCode(); @Override int compareTo(EntityReference reference); }
EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { @Override public int compareTo(EntityReference reference) { if (reference == null) { throw new NullPointerException("Provided reference should not be null"); } if (reference == this) { return 0; } int stringCompareResult = toString().compareTo(reference.toString()); if (stringCompareResult != 0) { return stringCompareResult; } return compareParameters(reference); } EntityReference(EntityReference reference);  EntityReference(EntityReference reference, EntityReference parent); protected  EntityReference(EntityReference reference, EntityReference oldReference, EntityReference newReference);  EntityReference(String name, EntityType type);  EntityReference(String name, EntityType type, EntityReference parent); @Unstable  EntityReference(String name, EntityType type, Map<String, Serializable> parameters);  EntityReference(String name, EntityType type, EntityReference parent, Map<String, Serializable> parameters); @Unstable  EntityReference(EntityReference reference, Map<String, Serializable> parameters); final String getName(); final EntityReference getParent(); final EntityType getType(); final Map<String, Serializable> getParameters(); @Transient EntityReference getRoot(); @Transient List<EntityReference> getReversedReferenceChain(); int size(); EntityReference extractReference(EntityType type); EntityReference extractFirstReference(EntityType type); EntityReference replaceParent(EntityReference oldParent, EntityReference newParent); EntityReference replaceParent(EntityReference newParent); EntityReference appendParent(EntityReference newParent); EntityReference removeParent(EntityReference oldParent); boolean hasParent(EntityReference expectedParent); @Override String toString(); @Override boolean equals(Object obj); boolean equals(EntityReference otherReference, EntityType to); boolean equals(EntityReference otherReference, EntityType from, EntityType to); boolean equalsNonRecursive(EntityReference otherReference); @Override int hashCode(); @Override int compareTo(EntityReference reference);  }