|
JavaTM 2 Platform Std. Ed. v1.4.2 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection java.util.AbstractSet
This 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集合框架成员之一。
Collection
,
AbstractCollection
,
Set
Constructor Summary | |
protected |
AbstractSet() Sole constructor. 唯一的构造函数。 |
Method Summary | |
boolean |
equals(Object o) Compares the specified object with this set for equality. 将指定对象和当前set就相等性进行比较。 |
int |
hashCode() Returns the hash code value for this set. 返回set的哈希码值。 |
boolean |
removeAll(Collection c) 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 |
protected AbstractSet()
Method Detail |
public boolean equals(Object o)
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)。
equals
in interface
Set
equals
in class
Object
o
- Object to be compared for equality with this set. 同当前set比较相等性的Object。
Object.hashCode()
,
Hashtable
public int hashCode()
This implementation enumerates over the set, calling the hashCode method on each element in the collection, and adding up the results. 实现对set进行枚举,对集合中每一个元素调用hashCode方法,然后将结果相加。
hashCode
in interface
Set
hashCode
in class
Object
Object.equals(java.lang.Object)
,
Hashtable
public boolean removeAll(Collection c)
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。
removeAll
in interface
Set
removeAll
in class
AbstractCollection
c
- elements to be removed from this set. 要从set中删除的元素。
UnsupportedOperationException
- removeAll is not supported by this set. set不支持removeAll则抛出。
NullPointerException
- if the specified collection is null. 如果指定集合为null时抛出。
AbstractCollection.remove(Object)
,
AbstractCollection.contains(Object)
|
JavaTM 2 Platform Std. Ed. v1.4.2 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.