You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by se...@apache.org on 2014/09/26 16:20:36 UTC
svn commit: r1627792 [2/2] - in
/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2:
ae/ concept/ consumer/ dictionary/ util/collection/
Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/ArrayListMap.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/ArrayListMap.java?rev=1627792&r1=1627791&r2=1627792&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/ArrayListMap.java (original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/ArrayListMap.java Fri Sep 26 14:20:36 2014
@@ -7,83 +7,57 @@ import java.util.*;
* Affiliation: CHIP-NLP
* Date: 7/23/14
*/
-final public class ArrayListMap<K, V> extends HashMap<K, List<V>> implements CollectionMap<K, V> {
+final public class ArrayListMap<K, V> implements CollectionMap<K, V, List<V>> {
+
+ private final CollectionMap<K, V, List<V>> _delegate;
+
public ArrayListMap() {
- super();
+ final Map<K, List<V>> hashMap = new HashMap<>();
+ final CollectionCreator<V, List<V>> creator = CollectionCreatorFactory.createListCreator();
+ _delegate = new DefaultCollectionMap<>( hashMap, creator );
}
/**
- * @param size initial size of the ArrayListMap
+ * @param size initial size of the HashSetMap
*/
public ArrayListMap( final int size ) {
- super( size );
+ final Map<K, List<V>> hashMap = new HashMap<>( size );
+ final CollectionCreator<V, List<V>> creator = CollectionCreatorFactory.createListCreator();
+ _delegate = new DefaultCollectionMap<>( hashMap, creator );
}
+
/**
* {@inheritDoc}
*/
@Override
- public Iterator<Map.Entry<K, Collection<V>>> iterator() {
- final Iterator<Map.Entry<K, List<V>>> setIterator = entrySet().iterator();
- return new Iterator<Map.Entry<K, Collection<V>>>() {
- public boolean hasNext() {
- return setIterator.hasNext();
- }
-
- public Map.Entry<K, Collection<V>> next() {
- final Map.Entry<K, List<V>> next = setIterator.next();
- return new Map.Entry<K, Collection<V>>() {
- public K getKey() {
- return next.getKey();
- }
-
- public Collection<V> getValue() {
- return next.getValue();
- }
-
- public Collection<V> setValue( final Collection<V> value ) {
- return null;
- }
- };
- }
-
- public void remove() {
- }
- };
+ public Iterator<Map.Entry<K, List<V>>> iterator() {
+ return _delegate.iterator();
}
/**
* {@inheritDoc}
*/
@Override
- public Collection<Collection<V>> getAllCollections() {
- return new HashSet<Collection<V>>( values() );
+ public Collection<List<V>> getAllCollections() {
+ return new HashSet<>( _delegate.values() );
}
/**
* {@inheritDoc}
*/
@Override
- public Collection<V> getCollection( final K key ) {
- final List<V> list = get( key );
- if ( list != null ) {
- return list;
- }
- return Collections.emptyList();
+ public List<V> getCollection( final K key ) {
+ return _delegate.getCollection( key );
}
/**
* {@inheritDoc}
*/
@Override
- public Collection<V> obtainCollection( final K key ) {
- List<V> list = get( key );
- if ( list == null ) {
- list = new ArrayList<>();
- put( key, list );
- }
- return list;
+ public List<V> obtainCollection( final K key ) {
+ return _delegate.obtainCollection( key );
}
@@ -92,8 +66,7 @@ final public class ArrayListMap<K, V> ex
*/
@Override
public boolean containsValue( final K key, final V value ) {
- final Collection<V> values = get( key );
- return values != null && values.contains( value );
+ return _delegate.containsValue( key, value );
}
/**
@@ -101,12 +74,7 @@ final public class ArrayListMap<K, V> ex
*/
@Override
public boolean placeValue( final K key, final V value ) {
- List<V> list = get( key );
- if ( list == null ) {
- list = new ArrayList<>();
- put( key, list );
- }
- return list.add( value );
+ return _delegate.placeValue( key, value );
}
/**
@@ -114,12 +82,7 @@ final public class ArrayListMap<K, V> ex
*/
@Override
public boolean placeMap( final Map<K, V> map ) {
- boolean placedAny = false;
- for ( Map.Entry<K, V> entry : map.entrySet() ) {
- final boolean placed = placeValue( entry.getKey(), entry.getValue() );
- placedAny = placedAny || placed;
- }
- return placedAny;
+ return _delegate.placeMap( map );
}
/**
@@ -127,26 +90,15 @@ final public class ArrayListMap<K, V> ex
*/
@Override
public void removeValue( final K key, final V value ) {
- final List<V> list = get( key );
- if ( list == null ) {
- return;
- }
- list.remove( value );
+ _delegate.removeValue( key, value );
}
/**
* {@inheritDoc}
*/
@Override
- public int addAllValues( final K key, final Collection<V> collection ) {
- List<V> list = get( key );
- if ( list == null ) {
- list = new ArrayList<>();
- put( key, list );
- }
- final int oldSize = list.size();
- list.addAll( collection );
- return list.size() - oldSize;
+ public <C extends Collection<V>> int addAllValues( final K key, final C collection ) {
+ return _delegate.addAllValues( key, collection );
}
/**
@@ -154,22 +106,295 @@ final public class ArrayListMap<K, V> ex
*/
@Override
public void clearCollection( final K key ) {
- List<V> list = get( key );
- if ( list != null ) {
- list.clear();
- }
+ _delegate.clearCollection( key );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int size() {
+ return _delegate.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEmpty() {
+ return _delegate.isEmpty();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsKey( final Object key ) {
+ return _delegate.containsKey( key );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsValue( final Object value ) {
+ return _delegate.containsValue( value );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<V> get( final Object key ) {
+ return _delegate.get( key );
+ }
+
+ // Modification Operations
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<V> put( final K key, final List<V> value ) {
+ return _delegate.put( key, value );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<V> remove( final Object key ) {
+ return _delegate.remove( key );
+ }
+
+
+ // Bulk Operations
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void putAll( final Map<? extends K, ? extends List<V>> map ) {
+ _delegate.putAll( map );
}
/**
* {@inheritDoc}
*/
@Override
- public Map<K, Collection<V>> toSimpleMap() {
- final Map<K, Collection<V>> simpleMap = new HashMap<>( size() );
- for ( K key : keySet() ) {
- simpleMap.put( key, obtainCollection( key ) );
- }
- return simpleMap;
+ public void clear() {
+ _delegate.clear();
}
+
+ // Views
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<K> keySet() {
+ return _delegate.keySet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection<List<V>> values() {
+ return _delegate.values();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Map.Entry<K, List<V>>> entrySet() {
+ return _delegate.entrySet();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Map<K, List<V>> toSimpleMap() {
+ return _delegate;
+ }
+
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+// public ArrayListMap() {
+// super();
+// }
+//
+// /**
+// * @param size initial size of the ArrayListMap
+// */
+// public ArrayListMap( final int size ) {
+// super( size );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Iterator<Map.Entry<K, Collection<V>>> iterator() {
+// final Iterator<Map.Entry<K, List<V>>> setIterator = entrySet().iterator();
+// return new Iterator<Map.Entry<K, Collection<V>>>() {
+// public boolean hasNext() {
+// return setIterator.hasNext();
+// }
+//
+// public Map.Entry<K, Collection<V>> next() {
+// final Map.Entry<K, List<V>> next = setIterator.next();
+// return new Map.Entry<K, Collection<V>>() {
+// public K getKey() {
+// return next.getKey();
+// }
+//
+// public Collection<V> getValue() {
+// return next.getValue();
+// }
+//
+// public Collection<V> setValue( final Collection<V> value ) {
+// return null;
+// }
+// };
+// }
+//
+// public void remove() {
+// }
+// };
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Collection<Collection<V>> getAllCollections() {
+// return new HashSet<Collection<V>>( values() );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Collection<V> getCollection( final K key ) {
+// final List<V> list = get( key );
+// if ( list != null ) {
+// return list;
+// }
+// return Collections.emptyList();
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Collection<V> obtainCollection( final K key ) {
+// List<V> list = get( key );
+// if ( list == null ) {
+// list = new ArrayList<>();
+// put( key, list );
+// }
+// return list;
+// }
+//
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public boolean containsValue( final K key, final V value ) {
+// final Collection<V> values = get( key );
+// return values != null && values.contains( value );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public boolean placeValue( final K key, final V value ) {
+// List<V> list = get( key );
+// if ( list == null ) {
+// list = new ArrayList<>();
+// put( key, list );
+// }
+// return list.add( value );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public boolean placeMap( final Map<K, V> map ) {
+// boolean placedAny = false;
+// for ( Map.Entry<K, V> entry : map.entrySet() ) {
+// final boolean placed = placeValue( entry.getKey(), entry.getValue() );
+// placedAny = placedAny || placed;
+// }
+// return placedAny;
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public void removeValue( final K key, final V value ) {
+// final List<V> list = get( key );
+// if ( list == null ) {
+// return;
+// }
+// list.remove( value );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public int addAllValues( final K key, final Collection<V> collection ) {
+// List<V> list = get( key );
+// if ( list == null ) {
+// list = new ArrayList<>();
+// put( key, list );
+// }
+// final int oldSize = list.size();
+// list.addAll( collection );
+// return list.size() - oldSize;
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public void clearCollection( final K key ) {
+// List<V> list = get( key );
+// if ( list != null ) {
+// list.clear();
+// }
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Map<K, Collection<V>> toSimpleMap() {
+// final Map<K, Collection<V>> simpleMap = new HashMap<>( size() );
+// for ( K key : keySet() ) {
+// simpleMap.put( key, obtainCollection( key ) );
+// }
+// return simpleMap;
+// }
+
}
Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionMap.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionMap.java?rev=1627792&r1=1627791&r2=1627792&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionMap.java (original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/CollectionMap.java Fri Sep 26 14:20:36 2014
@@ -2,39 +2,27 @@ package org.apache.ctakes.dictionary.loo
import java.util.Collection;
import java.util.Map;
-import java.util.Set;
/**
* Author: SPF
* Affiliation: CHIP-NLP
* Date: 6/24/14
*/
-public interface CollectionMap<K, V> extends Iterable<Map.Entry<K, Collection<V>>> {
-
-
- public Set<K> keySet();
+public interface CollectionMap<K, V, T extends Collection<V>> extends Map<K, T>, Iterable<Map.Entry<K, T>> {
/**
* @return all of the collections for all keys
*/
- public Collection<Collection<V>> getAllCollections();
+ public Collection<T> getAllCollections();
/**
- * check the collection map for a key
- *
- * @param key key for internal collection
- * @return <tt>true</tt> if this CollectionMap contain the key
- */
- public boolean containsKey( K key );
-
- /**
* gets a collection mapped with key. If one does not exist then an empty collection is returned
*
* @param key key for internal collection
* @return collection mapped with key or an empty collection if there is none
*/
- public Collection<V> getCollection( K key );
+ public T getCollection( K key );
/**
* obtains a collection mapped with key. If one does not exist then one is added to this CollectionMap
@@ -42,7 +30,7 @@ public interface CollectionMap<K, V> ext
* @param key key for internal collection
* @return (possibly new) collection mapped with key
*/
- public Collection<V> obtainCollection( K key );
+ public T obtainCollection( K key );
/**
* check the collection map for a key and value combination
@@ -85,7 +73,7 @@ public interface CollectionMap<K, V> ext
* @param collection collection of values to place in internal collection
* @return the number of new items added
*/
- public int addAllValues( K key, Collection<V> collection );
+ public <C extends Collection<V>> int addAllValues( K key, C collection );
/**
* clearCollection the collection mapped with key
@@ -99,8 +87,7 @@ public interface CollectionMap<K, V> ext
*
* @return map of java.util.Collection
*/
- public Map<K, Collection<V>> toSimpleMap();
+ public Map<K, T> toSimpleMap();
- public boolean isEmpty();
}
Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/HashSetMap.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/HashSetMap.java?rev=1627792&r1=1627791&r2=1627792&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/HashSetMap.java (original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/HashSetMap.java Fri Sep 26 14:20:36 2014
@@ -7,17 +7,24 @@ import java.util.*;
* Affiliation: CHIP-NLP
* Date: 6/24/14
*/
-final public class HashSetMap<K, V> extends HashMap<K, Set<V>> implements CollectionMap<K, V> {
+final public class HashSetMap<K, V> implements CollectionMap<K, V, Set<V>> {
+
+ private final CollectionMap<K, V, Set<V>> _delegate;
+
public HashSetMap() {
- super();
+ final Map<K, Set<V>> hashMap = new HashMap<>();
+ final CollectionCreator<V, Set<V>> creator = CollectionCreatorFactory.createSetCreator();
+ _delegate = new DefaultCollectionMap<>( hashMap, creator );
}
/**
* @param size initial size of the HashSetMap
*/
public HashSetMap( final int size ) {
- super( size );
+ final Map<K, Set<V>> hashMap = new HashMap<>( size );
+ final CollectionCreator<V, Set<V>> creator = CollectionCreatorFactory.createSetCreator();
+ _delegate = new DefaultCollectionMap<>( hashMap, creator );
}
@@ -25,66 +32,32 @@ final public class HashSetMap<K, V> exte
* {@inheritDoc}
*/
@Override
- public Iterator<Map.Entry<K, Collection<V>>> iterator() {
- final Iterator<Map.Entry<K, Set<V>>> setIterator = entrySet().iterator();
- return new Iterator<Map.Entry<K, Collection<V>>>() {
- public boolean hasNext() {
- return setIterator.hasNext();
- }
-
- public Map.Entry<K, Collection<V>> next() {
- final Map.Entry<K, Set<V>> next = setIterator.next();
- return new Map.Entry<K, Collection<V>>() {
- public K getKey() {
- return next.getKey();
- }
-
- public Collection<V> getValue() {
- return next.getValue();
- }
-
- public Collection<V> setValue( final Collection<V> value ) {
- return null;
- }
- };
- }
-
- public void remove() {
- }
- };
+ public Iterator<Map.Entry<K, Set<V>>> iterator() {
+ return _delegate.iterator();
}
/**
* {@inheritDoc}
*/
@Override
- public Collection<Collection<V>> getAllCollections() {
- return new HashSet<Collection<V>>( values() );
+ public Collection<Set<V>> getAllCollections() {
+ return new HashSet<>( _delegate.values() );
}
/**
* {@inheritDoc}
*/
@Override
- public Collection<V> getCollection( final K key ) {
- final Set<V> set = get( key );
- if ( set != null ) {
- return set;
- }
- return Collections.emptySet();
+ public Set<V> getCollection( final K key ) {
+ return _delegate.getCollection( key );
}
/**
* {@inheritDoc}
*/
@Override
- public Collection<V> obtainCollection( final K key ) {
- Set<V> set = get( key );
- if ( set == null ) {
- set = new HashSet<>();
- put( key, set );
- }
- return set;
+ public Set<V> obtainCollection( final K key ) {
+ return _delegate.obtainCollection( key );
}
@@ -93,8 +66,7 @@ final public class HashSetMap<K, V> exte
*/
@Override
public boolean containsValue( final K key, final V value ) {
- final Collection<V> values = get( key );
- return values != null && values.contains( value );
+ return _delegate.containsValue( key, value );
}
/**
@@ -102,12 +74,7 @@ final public class HashSetMap<K, V> exte
*/
@Override
public boolean placeValue( final K key, final V value ) {
- Set<V> set = get( key );
- if ( set == null ) {
- set = new HashSet<>();
- put( key, set );
- }
- return set.add( value );
+ return _delegate.placeValue( key, value );
}
/**
@@ -115,12 +82,7 @@ final public class HashSetMap<K, V> exte
*/
@Override
public boolean placeMap( final Map<K, V> map ) {
- boolean placedAny = false;
- for ( Map.Entry<K, V> entry : map.entrySet() ) {
- final boolean placed = placeValue( entry.getKey(), entry.getValue() );
- placedAny = placedAny || placed;
- }
- return placedAny;
+ return _delegate.placeMap( map );
}
/**
@@ -128,26 +90,15 @@ final public class HashSetMap<K, V> exte
*/
@Override
public void removeValue( final K key, final V value ) {
- final Set<V> set = get( key );
- if ( set == null ) {
- return;
- }
- set.remove( value );
+ _delegate.removeValue( key, value );
}
/**
* {@inheritDoc}
*/
@Override
- public int addAllValues( final K key, final Collection<V> collection ) {
- Set<V> set = get( key );
- if ( set == null ) {
- set = new HashSet<>();
- put( key, set );
- }
- final int oldSize = set.size();
- set.addAll( collection );
- return set.size() - oldSize;
+ public <C extends Collection<V>> int addAllValues( final K key, final C collection ) {
+ return _delegate.addAllValues( key, collection );
}
/**
@@ -155,23 +106,313 @@ final public class HashSetMap<K, V> exte
*/
@Override
public void clearCollection( final K key ) {
- final Set<V> set = get( key );
- if ( set != null ) {
- set.clear();
- }
+ _delegate.clearCollection( key );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int size() {
+ return _delegate.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEmpty() {
+ return _delegate.isEmpty();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsKey( final Object key ) {
+ return _delegate.containsKey( key );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsValue( final Object value ) {
+ return _delegate.containsValue( value );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<V> get( final Object key ) {
+ return _delegate.get( key );
+ }
+
+ // Modification Operations
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<V> put( final K key, final Set<V> value ) {
+ return _delegate.put( key, value );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<V> remove( final Object key ) {
+ return _delegate.remove( key );
+ }
+
+
+ // Bulk Operations
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void putAll( final Map<? extends K, ? extends Set<V>> map ) {
+ _delegate.putAll( map );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear() {
+ _delegate.clear();
}
+ // Views
+
/**
* {@inheritDoc}
*/
@Override
- public Map<K, Collection<V>> toSimpleMap() {
- final Map<K, Collection<V>> simpleMap = new HashMap<>( size() );
- for ( K key : keySet() ) {
- simpleMap.put( key, obtainCollection( key ) );
- }
- return simpleMap;
+ public Set<K> keySet() {
+ return _delegate.keySet();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection<Set<V>> values() {
+ return _delegate.values();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Map.Entry<K, Set<V>>> entrySet() {
+ return _delegate.entrySet();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Map<K, Set<V>> toSimpleMap() {
+ return _delegate;
+ }
+
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+// public HashSetMap() {
+// super();
+// }
+//
+// /**
+// * @param size initial size of the HashSetMap
+// */
+// public HashSetMap( final int size ) {
+// super( size );
+// }
+//
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Iterator<Map.Entry<K, Collection<V>>> iterator() {
+// final Iterator<Map.Entry<K, Set<V>>> setIterator = entrySet().iterator();
+// return new Iterator<Map.Entry<K, Collection<V>>>() {
+// public boolean hasNext() {
+// return setIterator.hasNext();
+// }
+//
+// public Map.Entry<K, Collection<V>> next() {
+// final Map.Entry<K, Set<V>> next = setIterator.next();
+// return new Map.Entry<K, Collection<V>>() {
+// public K getKey() {
+// return next.getKey();
+// }
+//
+// public Collection<V> getValue() {
+// return next.getValue();
+// }
+//
+// public Collection<V> setValue( final Collection<V> value ) {
+// return null;
+// }
+// };
+// }
+//
+// public void remove() {
+// }
+// };
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Collection<Collection<V>> getAllCollections() {
+// return new HashSet<Collection<V>>( values() );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Collection<V> getCollection( final K key ) {
+// final Set<V> set = get( key );
+// if ( set != null ) {
+// return set;
+// }
+// return Collections.emptySet();
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Collection<V> obtainCollection( final K key ) {
+// Set<V> set = get( key );
+// if ( set == null ) {
+// set = new HashSet<>();
+// put( key, set );
+// }
+// return set;
+// }
+//
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public boolean containsValue( final K key, final V value ) {
+// final Collection<V> values = get( key );
+// return values != null && values.contains( value );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public boolean placeValue( final K key, final V value ) {
+// Set<V> set = get( key );
+// if ( set == null ) {
+// set = new HashSet<>();
+// put( key, set );
+// }
+// return set.add( value );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public boolean placeMap( final Map<K, V> map ) {
+// boolean placedAny = false;
+// for ( Map.Entry<K, V> entry : map.entrySet() ) {
+// final boolean placed = placeValue( entry.getKey(), entry.getValue() );
+// placedAny = placedAny || placed;
+// }
+// return placedAny;
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public void removeValue( final K key, final V value ) {
+// final Set<V> set = get( key );
+// if ( set == null ) {
+// return;
+// }
+// set.remove( value );
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public int addAllValues( final K key, final Collection<V> collection ) {
+// Set<V> set = get( key );
+// if ( set == null ) {
+// set = new HashSet<>();
+// put( key, set );
+// }
+// final int oldSize = set.size();
+// set.addAll( collection );
+// return set.size() - oldSize;
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public void clearCollection( final K key ) {
+// final Set<V> set = get( key );
+// if ( set != null ) {
+// set.clear();
+// }
+// }
+//
+//
+// /**
+// * {@inheritDoc}
+// */
+// @Override
+// public Map<K, Collection<V>> toSimpleMap() {
+// final Map<K, Collection<V>> simpleMap = new HashMap<>( size() );
+// for ( K key : keySet() ) {
+// simpleMap.put( key, obtainCollection( key ) );
+// }
+// return simpleMap;
+// }
+
}
Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/ImmutableCollectionMap.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/ImmutableCollectionMap.java?rev=1627792&r1=1627791&r2=1627792&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/ImmutableCollectionMap.java (original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/collection/ImmutableCollectionMap.java Fri Sep 26 14:20:36 2014
@@ -9,50 +9,48 @@ import java.util.*;
* Date: 9/5/2014
*/
@Immutable
-final public class ImmutableCollectionMap<K, V> implements CollectionMap<K, V> {
+final public class ImmutableCollectionMap<K, V, T extends Collection<V>> implements CollectionMap<K, V, T> {
- final private CollectionMap<K, V> _protectedMap;
+ private final CollectionMap<K, V, T> _protectedMap;
- public ImmutableCollectionMap( final CollectionMap<K, V> collectionMap ) {
+ public ImmutableCollectionMap( final CollectionMap<K, V, T> collectionMap ) {
_protectedMap = collectionMap;
}
- public Iterator<Map.Entry<K, Collection<V>>> iterator() {
- return _protectedMap.iterator();
- }
/**
* {@inheritDoc}
*/
@Override
- public Set<K> keySet() {
- return Collections.unmodifiableSet( _protectedMap.keySet() );
+ public Iterator<Map.Entry<K, T>> iterator() {
+ return _protectedMap.iterator();
}
/**
* {@inheritDoc}
*/
@Override
- public Collection<Collection<V>> getAllCollections() {
- return Collections.unmodifiableCollection( _protectedMap.getAllCollections() );
+ public Collection<T> getAllCollections() {
+ return new HashSet<>( _protectedMap.values() );
}
/**
* {@inheritDoc}
*/
@Override
- public boolean containsKey( final K key ) {
- return _protectedMap.containsKey( key );
+ public T getCollection( final K key ) {
+ return _protectedMap.getCollection( key );
}
/**
* {@inheritDoc}
*/
@Override
- public Collection<V> getCollection( final K key ) {
- return _protectedMap.getCollection( key );
+ public T obtainCollection( final K key ) {
+ return _protectedMap.obtainCollection( key );
}
+
/**
* {@inheritDoc}
*/
@@ -63,8 +61,6 @@ final public class ImmutableCollectionMa
/**
* {@inheritDoc}
- *
- * @throws java.lang.UnsupportedOperationException
*/
@Override
public boolean placeValue( final K key, final V value ) {
@@ -73,8 +69,6 @@ final public class ImmutableCollectionMa
/**
* {@inheritDoc}
- *
- * @throws java.lang.UnsupportedOperationException
*/
@Override
public boolean placeMap( final Map<K, V> map ) {
@@ -85,37 +79,73 @@ final public class ImmutableCollectionMa
* {@inheritDoc}
*/
@Override
- public Collection<V> obtainCollection( final K key ) {
- return getCollection( key );
+ public void removeValue( final K key, final V value ) {
+ throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
- *
- * @throws java.lang.UnsupportedOperationException
*/
@Override
- public void removeValue( final K key, final V value ) {
+ public <C extends Collection<V>> int addAllValues( final K key, final C collection ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
- *
- * @throws java.lang.UnsupportedOperationException
*/
@Override
- public int addAllValues( final K key, final Collection<V> collection ) {
+ public void clearCollection( final K key ) {
throw new UnsupportedOperationException();
}
/**
* {@inheritDoc}
- *
- * @throws java.lang.UnsupportedOperationException
*/
@Override
- public void clearCollection( final K key ) {
+ public int size() {
+ return _protectedMap.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isEmpty() {
+ return _protectedMap.isEmpty();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsKey( final Object key ) {
+ return _protectedMap.containsKey( key );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsValue( final Object value ) {
+ return _protectedMap.containsValue( value );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T get( final Object key ) {
+ return _protectedMap.get( key );
+ }
+
+ // Modification Operations
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public T put( final K key, final T value ) {
throw new UnsupportedOperationException();
}
@@ -123,16 +153,63 @@ final public class ImmutableCollectionMa
* {@inheritDoc}
*/
@Override
- public Map<K, Collection<V>> toSimpleMap() {
- return _protectedMap.toSimpleMap();
+ public T remove( final Object key ) {
+ throw new UnsupportedOperationException();
}
+
+ // Bulk Operations
+
/**
* {@inheritDoc}
*/
@Override
- public boolean isEmpty() {
- return _protectedMap.isEmpty();
+ public void putAll( final Map<? extends K, ? extends T> map ) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+
+ // Views
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<K> keySet() {
+ return _protectedMap.keySet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection<T> values() {
+ return _protectedMap.values();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Map.Entry<K, T>> entrySet() {
+ return _protectedMap.entrySet();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Map<K, T> toSimpleMap() {
+ return Collections.unmodifiableMap( _protectedMap );
}
}