Constructors Summary |
---|
public BasicAttributes()Constructs a new instance of Attributes.
The character case of attribute identifiers
is significant when subsequently retrieving or adding attributes.
|
public BasicAttributes(boolean ignoreCase)Constructs a new instance of Attributes.
If ignoreCase is true, the character case of attribute
identifiers is ignored; otherwise the case is significant.
this.ignoreCase = ignoreCase;
|
public BasicAttributes(String attrID, Object val)Constructs a new instance of Attributes with one attribute.
The attribute specified by attrID and val are added to the newly
created attribute.
The character case of attribute identifiers
is significant when subsequently retrieving or adding attributes.
this();
this.put(new BasicAttribute(attrID, val));
|
public BasicAttributes(String attrID, Object val, boolean ignoreCase)Constructs a new instance of Attributes with one attribute.
The attribute specified by attrID and val are added to the newly
created attribute.
If ignoreCase is true, the character case of attribute
identifiers is ignored; otherwise the case is significant.
this(ignoreCase);
this.put(new BasicAttribute(attrID, val));
|
Methods Summary |
---|
public java.lang.Object | clone()
BasicAttributes attrset;
try {
attrset = (BasicAttributes)super.clone();
} catch (CloneNotSupportedException e) {
attrset = new BasicAttributes(ignoreCase);
}
attrset.attrs = (Hashtable)attrs.clone();
return attrset;
|
public boolean | equals(java.lang.Object obj)Determines whether this BasicAttributes is equal to another
Attributes
Two Attributes are equal if they are both instances of
Attributes,
treat the case of attribute IDs the same way, and contain the
same attributes. Each Attribute in this BasicAttributes
is checked for equality using Object.equals(), which may have
be overridden by implementations of Attribute).
If a subclass overrides equals(),
it should override hashCode()
as well so that two Attributes instances that are equal
have the same hash code.
if ((obj != null) && (obj instanceof Attributes)) {
Attributes target = (Attributes)obj;
// Check case first
if (ignoreCase != target.isCaseIgnored()) {
return false;
}
if (size() == target.size()) {
Attribute their, mine;
try {
NamingEnumeration theirs = target.getAll();
while (theirs.hasMore()) {
their = (Attribute)theirs.next();
mine = get(their.getID());
if (!their.equals(mine)) {
return false;
}
}
} catch (NamingException e) {
return false;
}
return true;
}
}
return false;
|
public javax.naming.directory.Attribute | get(java.lang.String attrID)
Attribute attr = (Attribute) attrs.get(
ignoreCase ? attrID.toLowerCase() : attrID);
return (attr);
|
public javax.naming.NamingEnumeration | getAll()
return new AttrEnumImpl();
|
public javax.naming.NamingEnumeration | getIDs()
return new IDEnumImpl();
|
public int | hashCode()Calculates the hash code of this BasicAttributes.
The hash code is computed by adding the hash code of
the attributes of this object. If this BasicAttributes
ignores case of its attribute IDs, one is added to the hash code.
If a subclass overrides hashCode(),
it should override equals()
as well so that two Attributes instances that are equal
have the same hash code.
int hash = (ignoreCase ? 1 : 0);
try {
NamingEnumeration all = getAll();
while (all.hasMore()) {
hash += all.next().hashCode();
}
} catch (NamingException e) {}
return hash;
|
public boolean | isCaseIgnored()
return ignoreCase;
|
public javax.naming.directory.Attribute | put(java.lang.String attrID, java.lang.Object val)
return (Attribute)this.put(new BasicAttribute(attrID, val));
|
public javax.naming.directory.Attribute | put(javax.naming.directory.Attribute attr)
String id = attr.getID();
if (ignoreCase) {
id = id.toLowerCase();
}
return (Attribute)attrs.put(id, attr);
|
private void | readObject(java.io.ObjectInputStream s)Overridden to avoid exposing implementation details.
s.defaultReadObject(); // read in the ignoreCase flag
int n = s.readInt(); // number of attributes
attrs = (n >= 1)
? new Hashtable(n * 2)
: new Hashtable(2); // can't have initial size of 0 (grrr...)
while (--n >= 0) {
put((Attribute)s.readObject());
}
|
public javax.naming.directory.Attribute | remove(java.lang.String attrID)
String id = (ignoreCase ? attrID.toLowerCase() : attrID);
return (Attribute)attrs.remove(id);
|
public int | size()
return attrs.size();
|
public java.lang.String | toString()Generates the string representation of this attribute set.
The string consists of each attribute identifier and the contents
of each attribute. The contents of this string is useful
for debugging and is not meant to be interpreted programmatically.
if (attrs.size() == 0) {
return("No attributes");
} else {
return attrs.toString();
}
|
private void | writeObject(java.io.ObjectOutputStream s)Overridden to avoid exposing implementation details.
s.defaultWriteObject(); // write out the ignoreCase flag
s.writeInt(attrs.size());
Enumeration attrEnum = attrs.elements();
while (attrEnum.hasMoreElements()) {
s.writeObject(attrEnum.nextElement());
}
|