Package org.moera.lib.naming
Class NodeName
java.lang.Object
org.moera.lib.naming.NodeName
Represents a node name that consists of a name and its generation. This
class provides utility methods for parsing, shortening, and expanding node names.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Expands the provided node name into its full representation.int
Retrieves the generation part of the node name.getName()
Retrieves the name part of the node name.static NodeName
Parses the provided node name string into aNodeName
object.void
setGeneration
(int generation) Sets the generation part of the node name.void
Sets the name part of the node name.static String
Shortens the given node name by removing its generation if it is zero, retaining only the main name component.Converts the currentNodeName
instance to a shortened string representation.toString()
Generates a string representation of thisNodeName
object by combining the name and generation in the format"<name>_<generation>"
.static String
Generates a string representation of a name and its generation in the format"<name>_<generation>"
.
-
Constructor Details
-
NodeName
public NodeName()Default constructor for theNodeName
class.
-
-
Method Details
-
parse
Parses the provided node name string into aNodeName
object. The input node name is expected to follow the format"<name>_<generation>"
. If the input isnull
or empty, an emptyNodeName
object is returned.- Parameters:
nodeName
- the string representation of the node name to be parsed, in the format"<name>_<generation>"
. Thegeneration
part is optional and defaults to 0 if not present.- Returns:
- a
NodeName
object - Throws:
NodeNameParsingException
- if the generation part of the node name is not a valid integer
-
shorten
Shortens the given node name by removing its generation if it is zero, retaining only the main name component.- Parameters:
nodeName
- the node name in the format"<name>_<generation>"
; can benull
or empty- Returns:
- a shortened version of the node name, or the original input if the node name is
null
or empty.
-
expand
Expands the provided node name into its full representation.- Parameters:
nodeName
- the node name to be expanded in the format"<name>_<generation>"
, wheregeneration
part is optional- Returns:
- the expanded full representation of the node name, or the original
input if it is
null
or empty.
-
getName
Retrieves the name part of the node name.- Returns:
- the name
-
setName
Sets the name part of the node name.- Parameters:
name
- the name to be set
-
getGeneration
public int getGeneration()Retrieves the generation part of the node name.- Returns:
- the generation
-
setGeneration
public void setGeneration(int generation) Sets the generation part of the node name.- Parameters:
generation
- the generation to be set
-
toString
Generates a string representation of thisNodeName
object by combining the name and generation in the format"<name>_<generation>"
. -
toShortString
Converts the currentNodeName
instance to a shortened string representation. If thegeneration
is non-zero, the result will be the full string representation (e.g.,"<name>_<generation>"
). Otherwise, it will return only thename
.- Returns:
- a shortened string representation of the node name
-
toString
Generates a string representation of a name and its generation in the format"<name>_<generation>"
. If the name isnull
, the method returnsnull
.- Parameters:
name
- the name to be included in the string representation; may benull
generation
- the generation to be included in the string representation- Returns:
- a formatted string combining the name and generation, or
null
if the input name isnull
-