The implementation class for CompoundName and CompositeName.
This class is package private.
| Method from javax.naming.NameImpl Detail: |
public void add(String comp) throws InvalidNameException {
if (size() > 0 && syntaxDirection == FLAT) {
throw new InvalidNameException(
"A flat name can only have a single component");
}
components.addElement(comp);
}
|
public void add(int posn,
String comp) throws InvalidNameException {
if (size() > 0 && syntaxDirection == FLAT) {
throw new InvalidNameException(
"A flat name can only zero or one component");
}
components.insertElementAt(comp, posn);
}
|
public boolean addAll(Enumeration comps) throws InvalidNameException {
boolean added = false;
while (comps.hasMoreElements()) {
try {
Object comp = comps.nextElement();
if (size() > 0 && syntaxDirection == FLAT) {
throw new InvalidNameException(
"A flat name can only have a single component");
}
components.addElement(comp);
added = true;
} catch (NoSuchElementException e) {
break; // "comps" has shrunk.
}
}
return added;
}
|
public boolean addAll(int posn,
Enumeration comps) throws InvalidNameException {
boolean added = false;
for (int i = posn; comps.hasMoreElements(); i++) {
try {
Object comp = comps.nextElement();
if (size() > 0 && syntaxDirection == FLAT) {
throw new InvalidNameException(
"A flat name can only have a single component");
}
components.insertElementAt(comp, i);
added = true;
} catch (NoSuchElementException e) {
break; // "comps" has shrunk.
}
}
return added;
}
|
public int compareTo(NameImpl obj) {
if (this == obj) {
return 0;
}
int len1 = size();
int len2 = obj.size();
int n = Math.min(len1, len2);
int index1 = 0, index2 = 0;
while (n-- != 0) {
String comp1 = get(index1++);
String comp2 = obj.get(index2++);
// normalize according to syntax
if (syntaxTrimBlanks) {
comp1 = comp1.trim();
comp2 = comp2.trim();
}
if (syntaxCaseInsensitive) {
comp1 = comp1.toLowerCase();
comp2 = comp2.toLowerCase();
}
int local = comp1.compareTo(comp2);
if (local != 0) {
return local;
}
}
return len1 - len2;
}
Compares obj to this NameImpl to determine ordering.
Takes into account syntactic properties such as
elimination of blanks, case-ignore, etc, if relevant.
Note: using syntax of this NameImpl and ignoring
that of comparison target. |
public boolean endsWith(int posn,
Enumeration suffix) {
// posn is number of elements in suffix
// startIndex is the starting position in this name
// at which to start the comparison. It is calculated by
// subtracting 'posn' from size()
int startIndex = size() - posn;
if (startIndex < 0 || startIndex > size()) {
return false;
}
try {
Enumeration mycomps = getSuffix(startIndex);
while (mycomps.hasMoreElements()) {
String my = (String)mycomps.nextElement();
String his = (String)suffix.nextElement();
if (syntaxTrimBlanks) {
my = my.trim();
his = his.trim();
}
if (syntaxCaseInsensitive) {
if (!(my.equalsIgnoreCase(his)))
return false;
} else {
if (!(my.equals(his)))
return false;
}
}
} catch (NoSuchElementException e) {
return false;
}
return true;
}
|
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof NameImpl)) {
NameImpl target = (NameImpl)obj;
if (target.size() == this.size()) {
Enumeration mycomps = getAll();
Enumeration comps = target.getAll();
while (mycomps.hasMoreElements()) {
// %% comps could shrink in the middle.
String my = (String)mycomps.nextElement();
String his = (String)comps.nextElement();
if (syntaxTrimBlanks) {
my = my.trim();
his = his.trim();
}
if (syntaxCaseInsensitive) {
if (!(my.equalsIgnoreCase(his)))
return false;
} else {
if (!(my.equals(his)))
return false;
}
}
return true;
}
}
return false;
}
|
public String get(int posn) {
return ((String) components.elementAt(posn));
}
|
public Enumeration getAll() {
return components.elements();
}
|
public Enumeration getPrefix(int posn) {
if (posn < 0 || posn > size()) {
throw new ArrayIndexOutOfBoundsException(posn);
}
return new NameImplEnumerator(components, 0, posn);
}
|
public Enumeration getSuffix(int posn) {
int cnt = size();
if (posn < 0 || posn > cnt) {
throw new ArrayIndexOutOfBoundsException(posn);
}
return new NameImplEnumerator(components, posn, cnt);
}
|
public int hashCode() {
int hash = 0;
for (Enumeration e = getAll(); e.hasMoreElements();) {
String comp = (String)e.nextElement();
if (syntaxTrimBlanks) {
comp = comp.trim();
}
if (syntaxCaseInsensitive) {
comp = comp.toLowerCase();
}
hash += comp.hashCode();
}
return hash;
}
|
public boolean isEmpty() {
return (components.isEmpty());
}
|
public Object remove(int posn) {
Object r = components.elementAt(posn);
components.removeElementAt(posn);
return r;
}
|
public int size() {
return (components.size());
}
|
public boolean startsWith(int posn,
Enumeration prefix) {
if (posn < 0 || posn > size()) {
return false;
}
try {
Enumeration mycomps = getPrefix(posn);
while (mycomps.hasMoreElements()) {
String my = (String)mycomps.nextElement();
String his = (String)prefix.nextElement();
if (syntaxTrimBlanks) {
my = my.trim();
his = his.trim();
}
if (syntaxCaseInsensitive) {
if (!(my.equalsIgnoreCase(his)))
return false;
} else {
if (!(my.equals(his)))
return false;
}
}
} catch (NoSuchElementException e) {
return false;
}
return true;
}
|
public String toString() {
StringBuffer answer = new StringBuffer();
String comp;
boolean compsAllEmpty = true;
int size = components.size();
for (int i = 0; i < size; i++) {
if (syntaxDirection == RIGHT_TO_LEFT) {
comp =
stringifyComp((String) components.elementAt(size - 1 - i));
} else {
comp = stringifyComp((String) components.elementAt(i));
}
if ((i != 0) && (syntaxSeparator != null))
answer.append(syntaxSeparator);
if (comp.length() >= 1)
compsAllEmpty = false;
answer = answer.append(comp);
}
if (compsAllEmpty && (size >= 1) && (syntaxSeparator != null))
answer = answer.append(syntaxSeparator);
return (answer.toString());
}
|