Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java')
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java456
1 files changed, 228 insertions, 228 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java
index d1b96ce6683..cffcb1ac3bc 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/type/HashCollection.java
@@ -29,259 +29,259 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class HashCollection<K, V> {
- private boolean isSynchronized;
- @SuppressWarnings("unchecked")
- private Class<? extends Collection> collectionType;
+ private boolean isSynchronized;
+ @SuppressWarnings("unchecked")
+ private Class<? extends Collection> collectionType;
- private Map<K, Collection<V>> map;
- @SuppressWarnings("unchecked")
- public static final Class<? extends Collection> DEFAULT_COLLECTION_TYPE = ArrayList.class;
+ private Map<K, Collection<V>> map;
+ @SuppressWarnings("unchecked")
+ public static final Class<? extends Collection> DEFAULT_COLLECTION_TYPE = ArrayList.class;
- /********************************************************************************************************************
- * Constructors
- *******************************************************************************************************************/
+ /********************************************************************************************************************
+ * Constructors
+ *******************************************************************************************************************/
- /**
- * @param isSynchronized - If true, the Map & Collection will both be synchronized using the
- * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be synchronzied
- * and therefore not threadsafe.
- * @param collectionType The type of collection to use to as the values within the HashMap.
- * @param initialCapacity
- * @see HashMap#HashMap(int, float)
- */
- @SuppressWarnings("unchecked")
- public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType, int initialCapacity, float loadFactor) {
+ /**
+ * @param isSynchronized - If true, the Map & Collection will both be synchronized using the
+ * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be synchronzied
+ * and therefore not threadsafe.
+ * @param collectionType The type of collection to use to as the values within the HashMap.
+ * @param initialCapacity
+ * @see HashMap#HashMap(int, float)
+ */
+ @SuppressWarnings("unchecked")
+ public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType, int initialCapacity, float loadFactor) {
- if (isSynchronized) {
- map = new ConcurrentHashMap<K, Collection<V>>(initialCapacity, loadFactor);
- } else {
- map = new HashMap<K, Collection<V>>(initialCapacity, loadFactor);
- }
+ if (isSynchronized) {
+ map = new ConcurrentHashMap<K, Collection<V>>(initialCapacity, loadFactor);
+ } else {
+ map = new HashMap<K, Collection<V>>(initialCapacity, loadFactor);
+ }
- this.isSynchronized = isSynchronized;
- this.collectionType = collectionType;
- }
+ this.isSynchronized = isSynchronized;
+ this.collectionType = collectionType;
+ }
- /**
- * @param isSynchronized - If true, the Map & Collection will both be synchronized using the
- * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be synchronzied
- * and therefore not threadsafe.
- * @param collectionType - The type of collection to use to as the values within the HashMap.
- * @param initialCapacity
- * @see HashMap#HashMap(int)
- */
- @SuppressWarnings("unchecked")
- public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType, int initialCapacity) {
- if (isSynchronized) {
- map = new ConcurrentHashMap<K, Collection<V>>(initialCapacity);
- } else {
- map = new HashMap<K, Collection<V>>(initialCapacity);
- }
+ /**
+ * @param isSynchronized - If true, the Map & Collection will both be synchronized using the
+ * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be synchronzied
+ * and therefore not threadsafe.
+ * @param collectionType - The type of collection to use to as the values within the HashMap.
+ * @param initialCapacity
+ * @see HashMap#HashMap(int)
+ */
+ @SuppressWarnings("unchecked")
+ public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType, int initialCapacity) {
+ if (isSynchronized) {
+ map = new ConcurrentHashMap<K, Collection<V>>(initialCapacity);
+ } else {
+ map = new HashMap<K, Collection<V>>(initialCapacity);
+ }
- this.isSynchronized = isSynchronized;
- this.collectionType = collectionType;
- }
+ this.isSynchronized = isSynchronized;
+ this.collectionType = collectionType;
+ }
- /**
- * @param isSynchronized - If true, the Map & Collection will both be synchronized using the
- * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be synchronzied
- * and therefore not threadsafe.
- * @param collectionType - The type of collection to use to as the values within the HashMap.
- * @see HashMap#HashMap()
- */
- @SuppressWarnings("unchecked")
- public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType) {
- if (isSynchronized) {
- map = new ConcurrentHashMap<K, Collection<V>>();
- } else {
- map = new HashMap<K, Collection<V>>();
- }
- this.isSynchronized = isSynchronized;
- this.collectionType = collectionType;
- }
+ /**
+ * @param isSynchronized - If true, the Map & Collection will both be synchronized using the
+ * Collections.synchronizedMap & Collections.synchronizedCollection. otherwise, this class will not be synchronzied
+ * and therefore not threadsafe.
+ * @param collectionType - The type of collection to use to as the values within the HashMap.
+ * @see HashMap#HashMap()
+ */
+ @SuppressWarnings("unchecked")
+ public HashCollection(boolean isSynchronized, Class<? extends Collection> collectionType) {
+ if (isSynchronized) {
+ map = new ConcurrentHashMap<K, Collection<V>>();
+ } else {
+ map = new HashMap<K, Collection<V>>();
+ }
+ this.isSynchronized = isSynchronized;
+ this.collectionType = collectionType;
+ }
- /**
- * Creates an unsynchronized Plus using a default Collection type (ArrayList)
- *
- * @see HashMap#HashMap(int, float)
- */
- public HashCollection(int initialCapacity, float loadFactor) {
- this(false, DEFAULT_COLLECTION_TYPE, initialCapacity, loadFactor);
- }
+ /**
+ * Creates an unsynchronized Plus using a default Collection type (ArrayList)
+ *
+ * @see HashMap#HashMap(int, float)
+ */
+ public HashCollection(int initialCapacity, float loadFactor) {
+ this(false, DEFAULT_COLLECTION_TYPE, initialCapacity, loadFactor);
+ }
- /**
- * Creates an unsynchronized Plus using a default Collection type (ArrayList)
- *
- * @see HashMap#HashMap(int)
- */
- public HashCollection(int initialCapacity) {
- this(false, DEFAULT_COLLECTION_TYPE, initialCapacity);
- }
+ /**
+ * Creates an unsynchronized Plus using a default Collection type (ArrayList)
+ *
+ * @see HashMap#HashMap(int)
+ */
+ public HashCollection(int initialCapacity) {
+ this(false, DEFAULT_COLLECTION_TYPE, initialCapacity);
+ }
- public HashCollection(boolean isSynchronized) {
- this(isSynchronized, DEFAULT_COLLECTION_TYPE);
- }
+ public HashCollection(boolean isSynchronized) {
+ this(isSynchronized, DEFAULT_COLLECTION_TYPE);
+ }
- public HashCollection() {
- this(false, DEFAULT_COLLECTION_TYPE, 0);
- }
+ public HashCollection() {
+ this(false, DEFAULT_COLLECTION_TYPE, 0);
+ }
- /********************************************************************************************************************
- * Methods
- *******************************************************************************************************************/
+ /********************************************************************************************************************
+ * Methods
+ *******************************************************************************************************************/
- /**
- * Adds the value to the collection specified by the key. If there is not a collection for the given key, a new
- * collection is created and added to the hash.
- *
- * @param key The key whose collection we will add value to.
- * @param value The value to be added.
- * @return the collection containing value and all other items associated with the key.
- */
- @SuppressWarnings("unchecked")
- public Collection<V> put(K key, V value) {
- Collection<V> collection = map.get(key);
- if (collection == null) {
- try {
- if (isSynchronized) {
- collection = Collections.synchronizedCollection(collectionType.newInstance());
- } else {
- collection = collectionType.newInstance();
- }
- map.put(key, collection);
- } catch (InstantiationException ex) {
- ex.printStackTrace();
- return null;
- } catch (IllegalAccessException ex) {
- ex.printStackTrace();
- return null;
- }
- }
- collection.add(value);
- return collection;
- }
+ /**
+ * Adds the value to the collection specified by the key. If there is not a collection for the given key, a new
+ * collection is created and added to the hash.
+ *
+ * @param key The key whose collection we will add value to.
+ * @param value The value to be added.
+ * @return the collection containing value and all other items associated with the key.
+ */
+ @SuppressWarnings("unchecked")
+ public Collection<V> put(K key, V value) {
+ Collection<V> collection = map.get(key);
+ if (collection == null) {
+ try {
+ if (isSynchronized) {
+ collection = Collections.synchronizedCollection(collectionType.newInstance());
+ } else {
+ collection = collectionType.newInstance();
+ }
+ map.put(key, collection);
+ } catch (InstantiationException ex) {
+ ex.printStackTrace();
+ return null;
+ } catch (IllegalAccessException ex) {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+ collection.add(value);
+ return collection;
+ }
- /**
- * Adds all of the items in the Collection values to the collection for the specified key.
- *
- * @param key The key to add the values to
- * @param values The values to be added
- * @return The collection for the key, containing all values.
- */
- public Collection<V> put(K key, Collection<V> values) {
- Collection<V> items = null;
- for (V value : values) {
- if (items == null) {
- items = this.put(key, value);
- } else {
- items.add(value);
- }
- }
- return items;
- }
+ /**
+ * Adds all of the items in the Collection values to the collection for the specified key.
+ *
+ * @param key The key to add the values to
+ * @param values The values to be added
+ * @return The collection for the key, containing all values.
+ */
+ public Collection<V> put(K key, Collection<V> values) {
+ Collection<V> items = null;
+ for (V value : values) {
+ if (items == null) {
+ items = this.put(key, value);
+ } else {
+ items.add(value);
+ }
+ }
+ return items;
+ }
- /**
- * @param key The key whose collection we will remove value from.
- * @param value The value to be removed
- * @return true iff the value was removed from the collection for key.
- */
- public boolean removeValue(K key, V value) {
- Collection<V> collection = map.get(key);
- if (collection != null) {
- if (collection.remove(value)) {
- if (collection.isEmpty()) {
- map.remove(key);
- }
- return true;
- }
- }
- return false;
- }
+ /**
+ * @param key The key whose collection we will remove value from.
+ * @param value The value to be removed
+ * @return true iff the value was removed from the collection for key.
+ */
+ public boolean removeValue(K key, V value) {
+ Collection<V> collection = map.get(key);
+ if (collection != null) {
+ if (collection.remove(value)) {
+ if (collection.isEmpty()) {
+ map.remove(key);
+ }
+ return true;
+ }
+ }
+ return false;
+ }
- public Collection<V> removeValues(K key) {
- Collection<V> objectPair = map.remove(key);
- if (objectPair == null) {
- return Collections.emptyList();
- }
- return objectPair;
- }
+ public Collection<V> removeValues(K key) {
+ Collection<V> objectPair = map.remove(key);
+ if (objectPair == null) {
+ return Collections.emptyList();
+ }
+ return objectPair;
+ }
- /**
- * Returns the Collection of items for this key, or null if the key does not exist.
- *
- * @param key
- * @return Return value collection reference
- */
- public Collection<V> getValues(K key) {
- return map.get(key);
- }
+ /**
+ * Returns the Collection of items for this key, or null if the key does not exist.
+ *
+ * @param key
+ * @return Return value collection reference
+ */
+ public Collection<V> getValues(K key) {
+ return map.get(key);
+ }
- /**
- * Returns the Collection all items
- *
- * @param key
- * @return Return value collection reference
- */
- public List<V> getValues() {
- List<V> values = new ArrayList<V>();
- for (Collection<V> objectPair : map.values()) {
- if (objectPair != null) {
- values.addAll(objectPair);
- }
- }
- return values;
- }
+ /**
+ * Returns the Collection all items
+ *
+ * @param key
+ * @return Return value collection reference
+ */
+ public List<V> getValues() {
+ List<V> values = new ArrayList<V>();
+ for (Collection<V> objectPair : map.values()) {
+ if (objectPair != null) {
+ values.addAll(objectPair);
+ }
+ }
+ return values;
+ }
- public Set<K> keySet() {
- return map.keySet();
- }
+ public Set<K> keySet() {
+ return map.keySet();
+ }
- public void clear() {
- map.clear();
- }
+ public void clear() {
+ map.clear();
+ }
- public boolean containsKey(K key) {
- return map.containsKey(key);
- }
+ public boolean containsKey(K key) {
+ return map.containsKey(key);
+ }
- public boolean isEmpty() {
- return map.isEmpty();
- }
+ public boolean isEmpty() {
+ return map.isEmpty();
+ }
- /**
- * The total number of key-value combinations
- */
- public int size() {
- int size = 0;
- Set<K> keySet = keySet();
+ /**
+ * The total number of key-value combinations
+ */
+ public int size() {
+ int size = 0;
+ Set<K> keySet = keySet();
- synchronized (map) {
- for (K key : keySet) {
- size += getValues(key).size();
- }
- }
- return size;
- }
+ synchronized (map) {
+ for (K key : keySet) {
+ size += getValues(key).size();
+ }
+ }
+ return size;
+ }
- /**
- * @param value
- * @return whether the map contains this value
- */
- public boolean containsValue(Object value) {
- for (Collection<V> collection : map.values()) {
- if (collection != null) {
- for (V tempValue : collection) {
- if (value.equals(tempValue)) {
- return true;
- }
- }
- }
- }
- return false;
- }
+ /**
+ * @param value
+ * @return whether the map contains this value
+ */
+ public boolean containsValue(Object value) {
+ for (Collection<V> collection : map.values()) {
+ if (collection != null) {
+ for (V tempValue : collection) {
+ if (value.equals(tempValue)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
- @Override
- public String toString() {
- return map.toString();
- }
+ @Override
+ public String toString() {
+ return map.toString();
+ }
}

Back to the top