< prev index next >
src/java.naming/share/classes/javax/naming/directory/BasicAttribute.java
Print this page
*** 33,71 ****
import javax.naming.NamingException;
import javax.naming.NamingEnumeration;
import javax.naming.OperationNotSupportedException;
/**
! * This class provides a basic implementation of the <tt>Attribute</tt> interface.
*<p>
* This implementation does not support the schema methods
! * <tt>getAttributeDefinition()</tt> and <tt>getAttributeSyntaxDefinition()</tt>.
! * They simply throw <tt>OperationNotSupportedException</tt>.
! * Subclasses of <tt>BasicAttribute</tt> should override these methods if they
* support them.
*<p>
! * The <tt>BasicAttribute</tt> class by default uses <tt>Object.equals()</tt> to
* determine equality of attribute values when testing for equality or
* when searching for values, <em>except</em> when the value is an array.
! * For an array, each element of the array is checked using <tt>Object.equals()</tt>.
! * Subclasses of <tt>BasicAttribute</tt> can make use of schema information
* when doing similar equality checks by overriding methods
* in which such use of schema is meaningful.
! * Similarly, the <tt>BasicAttribute</tt> class by default returns the values passed to its
* constructor and/or manipulated using the add/remove methods.
! * Subclasses of <tt>BasicAttribute</tt> can override <tt>get()</tt> and <tt>getAll()</tt>
* to get the values dynamically from the directory (or implement
! * the <tt>Attribute</tt> interface directly instead of subclassing <tt>BasicAttribute</tt>).
*<p>
! * Note that updates to <tt>BasicAttribute</tt> (such as adding or removing a value)
* does not affect the corresponding representation of the attribute
* in the directory. Updates to the directory can only be effected
! * using operations in the <tt>DirContext</tt> interface.
*<p>
! * A <tt>BasicAttribute</tt> instance is not synchronized against concurrent
* multithreaded access. Multiple threads trying to access and modify a
! * <tt>BasicAttribute</tt> should lock the object.
*
* @author Rosanna Lee
* @author Scott Seligman
* @since 1.3
*/
--- 33,71 ----
import javax.naming.NamingException;
import javax.naming.NamingEnumeration;
import javax.naming.OperationNotSupportedException;
/**
! * This class provides a basic implementation of the {@code Attribute} interface.
*<p>
* This implementation does not support the schema methods
! * {@code getAttributeDefinition()} and {@code getAttributeSyntaxDefinition()}.
! * They simply throw {@code OperationNotSupportedException}.
! * Subclasses of {@code BasicAttribute} should override these methods if they
* support them.
*<p>
! * The {@code BasicAttribute} class by default uses {@code Object.equals()} to
* determine equality of attribute values when testing for equality or
* when searching for values, <em>except</em> when the value is an array.
! * For an array, each element of the array is checked using {@code Object.equals()}.
! * Subclasses of {@code BasicAttribute} can make use of schema information
* when doing similar equality checks by overriding methods
* in which such use of schema is meaningful.
! * Similarly, the {@code BasicAttribute} class by default returns the values passed to its
* constructor and/or manipulated using the add/remove methods.
! * Subclasses of {@code BasicAttribute} can override {@code get()} and {@code getAll()}
* to get the values dynamically from the directory (or implement
! * the {@code Attribute} interface directly instead of subclassing {@code BasicAttribute}).
*<p>
! * Note that updates to {@code BasicAttribute} (such as adding or removing a value)
* does not affect the corresponding representation of the attribute
* in the directory. Updates to the directory can only be effected
! * using operations in the {@code DirContext} interface.
*<p>
! * A {@code BasicAttribute} instance is not synchronized against concurrent
* multithreaded access. Multiple threads trying to access and modify a
! * {@code BasicAttribute} should lock the object.
*
* @author Rosanna Lee
* @author Scott Seligman
* @since 1.3
*/
*** 110,129 ****
* If the attribute values are unordered, the order that the values were added
* are irrelevant. If the attribute values are ordered, then the
* order the values must match.
* If obj is null or not an Attribute, false is returned.
*<p>
! * By default <tt>Object.equals()</tt> is used when comparing the attribute
* id and its values except when a value is an array. For an array,
! * each element of the array is checked using <tt>Object.equals()</tt>.
* A subclass may override this to make
* use of schema syntax information and matching rules,
* which define what it means for two attributes to be equal.
* How and whether a subclass makes
* use of the schema information is determined by the subclass.
! * If a subclass overrides <tt>equals()</tt>, it should also override
! * <tt>hashCode()</tt>
* such that two attributes that are equal have the same hash code.
*
* @param obj The possibly null object to check.
* @return true if obj is equal to this attribute; false otherwise.
* @see #hashCode
--- 110,129 ----
* If the attribute values are unordered, the order that the values were added
* are irrelevant. If the attribute values are ordered, then the
* order the values must match.
* If obj is null or not an Attribute, false is returned.
*<p>
! * By default {@code Object.equals()} is used when comparing the attribute
* id and its values except when a value is an array. For an array,
! * each element of the array is checked using {@code Object.equals()}.
* A subclass may override this to make
* use of schema syntax information and matching rules,
* which define what it means for two attributes to be equal.
* How and whether a subclass makes
* use of the schema information is determined by the subclass.
! * If a subclass overrides {@code equals()}, it should also override
! * {@code hashCode()}
* such that two attributes that are equal have the same hash code.
*
* @param obj The possibly null object to check.
* @return true if obj is equal to this attribute; false otherwise.
* @see #hashCode
*** 170,181 ****
*<p>
* The hash code is computed by adding the hash code of
* the attribute's id and that of all of its values except for
* values that are arrays.
* For an array, the hash code of each element of the array is summed.
! * If a subclass overrides <tt>hashCode()</tt>, it should override
! * <tt>equals()</tt>
* as well so that two attributes that are equal have the same hash code.
*
* @return an int representing the hash code of this attribute.
* @see #equals
*/
--- 170,181 ----
*<p>
* The hash code is computed by adding the hash code of
* the attribute's id and that of all of its values except for
* values that are arrays.
* For an array, the hash code of each element of the array is summed.
! * If a subclass overrides {@code hashCode()}, it should override
! * {@code equals()}
* as well so that two attributes that are equal have the same hash code.
*
* @return an int representing the hash code of this attribute.
* @see #equals
*/
*** 313,326 ****
/**
* Determines whether a value is in this attribute.
*<p>
* By default,
! * <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
! * with this attribute's values except when <tt>attrVal</tt> is an array.
* For an array, each element of the array is checked using
! * <tt>Object.equals()</tt>.
* A subclass may use schema information to determine equality.
*/
public boolean contains(Object attrVal) {
return (find(attrVal) >= 0);
}
--- 313,326 ----
/**
* Determines whether a value is in this attribute.
*<p>
* By default,
! * {@code Object.equals()} is used when comparing {@code attrVal}
! * with this attribute's values except when {@code attrVal} is an array.
* For an array, each element of the array is checked using
! * {@code Object.equals()}.
* A subclass may use schema information to determine equality.
*/
public boolean contains(Object attrVal) {
return (find(attrVal) >= 0);
}
*** 350,360 ****
return -1; // not found
}
/**
* Determines whether two attribute values are equal.
! * Use arrayEquals for arrays and <tt>Object.equals()</tt> otherwise.
*/
private static boolean valueEquals(Object obj1, Object obj2) {
if (obj1 == obj2) {
return true; // object references are equal
}
--- 350,360 ----
return -1; // not found
}
/**
* Determines whether two attribute values are equal.
! * Use arrayEquals for arrays and {@code Object.equals()} otherwise.
*/
private static boolean valueEquals(Object obj1, Object obj2) {
if (obj1 == obj2) {
return true; // object references are equal
}
*** 368,378 ****
return (obj1.equals(obj2));
}
/**
* Determines whether two arrays are equal by comparing each of their
! * elements using <tt>Object.equals()</tt>.
*/
private static boolean arrayEquals(Object a1, Object a2) {
int len;
if ((len = Array.getLength(a1)) != Array.getLength(a2))
return false;
--- 368,378 ----
return (obj1.equals(obj2));
}
/**
* Determines whether two arrays are equal by comparing each of their
! * elements using {@code Object.equals()}.
*/
private static boolean arrayEquals(Object a1, Object a2) {
int len;
if ((len = Array.getLength(a1)) != Array.getLength(a2))
return false;
*** 391,404 ****
}
/**
* Adds a new value to this attribute.
*<p>
! * By default, <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
! * with this attribute's values except when <tt>attrVal</tt> is an array.
* For an array, each element of the array is checked using
! * <tt>Object.equals()</tt>.
* A subclass may use schema information to determine equality.
*/
public boolean add(Object attrVal) {
if (isOrdered() || (find(attrVal) < 0)) {
values.addElement(attrVal);
--- 391,404 ----
}
/**
* Adds a new value to this attribute.
*<p>
! * By default, {@code Object.equals()} is used when comparing {@code attrVal}
! * with this attribute's values except when {@code attrVal} is an array.
* For an array, each element of the array is checked using
! * {@code Object.equals()}.
* A subclass may use schema information to determine equality.
*/
public boolean add(Object attrVal) {
if (isOrdered() || (find(attrVal) < 0)) {
values.addElement(attrVal);
*** 409,422 ****
}
/**
* Removes a specified value from this attribute.
*<p>
! * By default, <tt>Object.equals()</tt> is used when comparing <tt>attrVal</tt>
! * with this attribute's values except when <tt>attrVal</tt> is an array.
* For an array, each element of the array is checked using
! * <tt>Object.equals()</tt>.
* A subclass may use schema information to determine equality.
*/
public boolean remove(Object attrval) {
// For the Java 2 platform, can just use "return removeElement(attrval);"
// Need to do the following to handle null case
--- 409,422 ----
}
/**
* Removes a specified value from this attribute.
*<p>
! * By default, {@code Object.equals()} is used when comparing {@code attrVal}
! * with this attribute's values except when {@code attrVal} is an array.
* For an array, each element of the array is checked using
! * {@code Object.equals()}.
* A subclass may use schema information to determine equality.
*/
public boolean remove(Object attrval) {
// For the Java 2 platform, can just use "return removeElement(attrval);"
// Need to do the following to handle null case
< prev index next >