Class ServicePath

java.lang.Object
com.github.cafapi.common.util.naming.ServicePath
All Implemented Interfaces:
Iterable<String>

public final class ServicePath extends Object implements Iterable<String>
Simple object to store the service path, expected to be in the form /group/subgroup/id. Internally this is represented by a javax.naming.Name object. Any leading or terminating forward-slashes are removed upon creation. Valid path: a/b/c Valid path: /a/b/c/ (leading and terminating slashes will be removed) Invalid path: /a/b//c/ (empty naming groups are not allowed) Invalid path: /a (no group)
  • Constructor Details

    • ServicePath

      public ServicePath(String path) throws InvalidNameException
      Create a new ServicePath from a String.
      Parameters:
      path - the String to create the ServicePath from
      Throws:
      InvalidNameException - if there are invalid characters, empty groups, or less than 2 components
  • Method Details

    • getRoot

      public String getRoot()
      Return the root of the service path, ie. the first group the service is a part of. In the service path "/a/b/c", this will be "a".
      Returns:
      the root of the service path
    • getLeaf

      public String getLeaf()
      Return the leaf or "tip" of the service path, ie. the final part of the service name. In the service path "/a/b/c", this will be "c".
      Returns:
      the leaf of the service path
    • getGroup

      public String getGroup()
      Return the immediate group of the service, ie. the node above the leaf. In the service path "/a/b/c", this will be "b".
      Returns:
      the immediate group of the service
    • getPath

      public Name getPath()
      Returns:
      the full service path
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the full service path, as a String
    • iterator

      public Iterator<String> iterator()
      Each iteration is the next element of the service path.
      Specified by:
      iterator in interface Iterable<String>
    • groupIterator

      public Iterator<String> groupIterator()
      Returns:
      an iterator that only iterates over the groups and subgroups of the service
    • descendingPathIterator

      public Iterator<Name> descendingPathIterator()
      Returns:
      an Iterator where each element is the entire service path up to the (decrementing) index