|
Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
java.util.AbstractCollection
com.tangosol.util.InflatableCollection
public abstract class InflatableCollection
A Collection implementation which optimizes memory consumption for collections that often contain just a single value. This implementation also reduces contention for read operations (e.g. contains, iterator, etc.)
Field Summary | |
---|---|
protected Collection |
m_colValue Holds elements if there are more then one. |
protected Object |
m_oValue Holds a single value. |
protected static Object |
NO_VALUE A marker value indicating that the single value has not been initialized. |
Constructor Summary | |
---|---|
InflatableCollection() |
Method Summary | |
---|---|
boolean |
add(Object o) Ensures that this collection contains the specified element (optional operation). |
void |
clear() Removes all of the elements from this collection (optional operation). |
boolean |
contains(Object o) Returns true if this collection contains the specified element. |
boolean |
equals(Object o) Compares the specified object with this collection for equality. |
int |
hashCode() Returns the hash code value for this collection. |
protected abstract Collection |
instantiateCollection() Factory method used to create a new Collection. |
Iterator |
iterator() Returns an iterator over the elements contained in this collection. |
boolean |
remove(Object o) Removes a single instance of the specified element from this collection, if it is present (optional operation). |
int |
size() Returns the number of elements in this collection. |
Object[] |
toArray() Returns an array containing all of the elements in this collection. |
Object[] |
toArray(Object[] ao) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, containsAll, isEmpty, removeAll, retainAll, toString |
Field Detail |
---|
protected volatile Object m_oValue
protected volatile Collection m_colValue
protected static final Object NO_VALUE
Constructor Detail |
---|
public InflatableCollection()
Method Detail |
---|
public boolean equals(Object o)
While the Collection interface adds no stipulations to the general contract for the Object.equals, programmers who implement the Collection interface "directly" (in other words, create a class that is a Collection but is not a Set or a List) must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementer may wish to implement a "value comparison" in place of the default "reference comparison." (The List and Set interfaces mandate such value comparisons.)
The general contract for the Object.equals method states that equals must be symmetric (in other words, a.equals(b) if and only if b.equals(a)). The contracts for List.equals and Set.equals state that lists are only equal to other lists, and sets to other sets. Thus, a custom equals method for a collection class that implements neither the List nor Set interface must return false when this collection is compared to any list or set. (By the same logic, it is not possible to write a class that correctly implements both the Set and List interfaces.)
o
- Object to be compared for equality with this collection.Object.equals(Object)
, Set.equals(Object)
, List.equals(Object)
public int hashCode()
Object.hashCode()
, Object.equals(Object)
public boolean add(Object o)
This implementation always throws an UnsupportedOperationException.
add
in interface Collection
add
in class AbstractCollection
o
- element whose presence in this collection is to be ensured.public boolean remove(Object o)
This implementation iterates over the collection looking for the specified element. If it finds the element, it removes the element from the collection using the iterator's remove method.
Note that this implementation throws an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection contains the specified object.
remove
in interface Collection
remove
in class AbstractCollection
o
- element to be removed from this collection, if present.public void clear()
This implementation iterates over this collection, removing each element using the Iterator.remove operation. Most implementations will probably choose to override this method for efficiency.
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection is non-empty.
clear
in interface Collection
clear
in class AbstractCollection
public boolean contains(Object o)
This implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.
contains
in interface Collection
contains
in class AbstractCollection
o
- object to be checked for containment in this collection.public Iterator iterator()
iterator
in interface Iterable
iterator
in interface Collection
iterator
in class AbstractCollection
public int size()
size
in interface Collection
size
in class AbstractCollection
public Object[] toArray()
This implementation allocates the array to be returned, and iterates over the elements in the collection, storing each object reference in the next consecutive element of the array, starting with element 0.
toArray
in interface Collection
toArray
in class AbstractCollection
public Object[] toArray(Object[] ao)
If the collection fits in the specified array with room to spare (i.e., the array has more elements than the collection), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the collection only if the caller knows that the collection does not contain any null elements.)
If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
This implementation checks if the array is large enough to contain the collection; if not, it allocates a new array of the correct size and type (using reflection). Then, it iterates over the collection, storing each object reference in the next consecutive element of the array, starting with element 0. If the array is larger than the collection, a null is stored in the first location after the end of the collection.
toArray
in interface Collection
toArray
in class AbstractCollection
ao
- the array into which the elements of the collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.protected abstract Collection instantiateCollection()
|
Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |