@Test public void hasParent() { EntityReference wiki = new EntityReference("wiki", EntityType.WIKI); EntityReference alice = new EntityReference("alice", EntityType.SPACE, wiki); EntityReference bob = new EntityReference("bob", EntityType.SPACE, alice); EntityReference carol = new EntityReference("carol", EntityType.DOCUMENT, bob); assertTrue(wiki.hasParent(null)); assertFalse(wiki.hasParent(wiki)); assertFalse(wiki.hasParent(alice)); assertFalse(alice.hasParent(null)); assertTrue(alice.hasParent(wiki)); assertFalse(alice.hasParent(alice)); assertFalse(alice.hasParent(bob)); assertFalse(alice.hasParent(carol)); assertTrue(bob.hasParent(wiki)); assertTrue(bob.hasParent(alice)); assertFalse(carol.hasParent(null)); assertTrue(carol.hasParent(wiki)); assertTrue(carol.hasParent(alice)); assertTrue(carol.hasParent(bob)); assertFalse(carol.hasParent(carol)); assertFalse(carol.hasParent(bob.removeParent(alice))); assertFalse(carol.hasParent(bob.removeParent(wiki))); }
public boolean hasParent(EntityReference expectedParent) { EntityReference actualParent = getParent(); if (actualParent == expectedParent) { return true; } while (actualParent != null && !actualParent.equals(expectedParent)) { actualParent = actualParent.getParent(); } return actualParent != null; }
EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { public boolean hasParent(EntityReference expectedParent) { EntityReference actualParent = getParent(); if (actualParent == expectedParent) { return true; } while (actualParent != null && !actualParent.equals(expectedParent)) { actualParent = actualParent.getParent(); } return actualParent != null; } }
EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { public boolean hasParent(EntityReference expectedParent) { EntityReference actualParent = getParent(); if (actualParent == expectedParent) { return true; } while (actualParent != null && !actualParent.equals(expectedParent)) { actualParent = actualParent.getParent(); } return actualParent != null; } 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> { public boolean hasParent(EntityReference expectedParent) { EntityReference actualParent = getParent(); if (actualParent == expectedParent) { return true; } while (actualParent != null && !actualParent.equals(expectedParent)) { actualParent = actualParent.getParent(); } return actualParent != null; } 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> { public boolean hasParent(EntityReference expectedParent) { EntityReference actualParent = getParent(); if (actualParent == expectedParent) { return true; } while (actualParent != null && !actualParent.equals(expectedParent)) { actualParent = actualParent.getParent(); } return actualParent != null; } 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);  }