Package com.yahoo.processing.request
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 Summary
Fields Modifier and Type Field Description static CompoundName
empty
The empty compound
-
Constructor Summary
Constructors Constructor Description CompoundName(String name)
Constructs this from a string which may contains dot-separated componentsCompoundName(List<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 itCompoundName
append(String name)
Returns a compound name which has the given compound string appended to itList<String>
asList()
Returns an immutable list of the components of thisboolean
equals(Object o)
String
first()
Returns the name before the first dot.CompoundName
first(int n)
Returns the first n components of this.static CompoundName
fromComponents(String... components)
Constructs this from an array of name components which are assumed not to contain dotsString
get(int i)
Returns the compound element as the given indexString
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 elementboolean
isEmpty()
String
last()
Returns the name after the last dot.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".CompoundName
rest()
Returns the name after the first dot, or "" if this name has no dotsCompoundName
rest(int n)
Returns the name starting after the n first components (i.e dots).CompoundName
set(int i, 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.String
toString()
Returns the string representation of this - all the name components in order separated by dots.
-
-
-
Field Detail
-
empty
public static final CompoundName empty
The empty compound
-
-
Constructor Detail
-
CompoundName
public CompoundName(String name)
Constructs this from a string which may contains dot-separated components- Throws:
NullPointerException
- if name is null
-
-
Method Detail
-
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 returnsthis
-
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 returnsthis
-
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 returnsthis
-
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
-
toString
public String toString()
Returns the string representation of this - all the name components in order separated by dots.
-
getLowerCasedName
public String getLowerCasedName()
-
-