Package com.saperion.common.lang.id
Class HierarchicalName
java.lang.Object
com.saperion.common.lang.id.StringId
com.saperion.common.lang.id.HierarchicalName
- All Implemented Interfaces:
Id,Serializable,Comparable<StringId>
A HierarchicalName is an immutable encapsulation that consists of hierarchical name elements connected by an
element separator where the left-most element represents the top-most hierarchy level.
The name elements are heavily restricted by a regular expression to guarantee the usability of
this class in many different situations. They must consist of letters and numbers only (starting with a letter).
The StringId.toString()-method returns a full representation of a HierarchicalName which is compatible with
the constructor. So this StringId.toString() -method is usable in business-logic
and not only for debugging purposes.
An instance of HierarchicalName can be used in several threads concurrently.
- Author:
- agz
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe regular expression of the name elements.static final charThe character that separates the name elements. -
Constructor Summary
ConstructorsConstructorDescriptionHierarchicalName(String name) Creates a hierarchical name based on its representation (asStringId.toString()would return). -
Method Summary
Modifier and TypeMethodDescriptionadd(HierarchicalName hierarchicalName) Returns a newHierarchicalNamethat contains the name elements of thisHierarchicalNamefirst, followed by the name elements of the specifiedHierarchicalName.Returns a newHierarchicalNamethat contains the name elements of thisHierarchicalNamefirst, followed by the name elements of the specified string representation.booleanendsWith(HierarchicalName hierarchicalName) Returns whether thisHierarchicalNameends with the specifiedHierarchicalName.intReturns the count of name elements in thisHierarchicalName.getPrefix(int elementPosition) Returns a prefix, i.e aHierarchicalNamethat contains the name elements of thisHierarchicalNamein the range of [0, the specified element position).getSuffix(int elementPosition) Returns a suffix, i.e aHierarchicalNamethat contains the name elements of thisHierarchicalNamein the range of [the specified element position,getCountElements()).booleanstartsWith(HierarchicalName hierarchicalName) Returns whether thisHierarchicalNamestarts with the specifiedHierarchicalName.subtractPrefix(HierarchicalName hierarchicalName) Returns a suffix of thisHierarchicalNameby subtracting the specified prefix.subtractSuffix(HierarchicalName hierarchicalName) Returns a prefix of thisHierarchicalNameby subtracting the specified suffix.
-
Field Details
-
ELEMENT_SEPARATOR
public static final char ELEMENT_SEPARATORThe character that separates the name elements.- See Also:
-
ELEMENT_REGEX
The regular expression of the name elements.- See Also:
-
-
Constructor Details
-
HierarchicalName
Creates a hierarchical name based on its representation (asStringId.toString()would return). The specified name must not benullor empty. Every contained name element must not violate theelement name regular expression.- Parameters:
name- string-representation to create theHierarchicalNamefrom
-
-
Method Details
-
getCountElements
public int getCountElements()Returns the count of name elements in thisHierarchicalName.- Returns:
- the count of name elements in this
HierarchicalName
-
add
Returns a newHierarchicalNamethat contains the name elements of thisHierarchicalNamefirst, followed by the name elements of the specified string representation. The specified name must not benullor empty. Every contained name element must not violate theelement name regular expression.- Parameters:
name- string-representation of name elements to add- Returns:
- new
HierarchicalNamethat contains the name elements of thisHierarchicalNamefirst, followed by the name elements of the specified string representation
-
add
Returns a newHierarchicalNamethat contains the name elements of thisHierarchicalNamefirst, followed by the name elements of the specifiedHierarchicalName. The specifiedHierarchicalNamemust not benull.- Parameters:
hierarchicalName-HierarchicalNameto add- Returns:
- new
HierarchicalNamethat contains the name elements of thisHierarchicalNamefirst, followed by the name elements of the specifiedHierarchicalName
-
getPrefix
Returns a prefix, i.e aHierarchicalNamethat contains the name elements of thisHierarchicalNamein the range of [0, the specified element position). The specified element position must be in the range [1,getCountElements()]- Parameters:
elementPosition- end position of the prefix to return- Returns:
- prefix that contains the name elements of this
HierarchicalNamein the range of [0, the specified element position)
-
subtractSuffix
Returns a prefix of thisHierarchicalNameby subtracting the specified suffix. The specifiedHierarchicalNamemust not benull. ThisHierarchicalNamemustend withthe specifiedHierarchicalName. There must be a remaining prefix, i.e. thisHierarchicalNamemust not equal the specifiedHierarchicalName.- Parameters:
hierarchicalName- suffix to subtract- Returns:
- a prefix of this
HierarchicalNameby subtracting the specified suffix
-
getSuffix
Returns a suffix, i.e aHierarchicalNamethat contains the name elements of thisHierarchicalNamein the range of [the specified element position,getCountElements()). The specified element position must be in the range [0,getCountElements()- 1]- Parameters:
elementPosition- start position of the suffix to return- Returns:
- suffix that contains the name elements of this
HierarchicalNamein the range of [the specified element position,getCountElements())
-
subtractPrefix
Returns a suffix of thisHierarchicalNameby subtracting the specified prefix. The specifiedHierarchicalNamemust not benull. ThisHierarchicalNamemuststart withthe specifiedHierarchicalName. There must be a remaining suffix, i.e. thisHierarchicalNamemust not equal the specifiedHierarchicalName.- Parameters:
hierarchicalName- prefix to subtract- Returns:
- a suffix of this
HierarchicalNameby subtracting the specified prefix
-
startsWith
Returns whether thisHierarchicalNamestarts with the specifiedHierarchicalName. The specifiedHierarchicalNamemust not benull.- Parameters:
hierarchicalName- prefix to test- Returns:
- whether this
HierarchicalNamestarts with the specifiedHierarchicalName
-
endsWith
Returns whether thisHierarchicalNameends with the specifiedHierarchicalName. The specifiedHierarchicalNamemust not benull.- Parameters:
hierarchicalName- suffix to test- Returns:
- whether this
HierarchicalNameends with the specifiedHierarchicalName
-