[/url] [url=file:///F:/资料/文字资料/j2sdk-1_4_2-doc/docs/api/overview-summary.html]Overview
Class
JavaTM 2 Platform
Std. Ed. v1.4.2
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
java.util
Class AbstractSetjava.lang.Object
java.util.AbstractCollection
java.util.AbstractSet
All Implemented Interfaces: Collection, Set Direct Known Subclasses: HashSet, TreeSet public abstract class AbstractSet extends AbstractCollection implements SetThis class provides a skeletal implementation of the Set interface to minimize the effort required to implement this interface. 该类提供了接口Set的框架实现,用来降低实现该接口的复杂程度。
The process of implementing a set by extending this class is identical to that of implementing a Collection by extending AbstractCollection, except that all of the methods and constructors in subclasses of this class must obey the additional constraints imposed by the Set interface (for instance, the add method must not permit addition of multiple intances of an object to a set). 通过继承该类以实现set的过程和通过继承AbstractCollection实现Collection一样, 除了该类子类的所有方法和构造函数必须遵守Set接口的一些额外约定(例如,add方法不允许向set中加入重复对象)。
Note that this class does not override any of the implementations from the AbstractCollection class. It merely adds implementations for equals and hashCode. 注意该类没有重载AbstractCollection类的任何实现。它只是增加了equals和hashCode的实现。
This class is a member of the Java Collections Framework. 该类是Java集合框架成员之一。
Since: 1.2 See Also: Collection, AbstractCollection, SetConstructor Summary
protected
Sole constructor. 唯一的构造函数。
Method Summary
boolean
Compares the specified object with this set for equality. 将指定对象和当前set就相等性进行比较。
int
hashCode()
Returns the hash code value for this set. 返回set的哈希码值。
boolean
Removes from this set all of its elements that are contained in the specified collection (optional operation). 从set中删除指定集合所包含的所有元素(可选操作)。
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, )]toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, )]toArray
Constructor Detail
AbstractSetprotected AbstractSet()
Sole constructor. (For invocation by subclass constructors, typically implicit.) 唯一的构造函数。(通常由子类隐式调用)
Method Detail
equalspublic boolean equals(Object o)
Compares the specified object with this set for equality. Returns true if the given object is also a set, the two sets have the same size, and every member of the given set is contained in this set. This ensures that the equals method works properly across different implementations of the Set interface. 将指定对象和当前set就相等性进行比较。如果指定对象也是一个set,两个set有着相同大小,指定set的每一个成员在当前 set中。该定义可以保证对于set接口的不同实现,equals方法都能正常工作。 This implementation first checks if the specified object is this set; if so it returns true. Then, it checks if the specified object is a set whose size is identical to the size of this set; if not, it it returns false. If so, it returns containsAll((Collection) o). 实现首先检查指定对象是否是当前set,如果是返回true。然后,检查指定对象是否是一个set,大小是否和当前set的一样, 如果不是,返回false。如果是,返回containsAll((Collection) o)。
Specified by: equals in interface Set Overrides: equals in class ObjectParameters: o - Object to be compared for equality with this set. 同当前set比较相等性的Object。 Returns: true if the specified object is equal to this set. 如果指定对象和当前set相等,返回true。 See Also: Object.hashCode(), HashtablehashCodepublic int hashCode()
Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two sets s1 and s2, as required by the general contract of Object.hashCode. 返回set的哈希码值。set的哈希码被定义为set中元素的哈希码之和, 这里null元素的哈希码被定义为0。 这将保证对于两个set s1和s2, s1.equals(s2)意味着s1.hashCode()==s2.hashCode(),遵循 Object.hashCode方法的一般约定。 This implementation enumerates over the set, calling the hashCode method on each element in the collection, and adding up the results. 实现对set进行枚举,对集合中每一个元素调用hashCode方法,然后将结果相加。
Specified by: hashCode in interface Set Overrides: hashCode in class ObjectReturns: the hash code value for this set. set的哈希码值。 See Also: Object.equals(java.lang.Object), HashtableremoveAllpublic boolean removeAll(Collection c)
Removes from this set all of its elements that are contained in the specified collection (optional operation). 从set中删除指定集合所包含的所有元素(可选操作)。 This implementation determines which is the smaller of this set and the specified collection, by invoking the size method on each. If this set has fewer elements, then the implementation iterates over this set, checking each element returned by the iterator in turn to see if it is contained in the specified collection. If it is so contained, it is removed from this set with the iterator's remove method. If the specified collection has fewer elements, then the implementation iterates over the specified collection, removing from this set each element returned by the iterator, using this set's remove method. 该实现首先通过调用size方法来确定当前set和指定集合哪个更小。如果set的元素更少, 那么实现遍历set,按顺序检查由迭代器返回的每一个元素,查看指定集合中是否包含。 如果包含,使用迭代器的remove方法从set中删除。如果指定集合的元素更少,那么遍历指定集合, 使用set的remove方法来从set中删除由迭代器返回的每一个元素。
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method. 注意如果由iterator方法返回的迭代器没有实现remove方法,实现将抛出UnsupportedOperationException。
Specified by: removeAll in interface Set Overrides: removeAll in class AbstractCollectionParameters: c - elements to be removed from this set. 要从set中删除的元素。 Returns: true if this set changed as a result of the call. 如果调用的结果改变了set,返回true。 Throws: UnsupportedOperationException - removeAll is not supported by this set. set不支持removeAll则抛出。 NullPointerException - if the specified collection is null. 如果指定集合为null时抛出。 See Also: AbstractCollection.remove(Object), AbstractCollection.contains(Object)[/url][url=file:///F:/资料/文字资料/j2sdk-1_4_2-doc/docs/api/overview-summary.html]Overview
Class
JavaTM 2 Platform
Std. Ed. v1.4.2
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.