Class NodeName

java.lang.Object
org.moera.lib.naming.NodeName

public class NodeName extends Object
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
    Constructor
    Description
    Default constructor for the NodeName class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    expand(String nodeName)
    Expands the provided node name into its full representation.
    int
    Retrieves the generation part of the node name.
    Retrieves the name part of the node name.
    static NodeName
    parse(String nodeName)
    Parses the provided node name string into a NodeName object.
    void
    setGeneration(int generation)
    Sets the generation part of the node name.
    void
    Sets the name part of the node name.
    static String
    shorten(String nodeName)
    Shortens the given node name by removing its generation if it is zero, retaining only the main name component.
    Converts the current NodeName instance to a shortened string representation.
    Generates a string representation of this NodeName object by combining the name and generation in the format "<name>_<generation>".
    static String
    toString(String name, int generation)
    Generates a string representation of a name and its generation in the format "<name>_<generation>".

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • NodeName

      public NodeName()
      Default constructor for the NodeName class.
  • Method Details

    • parse

      public static NodeName parse(String nodeName)
      Parses the provided node name string into a NodeName object. The input node name is expected to follow the format "<name>_<generation>". If the input is null or empty, an empty NodeName object is returned.
      Parameters:
      nodeName - the string representation of the node name to be parsed, in the format "<name>_<generation>". The generation 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

      public static String shorten(String nodeName)
      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 be null or empty
      Returns:
      a shortened version of the node name, or the original input if the node name is null or empty.
    • expand

      public static String expand(String nodeName)
      Expands the provided node name into its full representation.
      Parameters:
      nodeName - the node name to be expanded in the format "<name>_<generation>", where generation part is optional
      Returns:
      the expanded full representation of the node name, or the original input if it is null or empty.
    • getName

      public String getName()
      Retrieves the name part of the node name.
      Returns:
      the name
    • setName

      public void setName(String name)
      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

      public String toString()
      Generates a string representation of this NodeName object by combining the name and generation in the format "<name>_<generation>".
      Overrides:
      toString in class Object
      Returns:
      a string representation of this NodeName, or null if the name is null.
    • toShortString

      public String toShortString()
      Converts the current NodeName instance to a shortened string representation. If the generation is non-zero, the result will be the full string representation (e.g., "<name>_<generation>"). Otherwise, it will return only the name.
      Returns:
      a shortened string representation of the node name
    • toString

      public static String toString(String name, int generation)
      Generates a string representation of a name and its generation in the format "<name>_<generation>". If the name is null, the method returns null.
      Parameters:
      name - the name to be included in the string representation; may be null
      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 is null