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
HierarchicalName
is an immutable encapsulation that consists of hierarchical name elements connected by anelement 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 aHierarchicalName
which is compatible with theconstructor
. So thisStringId.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ELEMENT_REGEX
The regular expression of the name elements.static char
ELEMENT_SEPARATOR
The 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 HierarchicalName
add(HierarchicalName hierarchicalName)
Returns a newHierarchicalName
that contains the name elements of thisHierarchicalName
first, followed by the name elements of the specifiedHierarchicalName
.HierarchicalName
add(java.lang.String name)
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
getCountElements()
Returns the count of name elements in thisHierarchicalName
.HierarchicalName
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).HierarchicalName
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
.HierarchicalName
subtractPrefix(HierarchicalName hierarchicalName)
Returns a suffix of thisHierarchicalName
by subtracting the specified prefix.HierarchicalName
subtractSuffix(HierarchicalName hierarchicalName)
Returns a prefix of thisHierarchicalName
by 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 benull
or empty. Every contained name element must not violate theelement name regular expression
.- Parameters:
name
- string-representation to create theHierarchicalName
from
-
-
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 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
public HierarchicalName add(HierarchicalName hierarchicalName)
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
public HierarchicalName 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). 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
public HierarchicalName subtractSuffix(HierarchicalName hierarchicalName)
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
public HierarchicalName 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()
). 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
public HierarchicalName subtractPrefix(HierarchicalName hierarchicalName)
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
public boolean startsWith(HierarchicalName hierarchicalName)
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
public boolean endsWith(HierarchicalName hierarchicalName)
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
-
-