Class CompoundName

java.lang.Object
com.yahoo.processing.request.CompoundName

public final class CompoundName extends Object
An immutable compound name of the general form "a.bb.ccc", where there can be any number of such compounds, including one or zero.

Using CompoundName is generally substantially faster than using strings.

Author:
bratseth
  • Field Details

    • empty

      public static final CompoundName empty
      The empty compound
  • Constructor Details

    • CompoundName

      public CompoundName(String name)
      Constructs this from a string which may contains dot-separated components
      Throws:
      NullPointerException - if name is null
    • CompoundName

      public CompoundName(List<String> compounds)
      Constructs this from a list of compounds.
  • Method Details

    • fromComponents

      public static CompoundName fromComponents(String... components)
      Constructs this from an array of name components which are assumed not to contain dots
    • append

      public CompoundName append(String name)
      Returns a compound name which has the given compound string appended to it
      Parameters:
      name - if name is empty this returns this
    • append

      public CompoundName append(CompoundName name)
      Returns a compound name which has the given compounds appended to it
      Parameters:
      name - if name is empty this returns this
    • prepend

      public CompoundName prepend(String... nameParts)
      Returns a compound name which has the given name components prepended to this name, in the given order, i.e new ComponentName("c").prepend("a","b") will yield "a.b.c".
      Parameters:
      nameParts - if name is empty this returns this
    • last

      public String last()
      Returns the name after the last dot. If there are no dots, the full name is returned.
    • first

      public String first()
      Returns the name before the first dot. If there are no dots the full name is returned.
    • first

      public CompoundName first(int n)
      Returns the first n components of this.
      Throws:
      IllegalArgumentException - if this does not have at least n components
    • rest

      public CompoundName rest()
      Returns the name after the first dot, or "" if this name has no dots
    • rest

      public CompoundName rest(int n)
      Returns the name starting after the n first components (i.e dots). This may be the empty name.
      Throws:
      IllegalArgumentException - if this does not have at least that many components
    • size

      public int size()
      Returns the number of compound elements in this. Which is exactly the number of dots in the string plus one. The size of an empty compound is 0.
    • get

      public String get(int i)
      Returns the compound element as the given index
    • set

      public CompoundName set(int i, String name)
      Returns a compound which have the name component at index i set to the given name. As an optimization, if the given name == the name component at this index, this is returned.
    • isCompound

      public boolean isCompound()
      Returns whether this name has more than one element
    • isEmpty

      public boolean isEmpty()
    • hasPrefix

      public boolean hasPrefix(CompoundName prefix)
      Returns whether the given name is a prefix of this. Prefixes are taken on the component, not character level, so "a" is a prefix of "a.b", but not a prefix of "ax.b
    • asList

      public List<String> asList()
      Returns an immutable list of the components of this
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object arg)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Returns the string representation of this - all the name components in order separated by dots.
      Overrides:
      toString in class Object
    • getLowerCasedName

      public String getLowerCasedName()
    • from

      public static CompoundName from(String name)