Class CompoundName


  • public final class CompoundName
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      static CompoundName empty
      The empty compound
    • Constructor Summary

      Constructors 
      Constructor Description
      CompoundName​(java.lang.String name)
      Constructs this from a string which may contains dot-separated components
      CompoundName​(java.util.List<java.lang.String> compounds)
      Constructs this from a list of compounds.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CompoundName append​(CompoundName name)
      Returns a compound name which has the given compounds appended to it
      CompoundName append​(java.lang.String name)
      Returns a compound name which has the given compound string appended to it
      java.util.List<java.lang.String> asList()
      Returns an immutable list of the components of this
      boolean equals​(java.lang.Object o)  
      java.lang.String first()
      Returns the name before the first dot.
      CompoundName first​(int n)
      Returns the first n components of this.
      static CompoundName fromComponents​(java.lang.String... components)
      Constructs this from an array of name components which are assumed not to contain dots
      java.lang.String get​(int i)
      Returns the compound element as the given index
      java.lang.String getLowerCasedName()  
      int hashCode()  
      boolean hasPrefix​(CompoundName prefix)
      Returns whether the given name is a prefix of this.
      boolean isCompound()
      Returns whether this name has more than one element
      boolean isEmpty()  
      java.lang.String last()
      Returns the name after the last dot.
      CompoundName prepend​(java.lang.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".
      CompoundName rest()
      Returns the name after the first dot, or "" if this name has no dots
      CompoundName rest​(int n)
      Returns the name starting after the n first components (i.e dots).
      CompoundName set​(int i, java.lang.String name)
      Returns a compound which have the name component at index i set to the given name.
      int size()
      Returns the number of compound elements in this.
      java.lang.String toString()
      Returns the string representation of this - all the name components in order separated by dots.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • empty

        public static final CompoundName empty
        The empty compound
    • Constructor Detail

      • CompoundName

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

        public CompoundName​(java.util.List<java.lang.String> compounds)
        Constructs this from a list of compounds.
    • Method Detail

      • fromComponents

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

        public CompoundName append​(java.lang.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​(java.lang.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 java.lang.String last()
        Returns the name after the last dot. If there are no dots, the full name is returned.
      • first

        public java.lang.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:
        java.lang.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:
        java.lang.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 java.lang.String get​(int i)
        Returns the compound element as the given index
      • set

        public CompoundName set​(int i,
                                java.lang.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 java.util.List<java.lang.String> asList()
        Returns an immutable list of the components of this
      • hashCode

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

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toString

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

        public java.lang.String getLowerCasedName()