com.devexperts.util
Class SynchronizedIndexedSet<K,V>

java.lang.Object
  extended by com.devexperts.util.AbstractConcurrentSet<V>
      extended by com.devexperts.util.IndexedSet<K,V>
          extended by com.devexperts.util.SynchronizedIndexedSet<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<V>, Collection<V>, Set<V>

public class SynchronizedIndexedSet<K,V>
extends IndexedSet<K,V>

A synchronized thread-safe version of IndexedSet class. It provides following benefits over standard IndexedSet:

Note that SynchronizedIndexedSet can be wrapped by IndexedMap to create what can be considered a SynchronizedIndexedMap.

See Also:
Serialized Form

Constructor Summary
SynchronizedIndexedSet()
          Creates new empty set with default indexer Indexer.DEFAULT and default initial capacity.
SynchronizedIndexedSet(Collection<V> c)
          Creates a new set containing the elements in the specified collection.
SynchronizedIndexedSet(Indexer<K,? super V> indexer)
          Creates new empty set with specified indexer and default initial capacity.
SynchronizedIndexedSet(Indexer<K,? super V> indexer, Collection<? extends V> c)
          Creates a new set with specified indexer containing the elements in the specified collection.
SynchronizedIndexedSet(Indexer<K,? super V> indexer, int initial_capacity)
          Creates new empty set with specified indexer and specified initial capacity.
SynchronizedIndexedSet(int initial_capacity)
          Creates new empty set with default indexer Indexer.DEFAULT and specified initial capacity.
 
Method Summary
 void clear()
          Removes all elements from this set.
 SynchronizedIndexedSet<K,V> clone()
          Returns a shallow copy of this set - the values themselves are not cloned.
 void ensureCapacity(int capacity)
          Increases the capacity of this set instance, if necessary, to ensure that it can hold at least the number of elements specified by the capacity argument.
 IndexedSetStats getStats()
          Returns static structure statistics of this set.
static
<V> SynchronizedIndexedSet<V,V>
of(V... objs)
          Creates a new set with default indexer containing specified elements.
 V put(V value)
          Puts specified element into this set and returns previous element that matches specified one.
 V putIfAbsentAndGet(V value)
          Puts specified element into this set if it is absent and returns current element in the set that matches specified one.
 V removeKey(K key)
          Removes the element from this set which matches specified key if it is present and returns removed element or null if none were found.
 V removeKey(long key)
          Removes the element from this set which matches specified key if it is present and returns removed element or null if none were found.
 V removeValue(V value)
          Removes the element from this set which matches specified value if it is present and returns removed element or null if none were found.
 void trimToSize()
          Trims the capacity of this set instance to be the set's current size.
 
Methods inherited from class com.devexperts.util.IndexedSet
add, concurrentIterator, contains, containsKey, containsKey, containsValue, entryIterator, getByKey, getByKey, getByValue, getIndexer, iterator, keyIterator, remove, size, toArray, toArray
 
Methods inherited from class com.devexperts.util.AbstractConcurrentSet
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SynchronizedIndexedSet

public SynchronizedIndexedSet()
Creates new empty set with default indexer Indexer.DEFAULT and default initial capacity.


SynchronizedIndexedSet

public SynchronizedIndexedSet(int initial_capacity)
Creates new empty set with default indexer Indexer.DEFAULT and specified initial capacity.


SynchronizedIndexedSet

public SynchronizedIndexedSet(Indexer<K,? super V> indexer)
Creates new empty set with specified indexer and default initial capacity.


SynchronizedIndexedSet

public SynchronizedIndexedSet(Indexer<K,? super V> indexer,
                              int initial_capacity)
Creates new empty set with specified indexer and specified initial capacity.


SynchronizedIndexedSet

public SynchronizedIndexedSet(Collection<V> c)
Creates a new set containing the elements in the specified collection. If specified collection is an IndexedSet, then new indexed set uses same indexer, otherwise it uses default indexer Indexer.DEFAULT.


SynchronizedIndexedSet

public SynchronizedIndexedSet(Indexer<K,? super V> indexer,
                              Collection<? extends V> c)
Creates a new set with specified indexer containing the elements in the specified collection.

Method Detail

of

public static <V> SynchronizedIndexedSet<V,V> of(V... objs)
Creates a new set with default indexer containing specified elements.


clone

public SynchronizedIndexedSet<K,V> clone()
Returns a shallow copy of this set - the values themselves are not cloned.

Overrides:
clone in class IndexedSet<K,V>

ensureCapacity

public void ensureCapacity(int capacity)
Increases the capacity of this set instance, if necessary, to ensure that it can hold at least the number of elements specified by the capacity argument.

Overrides:
ensureCapacity in class IndexedSet<K,V>

trimToSize

public void trimToSize()
Trims the capacity of this set instance to be the set's current size. An application can use this operation to minimize the storage of this set instance.

Overrides:
trimToSize in class IndexedSet<K,V>

clear

public void clear()
Removes all elements from this set.

Specified by:
clear in interface Collection<V>
Specified by:
clear in interface Set<V>
Overrides:
clear in class IndexedSet<K,V>

getStats

public IndexedSetStats getStats()
Returns static structure statistics of this set.

Overrides:
getStats in class IndexedSet<K,V>

put

public V put(V value)
Puts specified element into this set and returns previous element that matches specified one.

Overrides:
put in class IndexedSet<K,V>

putIfAbsentAndGet

public V putIfAbsentAndGet(V value)
Puts specified element into this set if it is absent and returns current element in the set that matches specified one. This is equivalent to
   if (set.containsValue(value)) {
     return set.getByValue(value);
   } else {
     set.put(value);
     return value;
   }
 
except that the action is performed atomically if it is properly synchronized.

Note, that unlike ConcurrentMap.putIfAbsent(K, V), this method returns specified value (not null) if the value was absent.

Overrides:
putIfAbsentAndGet in class IndexedSet<K,V>

removeValue

public V removeValue(V value)
Removes the element from this set which matches specified value if it is present and returns removed element or null if none were found.

Overrides:
removeValue in class IndexedSet<K,V>

removeKey

public V removeKey(K key)
Removes the element from this set which matches specified key if it is present and returns removed element or null if none were found.

Overrides:
removeKey in class IndexedSet<K,V>

removeKey

public V removeKey(long key)
Removes the element from this set which matches specified key if it is present and returns removed element or null if none were found.

Overrides:
removeKey in class IndexedSet<K,V>


Copyright © 2013 Devexperts. All Rights Reserved.