ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1719760 [4/4] - in /ctakes/sandbox/dictionary-gui: data/ data/default/ data/optional/ data/small/ data/tim/ data/tiny/ lib/ src/main/java/org/apache/ctakes/dictionary/creator/gui/ctakes/ src/main/java/org/apache/ctakes/dictionary/creator/g...
Date Sun, 13 Dec 2015 04:27:44 GMT
Copied: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/RareWordDbWriter.java (from r1719001, ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/writer/RareWordDbWriter.java)
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/RareWordDbWriter.java?p2=ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/RareWordDbWriter.java&p1=ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/writer/RareWordDbWriter.java&r1=1719001&r2=1719760&rev=1719760&view=diff
==============================================================================
--- ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/writer/RareWordDbWriter.java (original)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/RareWordDbWriter.java Sun Dec 13 04:27:42 2015
@@ -1,189 +1,197 @@
-package org.apache.ctakes.dictionarytool.writer;
+package org.apache.ctakes.dictionary.creator.util;
 
-import org.apache.ctakes.dictionarytool.util.JdbcUtil;
-import org.apache.ctakes.dictionarytool.util.RareWordUtil;
-import org.apache.ctakes.dictionarytool.util.collection.HashSetMap;
+import org.apache.ctakes.dictionary.creator.gui.umls.Concept;
+import org.apache.ctakes.dictionary.creator.gui.umls.Tui;
+import org.apache.ctakes.dictionary.creator.gui.umls.Vocabulary;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
+import static org.apache.ctakes.dictionary.creator.util.LambdaUtil.asSelf;
+import static org.apache.ctakes.dictionary.creator.util.LambdaUtil.zeroLong;
 
 /**
- * <p>
- * CREATE CACHED TABLE CUI_TERMS (
- * CUI BIGINT,
- * RINDEX INTEGER,
- * TCOUNT INTEGER,
- * TEXT VARCHAR(255),
- * RWORD VARCHAR(48)
- * );
- * CREATE INDEX IDX_CUI_TERMS ON CUI_TERMS( RWORD );
- * COMMIT;
- * <p/>
- * CREATE CACHED TABLE TUI ( CUI BIGINT, TUI INTEGER );
- * CREATE INDEX IDX_TUI ON TUI( CUI );
- * COMMIT;
- * <p/>
- * CREATE CACHED TABLE SNOMEDCT ( CUI BIGINT, SNOMEDCT BIGINT );
- * CREATE INDEX IDX_SNOMEDCT ON SNOMEDCT( CUI );
- * COMMIT;
- * <p/>
- * CREATE CACHED TABLE RXNORM ( CUI BIGINT, RXNORM BIGINT );
- * CREATE INDEX IDX_RXNORM ON RXNORM( CUI );
- * COMMIT;
- * <p/>
- * CREATE CACHED TABLE ICD9CD ( CUI BIGINT, ICD9CD VARCHAR( 48 ) );
- * CREATE INDEX IDX_ICD9CD ON ICD9CD( CUI );
- * COMMIT;
- * <p/>
- * CREATE CACHED TABLE ICD10PCS ( CUI BIGINT, ICD10PCS VARCHAR( 48 ) );
- * CREATE INDEX IDX_ICD10PCS ON ICD10PCS( CUI );
- * COMMIT;
- * <p/>
- * CREATE CACHED TABLE PREFTERM ( CUI BIGINT, PREFTERM VARCHAR( 255 ) );
- * CREATE INDEX IDX_PREFTERM ON PREFTERM( CUI );
- * COMMIT;
- * </p>
- * <p/>
  * Author: SPF
  * Affiliation: CHIP-NLP
  * Date: 1/15/14
  */
 final public class RareWordDbWriter {
-   private RareWordDbWriter() {
-   }
 
-   static private enum CuiTermsField {
-      CUI( "CUI", 1, Long.class ), RINDEX( "RINDEX", 2, Integer.class ), TCOUNT( "TCOUNT", 3, Integer.class ),
-      TEXT( "TEXT", 4, String.class ), RWORD( "RWORD", 5, String.class );
-      final private String __name;
-      final private int __index;
-      final private Class __classType;
+   static private final Logger LOGGER = LogManager.getLogger( "RareWordDbWriter" );
 
-      CuiTermsField( final String name, final int index, final Class classType ) {
-         __name = name;
-         __index = index;
-         __classType = classType;
-      }
+   private RareWordDbWriter() {
    }
 
-   static private enum CuiMapField {
-      CUI( "CUI", 1, Long.class ), TUI( "TUI", 2, Integer.class ),
-      ICD9( "ICD9", 3, String.class ), ICD10( "ICD10", 4, String.class ),
-      SNOMED( "SNOMED", 5, Long.class ), RXNORM( "RXNORM", 6, Long.class ), PREFTERM( "PREFTERM", 7, String.class );
-      final private String __name;
+   private enum CuiTermsField {
+      CUI( 1, Long.class ), RINDEX( 2, Integer.class ), TCOUNT( 3, Integer.class ),
+      TEXT( 4, String.class ), RWORD( 5, String.class );
       final private int __index;
       final private Class __classType;
 
-      CuiMapField( final String name, final int index, final Class classType ) {
-         __name = name;
+      CuiTermsField( final int index, final Class classType ) {
          __index = index;
          __classType = classType;
       }
    }
 
 
-   static public void writeCuiTerms( final HashSetMap<Long, Integer> cuiTuis,
-                                     final HashSetMap<Long, String> cuiTexts,
-                                     final String url, final String user, final String pass, final String tableName ) {
+
+   static public boolean writeConcepts( final Map<Long, Concept> concepts,
+                                     final String url, final String user, final String pass ) {
+      // Get Count of appearance in dictionary per term token
+      final Map<String, Integer> tokenCounts = RareWordUtil.getTokenCounts( concepts.values() );
+      // Create insert sql statements
+      final String mainTableSql = JdbcUtil.createRowInsertSql( "CUI_TERMS", CuiTermsField.values() );
+      final String tuiTableSql = JdbcUtil.createCodeInsertSql( "tui" );
+      final String preftermTableSql = JdbcUtil.createCodeInsertSql( "prefterm" );
+      final Map<String,String> insertCodeSqls = createCodeInsertSqls();
+
+      long mainTableCount = 0;
+      long tuiTableCount = 0;
+      long preftermTableCount = 0;
+      final Map<String,Long> codeTableCounts = createCodeCounts();
       final Connection connection = JdbcUtil.createDatabaseConnection( url, user, pass );
-      final String sql = JdbcUtil.createRowInsertSql( tableName, CuiTermsField.values() );
       try {
-         final PreparedStatement rowInsertSql = connection.prepareStatement( sql );
-         final Map<String, Integer> tokenCounts = RareWordUtil.getTokenCounts( cuiTexts );
-         long lineCount = 0;
-         for ( Map.Entry<Long, Set<String>> cuiTextEntry : cuiTexts.entrySet() ) {
-            final Collection<Integer> tuis = cuiTuis.get( cuiTextEntry.getKey() );
-            if ( tuis == null ) {
+         // Create PreparedStatements from insert sql statements
+         final PreparedStatement mainTableStatement = connection.prepareStatement( mainTableSql );
+         final PreparedStatement tuiStatement = connection.prepareStatement( tuiTableSql );
+         final PreparedStatement preftermStatement = connection.prepareStatement( preftermTableSql );
+         final Map<String,PreparedStatement> codeStatements = createCodeStatements( connection, insertCodeSqls );
+
+         for ( Map.Entry<Long, Concept> conceptEntry : concepts.entrySet() ) {
+            final long cui = conceptEntry.getKey();
+            final Concept concept = conceptEntry.getValue();
+            final Collection<String> texts = concept.getTexts();
+            if ( texts.isEmpty() ) {
                continue;
             }
-            for ( String text : cuiTextEntry.getValue() ) {
+            // write main term table
+            for ( String text : conceptEntry.getValue().getTexts() ) {
                final RareWordUtil.IndexedRareWord indexedRareWord = RareWordUtil.getIndexedRareWord( text,
                                                                                                      tokenCounts );
-               rowInsertSql.setLong( CuiTermsField.CUI.__index, cuiTextEntry.getKey() );
-               rowInsertSql.setInt( CuiTermsField.RINDEX.__index, indexedRareWord.__index );
-               rowInsertSql.setInt( CuiTermsField.TCOUNT.__index, indexedRareWord.__tokenCount );
-               rowInsertSql.setString( CuiTermsField.TEXT.__index, text );
-               rowInsertSql.setString( CuiTermsField.RWORD.__index, indexedRareWord.__word );
-               rowInsertSql.executeUpdate();
-               lineCount++;
-               if ( lineCount % 100000 == 0 ) {
-                  System.out.println( "DB Row " + lineCount );
+               mainTableStatement.setLong( CuiTermsField.CUI.__index, cui );
+               mainTableStatement.setInt( CuiTermsField.RINDEX.__index, indexedRareWord.__index );
+               mainTableStatement.setInt( CuiTermsField.TCOUNT.__index, indexedRareWord.__tokenCount );
+               mainTableStatement.setString( CuiTermsField.TEXT.__index, text );
+               mainTableStatement.setString( CuiTermsField.RWORD.__index, indexedRareWord.__word );
+               mainTableStatement.executeUpdate();
+               mainTableCount = incrementCount( "Main", mainTableCount );
+            }
+            // write tui table
+            for ( Tui tui : concept.getTuis() ) {
+               tuiStatement.setLong( CuiTermsField.CUI.__index, cui );
+               tuiStatement.setInt( 2, tui.getIntValue() );
+               tuiStatement.executeUpdate();
+               tuiTableCount = incrementCount( "Tui", tuiTableCount );
+            }
+            // write preferred term table
+            final String preferredText = concept.getPreferredText();
+            if ( preferredText != null
+                 && !preferredText.isEmpty()
+                 && !preferredText.equals( Concept.PREFERRED_TERM_UNKNOWN ) ) {
+               preftermStatement.setLong( CuiTermsField.CUI.__index, cui );
+               preftermStatement.setString( 2, preferredText );
+               preftermStatement.executeUpdate();
+               preftermTableCount = incrementCount( "Preferred Term", preftermTableCount );
+            }
+            // write extra vocabulary code tables
+            final Collection<String> vocabularies = concept.getVocabularies();
+            for ( String vocabulary : vocabularies ) {
+               final PreparedStatement statement = codeStatements.get( vocabulary );
+               statement.setLong( CuiTermsField.CUI.__index, cui );
+               for ( String code : concept.getCodes( vocabulary ) ) {
+                  setCodeAppropriately( statement, code, Vocabulary.getInstance().getVocabularyClass( vocabulary ) );
+                  statement.executeUpdate();
+                  codeTableCounts.put( vocabulary, incrementCount( vocabulary, codeTableCounts.get( vocabulary ) ) );
                }
             }
          }
-         System.out.println( "DB Rows " + lineCount );
-
-         final Statement statement = connection.createStatement();
-         statement.execute( "commit" );
-         rowInsertSql.close();
+         connection.commit();
+         mainTableStatement.close();
+         tuiStatement.close();
+         preftermStatement.close();
+         preftermStatement.close();
+         for ( PreparedStatement codeStatement : codeStatements.values() ) {
+            codeStatement.close();
+         }
+         final Statement writeDelayStatement = connection.createStatement();
+         writeDelayStatement.execute( "SET WRITE_DELAY FALSE" );
+         writeDelayStatement.close();
+         final Statement setBinaryStatement = connection.createStatement();
+         setBinaryStatement.execute( "SET SCRIPTFORMAT BINARY" );
+         setBinaryStatement.close();
+         final Statement readOnlyStatement = connection.createStatement();
+         readOnlyStatement.execute( "SET READONLY TRUE" );
+         readOnlyStatement.close();
+         final Statement shutdownStatement = connection.createStatement();
+         shutdownStatement.execute( "SHUTDOWN" );
+         shutdownStatement.close();
+         connection.commit();
+         connection.close();
       } catch ( SQLException sqlE ) {
-         System.err.println( sqlE.getMessage() );
+         LOGGER.error( sqlE.getMessage() );
+         return false;
       }
+      LOGGER.info( "Main Table Rows " + mainTableCount );
+      LOGGER.info( "Tui Table Rows " + tuiTableCount );
+      LOGGER.info( "Preferred Term Table Rows " + preftermTableCount );
+      final Function<String,String> getCountInfo
+            = vocabulary -> vocabulary + " Table Rows " + codeTableCounts.get( vocabulary );
+      Vocabulary.getInstance().getAllVocabularies().stream().map( getCountInfo ).forEach( LOGGER::info );
+      return true;
    }
 
-   // TODO switch to cui map
-   //   static public void writeCuiMap( final HashSetMap<Long, String> cuiTuis,
-   //                                      final ArrayListMap<Long, String> cuiTexts,
-   //                                      final String url, final String user, final String pass, final String tableName ) {
-   //      final Connection connection = JdbcUtil.createDatabaseConnection( url, user, pass );
-   //      final String sql = JdbcUtil.createRowInsertSql( tableName, CuiTermsField.values() );
-   //      try {
-   //         final PreparedStatement rowInsertSql = connection.prepareStatement( sql );
-   //         final Map<String, Integer> tokenCounts = RareWordUtil.getTokenCounts( cuiTexts );
-   //         long lineCount = 0;
-   //         for ( Map.Entry<Long, List<String>> cuiTextEntry : cuiTexts.entrySet() ) {
-   //            final Collection<String> tuis = cuiTuis.get( cuiTextEntry.getKey() );
-   //            if ( tuis == null ) {
-   //               continue;
-   //            }
-   //            for ( String text : cuiTextEntry.getValue() ) {
-   //               final String[] tokens = text.split( "\\s+" );
-   //               int bestIndex = 0;
-   //               int bestCount = Integer.MAX_VALUE;
-   //               for ( int i = 0; i < tokens.length; i++ ) {
-   //                  Integer count = tokenCounts.get( tokens[i] );
-   //                  if ( count != null && count < bestCount ) {
-   //                     bestIndex = i;
-   //                     bestCount = count;
-   //                  }
-   //               }
-   //               //               rowInsertSql.setString( FIELD.CUI.__index, cuiTextEntry.getKey() );
-   //               // TODO refactor all code to use long for Cuis and int for Tuis.
-   //               // TODO reference and store all cuis as long (sql bigint)
-   //               // TODO put Tuis in secondary table with alternate codes (sno: rx:, etc.) and preferred term
-   //               // TODO On lookup, grab appropriate cuis and text from main table
-   //               // TODO After lookup, upon store of terms, grab tuis, alternate codes, and preferred terms from table 2
-   //               // TODO overall storage requirements -should- be smaller
-   //               // TODO Plus, alternate codes and preferred terms may be tied to Tuis ...
-   //
-   //               rowInsertSql.setLong( CuiTermsField.CUI.__index, cuiTextEntry.getKey() );
-   //               //               rowInsertSql.setString( FIELD.TUI.__index, TokenUtil.createCsvLine( tuis ) );
-   //               rowInsertSql.setInt( CuiTermsField.RINDEX.__index, bestIndex );
-   //               rowInsertSql.setInt( CuiTermsField.TCOUNT.__index, tokens.length );
-   //               rowInsertSql.setString( CuiTermsField.TEXT.__index, text );
-   //               rowInsertSql.setString( CuiTermsField.RWORD.__index, tokens[bestIndex] );
-   //               rowInsertSql.executeUpdate();
-   //               lineCount++;
-   //               if ( lineCount % 100000 == 0 ) {
-   //                  System.out.println( "DB Row " + lineCount );
-   //               }
-   //            }
-   //         }
-   //         System.out.println( "DB Rows " + lineCount );
-   //
-   //         final Statement statement = connection.createStatement();
-   //         statement.execute( "commit" );
-   //         rowInsertSql.close();
-   //      } catch ( SQLException sqlE ) {
-   //         System.err.println( sqlE.getMessage() );
-   //      }
-   //   }
 
+   static private Map<String,String> createCodeInsertSqls() {
+      return Vocabulary.getInstance().getAllVocabularies().stream()
+            .collect( Collectors.toMap( asSelf, JdbcUtil::createCodeInsertSql ) );
+   }
+
+   static private Map<String,PreparedStatement> createCodeStatements( final Connection connection,
+                                                                      final Map<String,String> insertCodeSqls )
+         throws SQLException {
+      final Map<String,PreparedStatement> codeStatements = new HashMap<>( insertCodeSqls.size() );
+      for ( Map.Entry<String,String> codeSql : insertCodeSqls.entrySet() ) {
+         codeStatements.put( codeSql.getKey(), connection.prepareStatement( codeSql.getValue() ) );
+      }
+      return codeStatements;
+   }
+
+   static private Map<String,Long> createCodeCounts() {
+      return Vocabulary.getInstance().getAllVocabularies().stream().collect( Collectors.toMap( asSelf, zeroLong ) );
+   }
+
+   static private void setCodeAppropriately( final PreparedStatement statement, final String code,
+                                             final Class<?> type ) throws SQLException {
+      if ( String.class.equals( type ) ) {
+         statement.setString( 2, code );
+      } else if ( Double.class.equals( type ) ) {
+         statement.setDouble( 2, Double.valueOf( code ) );
+      } else if ( Long.class.equals( type ) ) {
+         statement.setLong( 2, Long.valueOf( code ) );
+      } else if ( Integer.class.equals( type ) ) {
+         statement.setInt( 2, Integer.valueOf( code ) );
+      } else {
+         LOGGER.error( "Could not set code for " + type.getName() );
+         statement.setString( 2, code );
+      }
+   }
+
+   static private long incrementCount( final String name, long count ) {
+      count++;
+      if ( count % 100000 == 0 ) {
+         LOGGER.info( name + " Table Rows " + count );
+      }
+      return count;
+   }
 
 }

Copied: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/RareWordUtil.java (from r1719001, ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/util/RareWordUtil.java)
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/RareWordUtil.java?p2=ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/RareWordUtil.java&p1=ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/util/RareWordUtil.java&r1=1719001&r2=1719760&rev=1719760&view=diff
==============================================================================
--- ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/util/RareWordUtil.java (original)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/RareWordUtil.java Sun Dec 13 04:27:42 2015
@@ -1,13 +1,12 @@
-package org.apache.ctakes.dictionarytool.util;
+package org.apache.ctakes.dictionary.creator.util;
 
-import org.apache.ctakes.dictionarytool.util.collection.HashSetMap;
+import org.apache.ctakes.dictionary.creator.gui.umls.Concept;
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import static org.apache.ctakes.dictionary.creator.util.LambdaUtil.*;
 
 /**
  * Author: SPF
@@ -88,51 +87,27 @@ final public class RareWordUtil {
       return hasLetter && !BAD_POS_TERM_SET.contains( token );
    }
 
-   /**
-    * @param cuiTexts -
-    * @return -
-    * @deprecated
-    */
-   static public Map<String, Integer> getTokenCounts( final Map<String, Collection<String>> cuiTexts ) {
-      final Map<String, Integer> tokenCounts = new HashMap<>();
-      for ( Collection<String> texts : cuiTexts.values() ) {
-         for ( String text : texts ) {
-            final String[] tokens = text.split( "\\s+" );
-            for ( String token : tokens ) {
-               if ( RareWordUtil.isRarableToken( token ) ) {
-                  Integer count = tokenCounts.get( token );
-                  if ( count == null ) {
-                     count = 0;
-                  }
-                  tokenCounts.put( token, (count + 1) );
-               }
-            }
 
-         }
-      }
-      return tokenCounts;
-   }
+   static private final Pattern SPACE_PATTERN = Pattern.compile( "\\s+" );
 
-   static public Map<String, Integer> getTokenCounts( final HashSetMap<Long, String> cuiTexts ) {
-      final Map<String, Integer> tokenCounts = new HashMap<>();
-      for ( Collection<String> texts : cuiTexts.values() ) {
-         for ( String text : texts ) {
-            final String[] tokens = text.split( "\\s+" );
-            for ( String token : tokens ) {
-               if ( RareWordUtil.isRarableToken( token ) ) {
-                  Integer count = tokenCounts.get( token );
-                  if ( count == null ) {
-                     count = 0;
-                  }
-                  tokenCounts.put( token, (count + 1) );
-               }
-            }
 
-         }
-      }
-      return tokenCounts;
+   static public Map<String, Integer> getTokenCounts( final Collection<Concept> concepts ) {
+      return concepts.stream()
+            .map( Concept::getTexts )
+            .flatMap( Collection::stream )
+            .map( SPACE_PATTERN::split )
+            .flatMap( Arrays::stream )
+            .filter( RareWordUtil::isRarableToken )
+            .collect( Collectors.toMap( asSelf, one, sumInt ) );
    }
 
+   static private void incrementCount( final Map<String,Integer> tokenCounts, final String token ) {
+      Integer count = tokenCounts.get( token );
+      if ( count == null ) {
+         count = 0;
+      }
+      tokenCounts.put( token, (count + 1) );
+   }
 
    //   static public String getRareToken( final Map<String,Integer> tokenCounts, final String text ) {
    //      final String[] tokens = text.split( "\\s+" );

Copied: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/TextTokenizer.java (from r1719001, ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/util/token/TextTokenizer.java)
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/TextTokenizer.java?p2=ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/TextTokenizer.java&p1=ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/util/token/TextTokenizer.java&r1=1719001&r2=1719760&rev=1719760&view=diff
==============================================================================
--- ctakes/sandbox/dictionarytool/src/org/apache/ctakes/dictionarytool/util/token/TextTokenizer.java (original)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/TextTokenizer.java Sun Dec 13 04:27:42 2015
@@ -1,4 +1,4 @@
-package org.apache.ctakes.dictionarytool.util.token;
+package org.apache.ctakes.dictionary.creator.util;
 
 import java.util.*;
 

Added: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/ArrayListMap.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/ArrayListMap.java?rev=1719760&view=auto
==============================================================================
--- ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/ArrayListMap.java (added)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/ArrayListMap.java Sun Dec 13 04:27:42 2015
@@ -0,0 +1,225 @@
+package org.apache.ctakes.dictionary.creator.util.collection;
+
+import java.util.*;
+
+/**
+ * Author: SPF
+ * Affiliation: CHIP-NLP
+ * Date: 7/23/14
+ */
+final public class ArrayListMap<K, V> implements CollectionMap<K, V, List<V>> {
+
+   private final CollectionMap<K, V, List<V>> _delegate;
+
+
+   public ArrayListMap() {
+      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 HashSetMap
+    */
+   public ArrayListMap( final int 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<Entry<K, List<V>>> iterator() {
+      return _delegate.iterator();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<List<V>> getAllCollections() {
+      return new HashSet<>( _delegate.values() );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public List<V> getCollection( final K key ) {
+      return _delegate.getCollection( key );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public List<V> obtainCollection( final K key ) {
+      return _delegate.obtainCollection( key );
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final K key, final V value ) {
+      return _delegate.containsValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeValue( final K key, final V value ) {
+      return _delegate.placeValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeMap( final Map<K, V> map ) {
+      return _delegate.placeMap( map );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void removeValue( final K key, final V value ) {
+      _delegate.removeValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public <C extends Collection<V>> int addAllValues( final K key, final C collection ) {
+      return _delegate.addAllValues( key, collection );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clearCollection( final K key ) {
+      _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 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<Entry<K, List<V>>> entrySet() {
+      return _delegate.entrySet();
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Map<K, List<V>> toSimpleMap() {
+      return _delegate;
+   }
+
+}

Added: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionCreator.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionCreator.java?rev=1719760&view=auto
==============================================================================
--- ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionCreator.java (added)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionCreator.java Sun Dec 13 04:27:42 2015
@@ -0,0 +1,17 @@
+package org.apache.ctakes.dictionary.creator.util.collection;
+
+import java.util.Collection;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+public interface CollectionCreator<V, T extends Collection<V>> {
+
+   public T createCollection();
+
+   public T createCollection( int size );
+
+
+}

Added: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionCreatorFactory.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionCreatorFactory.java?rev=1719760&view=auto
==============================================================================
--- ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionCreatorFactory.java (added)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionCreatorFactory.java Sun Dec 13 04:27:42 2015
@@ -0,0 +1,46 @@
+package org.apache.ctakes.dictionary.creator.util.collection;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+final public class CollectionCreatorFactory {
+
+   private CollectionCreatorFactory() {
+   }
+
+   static public <V> CollectionCreator<V, Set<V>> createSetCreator() {
+      return new CollectionCreator<V, Set<V>>() {
+         @Override
+         public Set<V> createCollection() {
+            return new HashSet<>();
+         }
+
+         @Override
+         public Set<V> createCollection( final int size ) {
+            return new HashSet<>( size );
+         }
+      };
+   }
+
+   static public <V> CollectionCreator<V, List<V>> createListCreator() {
+      return new CollectionCreator<V, List<V>>() {
+         @Override
+         public List<V> createCollection() {
+            return new ArrayList<>();
+         }
+
+         @Override
+         public List<V> createCollection( final int size ) {
+            return new ArrayList<>( size );
+         }
+      };
+   }
+
+}

Added: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionMap.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionMap.java?rev=1719760&view=auto
==============================================================================
--- ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionMap.java (added)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/CollectionMap.java Sun Dec 13 04:27:42 2015
@@ -0,0 +1,93 @@
+package org.apache.ctakes.dictionary.creator.util.collection;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Author: SPF
+ * Affiliation: CHIP-NLP
+ * Date: 6/24/14
+ */
+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<T> getAllCollections();
+
+
+   /**
+    * 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 T getCollection( K key );
+
+   /**
+    * obtains a collection mapped with key.  If one does not exist then one is added to this CollectionMap
+    *
+    * @param key key for internal collection
+    * @return (possibly new) collection mapped with key
+    */
+   public T obtainCollection( K key );
+
+   /**
+    * check the collection map for a key and value combination
+    *
+    * @param key   key for internal collection
+    * @param value value to check in internal collection
+    * @return <tt>true</tt> if this CollectionMap contain the value for the given key
+    */
+   public boolean containsValue( K key, V value );
+
+   /**
+    * places value into a collection mapped with key
+    *
+    * @param key   key for internal collection
+    * @param value value to placeValue in internal collection
+    * @return <tt>true</tt> if this set did not already contain the value
+    */
+   public boolean placeValue( K key, V value );
+
+   /**
+    * places each value of a map into a collection mapped with the appropriate key
+    *
+    * @param map map to store
+    * @return <tt>true</tt> if this set did not already contain the value
+    */
+   public boolean placeMap( Map<K, V> map );
+
+   /**
+    * removes value from a collection mapped with key
+    *
+    * @param key   key for internal collection
+    * @param value value to remove from internal collection
+    */
+   public void removeValue( K key, V value );
+
+   /**
+    * adds everything from the given collection to the internal collection mapped with key
+    *
+    * @param key        key for internal collection
+    * @param collection collection of values to place in internal collection
+    * @return the number of new items added
+    */
+   public <C extends Collection<V>> int addAllValues( K key, C collection );
+
+   /**
+    * clearCollection the collection mapped with key
+    *
+    * @param key key for internal collection
+    */
+   public void clearCollection( K key );
+
+   /**
+    * Copy of this object as a simple (java.util.Collection) map of Collection
+    *
+    * @return map of java.util.Collection
+    */
+   public Map<K, T> toSimpleMap();
+
+
+}

Added: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/DefaultCollectionMap.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/DefaultCollectionMap.java?rev=1719760&view=auto
==============================================================================
--- ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/DefaultCollectionMap.java (added)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/DefaultCollectionMap.java Sun Dec 13 04:27:42 2015
@@ -0,0 +1,279 @@
+package org.apache.ctakes.dictionary.creator.util.collection;
+
+import java.util.*;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+final public class DefaultCollectionMap<K, V, T extends Collection<V>> implements CollectionMap<K, V, T> {
+
+   private final Map<K, T> _delegate;
+   private final CollectionCreator<V, T> _collectionCreator;
+   private final T EMPTY_COLLECTION;
+
+   public DefaultCollectionMap( final Map<K, T> delegate, final CollectionCreator<V, T> collectionCreator ) {
+      _delegate = delegate;
+      _collectionCreator = collectionCreator;
+      EMPTY_COLLECTION = collectionCreator.createCollection();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Iterator<Entry<K, T>> iterator() {
+      final Iterator<Entry<K, T>> setIterator = _delegate.entrySet().iterator();
+      return new Iterator<Entry<K, T>>() {
+         public boolean hasNext() {
+            return setIterator.hasNext();
+         }
+
+         public Entry<K, T> next() {
+            final Entry<K, T> next = setIterator.next();
+            return new Entry<K, T>() {
+               public K getKey() {
+                  return next.getKey();
+               }
+
+               public T getValue() {
+                  return next.getValue();
+               }
+
+               public T setValue( final T value ) {
+                  return null;
+               }
+            };
+         }
+
+         public void remove() {
+         }
+      };
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<T> getAllCollections() {
+      return new HashSet<>( _delegate.values() );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T getCollection( final K key ) {
+      final T collection = _delegate.get( key );
+      if ( collection != null ) {
+         return collection;
+      }
+      return EMPTY_COLLECTION;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T obtainCollection( final K key ) {
+      T collection = _delegate.get( key );
+      if ( collection == null ) {
+         collection = _collectionCreator.createCollection();
+         _delegate.put( key, collection );
+      }
+      return collection;
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final K key, final V value ) {
+      final T collection = _delegate.get( key );
+      return collection != null && collection.contains( value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeValue( final K key, final V value ) {
+      T collection = _delegate.get( key );
+      if ( collection == null ) {
+         collection = _collectionCreator.createCollection();
+         _delegate.put( key, collection );
+      }
+      return collection.add( value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeMap( final Map<K, V> map ) {
+      boolean placedAny = false;
+      for ( 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 T collection = _delegate.get( key );
+      if ( collection == null ) {
+         return;
+      }
+      collection.remove( value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public <C extends Collection<V>> int addAllValues( final K key, final C values ) {
+      if ( values == null || values.isEmpty() ) {
+         return 0;
+      }
+      T collection = _delegate.get( key );
+      if ( collection == null ) {
+         collection = _collectionCreator.createCollection();
+         _delegate.put( key, collection );
+      }
+      final int oldSize = collection.size();
+      collection.addAll( values );
+      return collection.size() - oldSize;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clearCollection( final K key ) {
+      final T collection = _delegate.get( key );
+      if ( collection != null ) {
+         collection.clear();
+      }
+   }
+
+   /**
+    * {@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 T get( final Object key ) {
+      return _delegate.get( key );
+   }
+
+   // Modification Operations
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T put( final K key, final T value ) {
+      return _delegate.put( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T remove( final Object key ) {
+      return _delegate.remove( key );
+   }
+
+
+   // Bulk Operations
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void putAll( final Map<? extends K, ? extends T> map ) {
+      _delegate.putAll( map );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clear() {
+      _delegate.clear();
+   }
+
+
+   // Views
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<K> keySet() {
+      return _delegate.keySet();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<T> values() {
+      return _delegate.values();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<Entry<K, T>> entrySet() {
+      return _delegate.entrySet();
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Map<K, T> toSimpleMap() {
+      return _delegate;
+   }
+
+
+}

Added: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/EnumSetMap.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/EnumSetMap.java?rev=1719760&view=auto
==============================================================================
--- ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/EnumSetMap.java (added)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/EnumSetMap.java Sun Dec 13 04:27:42 2015
@@ -0,0 +1,215 @@
+package org.apache.ctakes.dictionary.creator.util.collection;
+
+import java.util.*;
+
+/**
+ * @author SPF , chip-nlp
+ * @version %I%
+ * @since 9/23/2014
+ */
+final public class EnumSetMap<K extends Enum<K>, V> implements CollectionMap<K, V, Set<V>> {
+
+   private final CollectionMap<K, V, Set<V>> _delegate;
+
+
+   public EnumSetMap( final Class<K> enumType ) {
+      final EnumMap<K, Set<V>> enumMap = new EnumMap<>( enumType );
+      final CollectionCreator<V, Set<V>> creator = CollectionCreatorFactory.createSetCreator();
+      _delegate = new DefaultCollectionMap<>( enumMap, creator );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Iterator<Entry<K, Set<V>>> iterator() {
+      return _delegate.iterator();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<Set<V>> getAllCollections() {
+      return new HashSet<>( _delegate.values() );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> getCollection( final K key ) {
+      return _delegate.getCollection( key );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> obtainCollection( final K key ) {
+      return _delegate.obtainCollection( key );
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final K key, final V value ) {
+      return _delegate.containsValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeValue( final K key, final V value ) {
+      return _delegate.placeValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeMap( final Map<K, V> map ) {
+      return _delegate.placeMap( map );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void removeValue( final K key, final V value ) {
+      _delegate.removeValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public <C extends Collection<V>> int addAllValues( final K key, final C collection ) {
+      return _delegate.addAllValues( key, collection );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clearCollection( final K key ) {
+      _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 Set<K> keySet() {
+      return _delegate.keySet();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<Set<V>> values() {
+      return _delegate.values();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<Entry<K, Set<V>>> entrySet() {
+      return _delegate.entrySet();
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Map<K, Set<V>> toSimpleMap() {
+      return _delegate;
+   }
+
+}

Added: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/HashSetMap.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/HashSetMap.java?rev=1719760&view=auto
==============================================================================
--- ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/HashSetMap.java (added)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/HashSetMap.java Sun Dec 13 04:27:42 2015
@@ -0,0 +1,225 @@
+package org.apache.ctakes.dictionary.creator.util.collection;
+
+import java.util.*;
+
+/**
+ * Author: SPF
+ * Affiliation: CHIP-NLP
+ * Date: 6/24/14
+ */
+final public class HashSetMap<K, V> implements CollectionMap<K, V, Set<V>> {
+
+   private final CollectionMap<K, V, Set<V>> _delegate;
+
+
+   public HashSetMap() {
+      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 ) {
+      final Map<K, Set<V>> hashMap = new HashMap<>( size );
+      final CollectionCreator<V, Set<V>> creator = CollectionCreatorFactory.createSetCreator();
+      _delegate = new DefaultCollectionMap<>( hashMap, creator );
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Iterator<Entry<K, Set<V>>> iterator() {
+      return _delegate.iterator();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<Set<V>> getAllCollections() {
+      return new HashSet<>( _delegate.values() );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> getCollection( final K key ) {
+      return _delegate.getCollection( key );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<V> obtainCollection( final K key ) {
+      return _delegate.obtainCollection( key );
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final K key, final V value ) {
+      return _delegate.containsValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeValue( final K key, final V value ) {
+      return _delegate.placeValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeMap( final Map<K, V> map ) {
+      return _delegate.placeMap( map );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void removeValue( final K key, final V value ) {
+      _delegate.removeValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public <C extends Collection<V>> int addAllValues( final K key, final C collection ) {
+      return _delegate.addAllValues( key, collection );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clearCollection( final K key ) {
+      _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 Set<K> keySet() {
+      return _delegate.keySet();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<Set<V>> values() {
+      return _delegate.values();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Set<Entry<K, Set<V>>> entrySet() {
+      return _delegate.entrySet();
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Map<K, Set<V>> toSimpleMap() {
+      return _delegate;
+   }
+
+}

Added: ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/ImmutableCollectionMap.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/ImmutableCollectionMap.java?rev=1719760&view=auto
==============================================================================
--- ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/ImmutableCollectionMap.java (added)
+++ ctakes/sandbox/dictionary-gui/src/main/java/org/apache/ctakes/dictionary/creator/util/collection/ImmutableCollectionMap.java Sun Dec 13 04:27:42 2015
@@ -0,0 +1,214 @@
+package org.apache.ctakes.dictionary.creator.util.collection;
+
+import java.util.*;
+
+/**
+ * Author: SPF
+ * Affiliation: CHIP-NLP
+ * Date: 9/5/2014
+ */
+final public class ImmutableCollectionMap<K, V, T extends Collection<V>> implements CollectionMap<K, V, T> {
+
+   private final CollectionMap<K, V, T> _protectedMap;
+
+   public ImmutableCollectionMap( final CollectionMap<K, V, T> collectionMap ) {
+      _protectedMap = collectionMap;
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Iterator<Entry<K, T>> iterator() {
+      return _protectedMap.iterator();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<T> getAllCollections() {
+      return Collections.unmodifiableCollection( _protectedMap.values() );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T getCollection( final K key ) {
+      // unfortunately, we cannot use an unmodifiable from Collections
+      return _protectedMap.getCollection( key );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T obtainCollection( final K key ) {
+      return getCollection( key );
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean containsValue( final K key, final V value ) {
+      return _protectedMap.containsValue( key, value );
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeValue( final K key, final V value ) {
+      throw new UnsupportedOperationException();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public boolean placeMap( final Map<K, V> map ) {
+      throw new UnsupportedOperationException();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void removeValue( final K key, final V value ) {
+      throw new UnsupportedOperationException();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public <C extends Collection<V>> int addAllValues( final K key, final C collection ) {
+      throw new UnsupportedOperationException();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public void clearCollection( final K key ) {
+      throw new UnsupportedOperationException();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   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();
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public T remove( final Object key ) {
+      throw new UnsupportedOperationException();
+   }
+
+
+   // Bulk Operations
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   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<Entry<K, T>> entrySet() {
+      return _protectedMap.entrySet();
+   }
+
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Map<K, T> toSimpleMap() {
+      return Collections.unmodifiableMap( _protectedMap );
+   }
+
+}



Mime
View raw message