Package com.saperion.common.lang.id
Class HierarchicalName
- java.lang.Object
-
- com.saperion.common.lang.id.StringId
-
- com.saperion.common.lang.id.HierarchicalName
-
public final class HierarchicalName extends StringId
A
HierarchicalNameis an immutable encapsulation that consists of hierarchical name elements connected by anelement separatorwhere the left-most element represents the top-most hierarchy level.The name elements are heavily restricted by a
regular expressionto 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 aHierarchicalNamewhich is compatible with theconstructor. So thisStringId.toString()-method is usable in business-logic and not only for debugging purposes.An instance of
HierarchicalNamecan be used in several threads concurrently.- Author:
- agz
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringELEMENT_REGEXThe regular expression of the name elements.static charELEMENT_SEPARATORThe character that separates the name elements.
-
Constructor Summary
Constructors Constructor Description HierarchicalName(java.lang.String name)Creates a hierarchical name based on its representation (asStringId.toString()would return).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HierarchicalNameadd(HierarchicalName hierarchicalName)Returns a newHierarchicalNamethat contains the name elements of thisHierarchicalNamefirst, followed by the name elements of the specifiedHierarchicalName.HierarchicalNameadd(java.lang.String name)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.intgetCountElements()Returns the count of name elements in thisHierarchicalName.HierarchicalNamegetPrefix(int elementPosition)Returns a prefix, i.e aHierarchicalNamethat contains the name elements of thisHierarchicalNamein the range of [0, the specified element position).HierarchicalNamegetSuffix(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.HierarchicalNamesubtractPrefix(HierarchicalName hierarchicalName)Returns a suffix of thisHierarchicalNameby subtracting the specified prefix.HierarchicalNamesubtractSuffix(HierarchicalName hierarchicalName)Returns a prefix of thisHierarchicalNameby subtracting the specified suffix.
-
-
-
Field Detail
-
ELEMENT_SEPARATOR
public static final char ELEMENT_SEPARATOR
The character that separates the name elements.- See Also:
- Constant Field Values
-
ELEMENT_REGEX
public static final java.lang.String ELEMENT_REGEX
The regular expression of the name elements.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HierarchicalName
public HierarchicalName(java.lang.String name)
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 Detail
-
getCountElements
public int getCountElements()
Returns the count of name elements in thisHierarchicalName.- Returns:
- the count of name elements in this
HierarchicalName
-
add
public HierarchicalName add(java.lang.String name)
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
public HierarchicalName add(HierarchicalName hierarchicalName)
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
public HierarchicalName getPrefix(int elementPosition)
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
public HierarchicalName subtractSuffix(HierarchicalName hierarchicalName)
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
public HierarchicalName getSuffix(int elementPosition)
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
public HierarchicalName subtractPrefix(HierarchicalName hierarchicalName)
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
public boolean startsWith(HierarchicalName hierarchicalName)
Returns whether thisHierarchicalNamestarts with the specifiedHierarchicalName. The specifiedHierarchicalNamemust not benull.- Parameters:
hierarchicalName- prefix to test- Returns:
- whether this
HierarchicalNamestarts with the specifiedHierarchicalName
-
endsWith
public boolean endsWith(HierarchicalName hierarchicalName)
Returns whether thisHierarchicalNameends with the specifiedHierarchicalName. The specifiedHierarchicalNamemust not benull.- Parameters:
hierarchicalName- suffix to test- Returns:
- whether this
HierarchicalNameends with the specifiedHierarchicalName
-
-