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 String
The regular expression of the name elements.static final char
The 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 newHierarchicalName
that contains the name elements of thisHierarchicalName
first, followed by the name elements of the specifiedHierarchicalName
.Returns a newHierarchicalName
that contains the name elements of thisHierarchicalName
first, followed by the name elements of the specified string representation.boolean
endsWith
(HierarchicalName hierarchicalName) Returns whether thisHierarchicalName
ends with the specifiedHierarchicalName
.int
Returns the count of name elements in thisHierarchicalName
.getPrefix
(int elementPosition) Returns a prefix, i.e aHierarchicalName
that contains the name elements of thisHierarchicalName
in the range of [0, the specified element position).getSuffix
(int elementPosition) Returns a suffix, i.e aHierarchicalName
that contains the name elements of thisHierarchicalName
in the range of [the specified element position,getCountElements()
).boolean
startsWith
(HierarchicalName hierarchicalName) Returns whether thisHierarchicalName
starts with the specifiedHierarchicalName
.subtractPrefix
(HierarchicalName hierarchicalName) Returns a suffix of thisHierarchicalName
by subtracting the specified prefix.subtractSuffix
(HierarchicalName hierarchicalName) Returns a prefix of thisHierarchicalName
by 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 benull
or empty. Every contained name element must not violate theelement name regular expression
.- Parameters:
name
- string-representation to create theHierarchicalName
from
-
-
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 newHierarchicalName
that contains the name elements of thisHierarchicalName
first, followed by the name elements of the specified string representation. The specified name must not benull
or empty. Every contained name element must not violate theelement name regular expression
.- Parameters:
name
- string-representation of name elements to add- Returns:
- new
HierarchicalName
that contains the name elements of thisHierarchicalName
first, followed by the name elements of the specified string representation
-
add
Returns a newHierarchicalName
that contains the name elements of thisHierarchicalName
first, followed by the name elements of the specifiedHierarchicalName
. The specifiedHierarchicalName
must not benull
.- Parameters:
hierarchicalName
-HierarchicalName
to add- Returns:
- new
HierarchicalName
that contains the name elements of thisHierarchicalName
first, followed by the name elements of the specifiedHierarchicalName
-
getPrefix
Returns a prefix, i.e aHierarchicalName
that contains the name elements of thisHierarchicalName
in 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
HierarchicalName
in the range of [0, the specified element position)
-
subtractSuffix
Returns a prefix of thisHierarchicalName
by subtracting the specified suffix. The specifiedHierarchicalName
must not benull
. ThisHierarchicalName
mustend with
the specifiedHierarchicalName
. There must be a remaining prefix, i.e. thisHierarchicalName
must not equal the specifiedHierarchicalName
.- Parameters:
hierarchicalName
- suffix to subtract- Returns:
- a prefix of this
HierarchicalName
by subtracting the specified suffix
-
getSuffix
Returns a suffix, i.e aHierarchicalName
that contains the name elements of thisHierarchicalName
in 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
HierarchicalName
in the range of [the specified element position,getCountElements()
)
-
subtractPrefix
Returns a suffix of thisHierarchicalName
by subtracting the specified prefix. The specifiedHierarchicalName
must not benull
. ThisHierarchicalName
muststart with
the specifiedHierarchicalName
. There must be a remaining suffix, i.e. thisHierarchicalName
must not equal the specifiedHierarchicalName
.- Parameters:
hierarchicalName
- prefix to subtract- Returns:
- a suffix of this
HierarchicalName
by subtracting the specified prefix
-
startsWith
Returns whether thisHierarchicalName
starts with the specifiedHierarchicalName
. The specifiedHierarchicalName
must not benull
.- Parameters:
hierarchicalName
- prefix to test- Returns:
- whether this
HierarchicalName
starts with the specifiedHierarchicalName
-
endsWith
Returns whether thisHierarchicalName
ends with the specifiedHierarchicalName
. The specifiedHierarchicalName
must not benull
.- Parameters:
hierarchicalName
- suffix to test- Returns:
- whether this
HierarchicalName
ends with the specifiedHierarchicalName
-