Package com.tangosol.util
Class InflatableCollection
- java.lang.Object
-
- java.util.AbstractCollection
-
- com.tangosol.util.InflatableCollection
-
- All Implemented Interfaces:
Iterable
,Collection
- Direct Known Subclasses:
InflatableList
,InflatableSet
public abstract class InflatableCollection extends AbstractCollection
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.)- Since:
- Coherence 3.6
- Author:
- ch 2009.11.22
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
InflatableCollection.InflatedCollection
A marker interface which is used to identify internally inflated Collections.
-
Field Summary
Fields Modifier and Type Field Description protected Object
m_oValue
Holds NO_VALUE, a single value, or an InflatedCollection of values.protected static Object
NO_VALUE
A marker value indicating that the single value has not been initialized.protected static AtomicReferenceFieldUpdater<InflatableCollection,Object>
VALUE_UPDATER
Atomic updater for collection values.
-
Constructor Summary
Constructors Constructor Description InflatableCollection()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
add(Object o)
void
clear()
boolean
contains(Object o)
boolean
equals(Object o)
int
hashCode()
protected abstract InflatableCollection.InflatedCollection
instantiateCollection()
Factory method used to create a new Collection.Iterator
iterator()
boolean
remove(Object o)
boolean
removeAll(Collection c)
boolean
retainAll(Collection c)
int
size()
Object[]
toArray()
Object[]
toArray(Object[] ao)
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Field Detail
-
NO_VALUE
protected static final Object NO_VALUE
A marker value indicating that the single value has not been initialized.
-
VALUE_UPDATER
protected static final AtomicReferenceFieldUpdater<InflatableCollection,Object> VALUE_UPDATER
Atomic updater for collection values. Static atomic field updater rather thanAtomicReference
is shared to reduce memory footprint of each InflatableCollection instance. (COH-9262)
-
m_oValue
protected volatile Object m_oValue
Holds NO_VALUE, a single value, or an InflatedCollection of values.
-
-
Method Detail
-
equals
public boolean equals(Object o)
- Specified by:
equals
in interfaceCollection
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection
- Overrides:
hashCode
in classObject
-
add
public boolean add(Object o)
- Specified by:
add
in interfaceCollection
- Overrides:
add
in classAbstractCollection
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection
- Overrides:
remove
in classAbstractCollection
-
removeAll
public boolean removeAll(Collection c)
- Specified by:
removeAll
in interfaceCollection
- Overrides:
removeAll
in classAbstractCollection
-
retainAll
public boolean retainAll(Collection c)
- Specified by:
retainAll
in interfaceCollection
- Overrides:
retainAll
in classAbstractCollection
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection
- Overrides:
clear
in classAbstractCollection
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection
- Overrides:
contains
in classAbstractCollection
-
iterator
public Iterator iterator()
- Specified by:
iterator
in interfaceCollection
- Specified by:
iterator
in interfaceIterable
- Specified by:
iterator
in classAbstractCollection
-
size
public int size()
- Specified by:
size
in interfaceCollection
- Specified by:
size
in classAbstractCollection
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection
- Overrides:
toArray
in classAbstractCollection
-
toArray
public Object[] toArray(Object[] ao)
- Specified by:
toArray
in interfaceCollection
- Overrides:
toArray
in classAbstractCollection
-
instantiateCollection
protected abstract InflatableCollection.InflatedCollection instantiateCollection()
Factory method used to create a new Collection. The returned Collection must provide a "safe" iterator.- Returns:
- a "real" implementation to use if this collection is expanded
-
-