return (impl.startsWith(n.size(), n.getAll()));
} else {
return false;
}
}
/**
* Determines whether a compound name is a suffix of this compound name.
* A compound name 'n' is a suffix if it it is equal to
* getSuffix(size()-n.size())--in other words, this
* compound name ends with 'n'.
* If n is null or not a compound name, false is returned.
*<p>
* Implementation note: Currently the syntax properties of n
* are not used when doing the comparison. They might be in the future.
* @param n The possibly null compound name to check.
* @return true if n is a CompoundName and
* is a suffix of this compound name, false otherwise.
*/
public boolean endsWith(Name n) {
if (n instanceof CompoundName) {
return (impl.endsWith(n.size(), n.getAll()));
} else {
return false;
}
}
/**
* Adds the components of a compound name -- in order -- to the end of
* this compound name.
*<p>
* Implementation note: Currently the syntax properties of suffix
* is not used or checked. They might be in the future.
* @param suffix The non-null components to add.
* @return The updated CompoundName, not a new one. Cannot be null.
* @exception InvalidNameException If suffix is not a compound name,
* or if the addition of the components violates the syntax
* of this compound name (e.g. exceeding number of components).
*/
public Name addAll(Name suffix) throws InvalidNameException {
if (suffix instanceof CompoundName) {
impl.addAll(suffix.getAll());
return this;
} else {
throw new InvalidNameException("Not a compound name: " +
suffix.toString());
}
}
/**
* Adds the components of a compound name -- in order -- at a specified
* position within this compound name.
* Components of this compound name at or after the index of the first
* new component are shifted up (away from index 0)
* to accommodate the new components.
*<p>
* Implementation note: Currently the syntax properties of suffix
* is not used or checked. They might be in the future.
*
* @param n The non-null components to add.
* @param posn The index in this name at which to add the new
* components. Must be in the range [0,size()].
* @return The updated CompoundName, not a new one. Cannot be null.
* @exception ArrayIndexOutOfBoundsException
* If posn is outside the specified range.
* @exception InvalidNameException If n is not a compound name,
* or if the addition of the components violates the syntax
* of this compound name (e.g. exceeding number of components).
*/
public Name addAll(int posn, Name n) throws InvalidNameException {
if (n instanceof CompoundName) {
impl.addAll(posn, n.getAll());
return this;
} else {
throw new InvalidNameException("Not a compound name: " +
n.toString());
}
}
/**
* Adds a single component to the end of this compound name.
*
* @param comp The non-null component to add.
* @return The updated CompoundName, not a new one. Cannot be null.
* @exception InvalidNameException If adding comp at end of the name
* would violate the compound name's syntax.
*/
public Name add(String comp) throws InvalidNameException{
impl.add(comp);
return this;
}
/**
* Adds a single component at a specified position within this
* compound name.
* Components of this compound name at or after the index of the new
* component are shifted up by one (away from index 0)
* to accommodate the new component.
*
* @param comp The non-null component to add.
=5= |