@Test public void extractReference() { EntityReference wiki = new EntityReference("wiki", EntityType.WIKI); EntityReference space1 = new EntityReference("space1", EntityType.SPACE, wiki); EntityReference space2 = new EntityReference("space2", EntityType.SPACE, space1); EntityReference reference = new EntityReference("page", EntityType.DOCUMENT, space2); assertSame(wiki, reference.extractReference(EntityType.WIKI)); assertSame(space2, reference.extractReference(EntityType.SPACE)); assertSame(reference, reference.extractReference(EntityType.DOCUMENT)); assertNull(reference.extractReference(EntityType.ATTACHMENT)); }
public EntityReference extractReference(EntityType type) { EntityReference reference = this; while (reference != null && reference.getType() != type) { reference = reference.getParent(); } return reference; }
EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { public EntityReference extractReference(EntityType type) { EntityReference reference = this; while (reference != null && reference.getType() != type) { reference = reference.getParent(); } return reference; } }
EntityReference implements Serializable, Cloneable, Comparable<EntityReference> { public EntityReference extractReference(EntityType type) { EntityReference reference = this; while (reference != null && reference.getType() != type) { reference = reference.getParent(); } return 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> { public EntityReference extractReference(EntityType type) { EntityReference reference = this; while (reference != null && reference.getType() != type) { reference = reference.getParent(); } return 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> { public EntityReference extractReference(EntityType type) { EntityReference reference = this; while (reference != null && reference.getType() != type) { reference = reference.getParent(); } return 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);  }