public class EntityReference extends Object implements Serializable, Cloneable, Comparable<EntityReference>
Modifier and Type | Field and Description |
---|---|
protected static org.xwiki.model.internal.reference.LocalizedStringEntityReferenceSerializer |
TOSTRING_SERIALIZER
Used to provide a nice and readable pretty name for the
toString() method. |
Modifier | Constructor and Description |
---|---|
|
EntityReference(EntityReference reference)
Clone an EntityReference.
|
|
EntityReference(EntityReference reference,
EntityReference parent)
Clone an EntityReference, but use the specified parent for its new parent.
|
protected |
EntityReference(EntityReference reference,
EntityReference oldReference,
EntityReference newReference)
Clone an EntityReference, but replace one of the parent in the chain by an other one.
|
|
EntityReference(EntityReference reference,
Map<String,Serializable> parameters)
Clone an EntityReference, but use the specified paramaters.
|
|
EntityReference(String name,
EntityType type)
Create a new root EntityReference.
|
|
EntityReference(String name,
EntityType type,
EntityReference parent)
Create a new EntityReference.
|
|
EntityReference(String name,
EntityType type,
EntityReference parent,
Map<String,Serializable> parameters)
Create a new EntityReference.
|
|
EntityReference(String name,
EntityType type,
Map<String,Serializable> parameters)
Create a new EntityReference.
|
Modifier and Type | Method and Description |
---|---|
EntityReference |
appendParent(EntityReference newParent)
Return a clone of this reference with a parent appended at the root of its parents chain.
|
int |
compareTo(EntityReference reference) |
boolean |
equals(EntityReference otherReference,
EntityType to)
Compared the two reference between the first reference and the last (including)
to type of entity. |
boolean |
equals(EntityReference otherReference,
EntityType from,
EntityType to)
Compared the two reference between the first (including)
from type of entity and the last
(including) to type of entity. |
boolean |
equals(Object obj) |
boolean |
equalsNonRecursive(EntityReference otherReference)
Same as
equals(Object) but only the first level of the references (ignore parents). |
EntityReference |
extractFirstReference(EntityType type)
Extract the first entity of the given type from this one by traversing the current entity to the root.
|
EntityReference |
extractReference(EntityType type)
Extract the last entity of the given type from this one by traversing the current entity to the root.
|
String |
getName()
Returns the name of this entity.
|
protected <T> T |
getParameter(String name)
Get the value of a parameter.
|
Map<String,Serializable> |
getParameters()
Get the parameters.
|
EntityReference |
getParent() |
List<EntityReference> |
getReversedReferenceChain() |
EntityReference |
getRoot() |
EntityType |
getType()
Returns the type of this entity.
|
int |
hashCode() |
boolean |
hasParent(EntityReference expectedParent)
Checks if a given reference is a parent of this reference.
|
EntityReference |
removeParent(EntityReference oldParent)
Return a clone of this reference truncated to a null parent when it reach the given parent.
|
EntityReference |
replaceParent(EntityReference newParent)
Return a clone of this reference, but with its parent replaced by the passed one.
|
EntityReference |
replaceParent(EntityReference oldParent,
EntityReference newParent)
Return a clone of this reference, but with one of its parent replaced by another one.
|
protected void |
setName(String name)
Entity reference are immutable since 3.3M2, so this method is now protected.
|
protected void |
setParameter(String name,
Serializable value)
Add or set a parameter value.
|
protected void |
setParameters(Map<String,Serializable> parameters)
Set multiple parameters at once.
|
protected void |
setParent(EntityReference parent)
Entity reference are immutable since 3.3M2, so this method is now protected.
|
protected void |
setType(EntityType type)
Entity reference are immutable since 3.3M2, so this method is now protected.
|
int |
size() |
String |
toString() |
protected static final org.xwiki.model.internal.reference.LocalizedStringEntityReferenceSerializer TOSTRING_SERIALIZER
toString()
method.public EntityReference(EntityReference reference)
reference
- the reference to clonepublic EntityReference(EntityReference reference, EntityReference parent)
reference
- the reference to cloneparent
- the new parent to useprotected EntityReference(EntityReference reference, EntityReference oldReference, EntityReference newReference)
reference
- the reference that is clonedoldReference
- the old parent that will be replacednewReference
- the new parent that will replace oldReference in the chainpublic EntityReference(String name, EntityType type)
name
- name for the newly created entity reference, could not be null.type
- type for the newly created entity reference, could not be null.public EntityReference(String name, EntityType type, EntityReference parent)
name
- name for the newly created entity reference, could not be null.type
- type for the newly created entity reference, could not be null.parent
- parent reference for the newly created entity reference, may be null.public EntityReference(String name, EntityType type, Map<String,Serializable> parameters)
name
- name for the newly created entity, could not be null.type
- type for the newly created entity, could not be null.parameters
- parameters for this reference, may be nullpublic EntityReference(String name, EntityType type, EntityReference parent, Map<String,Serializable> parameters)
name
- name for the newly created entity, could not be null.type
- type for the newly created entity, could not be null.parent
- parent reference for the newly created entity reference, may be null.parameters
- parameters for this reference, may be nullpublic EntityReference(EntityReference reference, Map<String,Serializable> parameters)
reference
- the reference to cloneparameters
- parameters for this reference, may be nullprotected void setName(String name)
name
- the name for this entityIllegalArgumentException
- if the passed name is null or emptypublic final String getName()
protected void setParent(EntityReference parent)
parent
- the parent for this entity, may be null for a root entity.public final EntityReference getParent()
protected void setType(EntityType type)
type
- the type for this entityIllegalArgumentException
- if the passed type is nullpublic final EntityType getType()
protected void setParameters(Map<String,Serializable> parameters)
parameters
- the map of parameter to setprotected void setParameter(String name, Serializable value)
name
- the name of the parametervalue
- the value of the parameterprotected final <T> T getParameter(String name)
T
- the type of the value of the requested parametername
- the name of the parameter to getpublic final Map<String,Serializable> getParameters()
public EntityReference getRoot()
public List<EntityReference> getReversedReferenceChain()
public int size()
EntityReference
public EntityReference extractReference(EntityType type)
type
- the type of the entity to be extractedpublic EntityReference extractFirstReference(EntityType type)
type
- the type of the entity to be extractedpublic EntityReference replaceParent(EntityReference oldParent, EntityReference newParent)
oldParent
- the old parent that will be replacednewParent
- the new parent that will replace oldParent in the chain. If the same as oldParent, this is
returned.public EntityReference replaceParent(EntityReference newParent)
newParent
- the new parent that will replace the parentpublic EntityReference appendParent(EntityReference newParent)
newParent
- the parent that became the root parent of this reference (and its parent). If null, this is
returned.public EntityReference removeParent(EntityReference oldParent)
oldParent
- the parent that will be replaced by a null. If null, this is returned.public boolean hasParent(EntityReference expectedParent)
expectedParent
- the parent reference to checktrue
if the given reference is a parent of this reference, false
otherwisepublic boolean equals(EntityReference otherReference, EntityType to)
to
type of entity.
For example if you want to make sure some local document matches some complete document reference you can so it with localDocumentReference.equals(documentReference, EntityType.SPACE).
otherReference
- the reference to compareto
- the type of the the last (including) entity reference to comparepublic boolean equals(EntityReference otherReference, EntityType from, EntityType to)
from
type of entity and the last
(including) to
type of entity.otherReference
- the reference to comparefrom
- the type of the first (including) entity reference to compareto
- the type of the the last (including) entity reference to comparepublic boolean equalsNonRecursive(EntityReference otherReference)
equals(Object)
but only the first level of the references (ignore parents).otherReference
- the reference to comparepublic int compareTo(EntityReference reference)
Note: The default implementation relies on comparing the string serialization of the 2 entities. It is the caller's responsibility to make sure that the entities are either first resolved or at least of the same type, in order for the comparison to actually make sense.
compareTo
in interface Comparable<EntityReference>
Comparable.compareTo(java.lang.Object)
Copyright © 2004–2021 XWiki. All rights reserved.