Revision: 19749
          http://sourceforge.net/p/gate/code/19749
Author:   markagreenwood
Date:     2016-11-18 04:33:25 +0000 (Fri, 18 Nov 2016)
Log Message:
-----------
make sure we close streams even if we hit an exception, plus some other minor 
improvements

Modified Paths:
--------------
    
gate/branches/sawdust2/plugins/Tools/src/main/java/gate/creole/GazetteerListsCollector.java

Modified: 
gate/branches/sawdust2/plugins/Tools/src/main/java/gate/creole/GazetteerListsCollector.java
===================================================================
--- 
gate/branches/sawdust2/plugins/Tools/src/main/java/gate/creole/GazetteerListsCollector.java
 2016-11-18 04:23:17 UTC (rev 19748)
+++ 
gate/branches/sawdust2/plugins/Tools/src/main/java/gate/creole/GazetteerListsCollector.java
 2016-11-18 04:33:25 UTC (rev 19749)
@@ -183,9 +183,8 @@
       if(statsPerType.get(annotType).containsKey(text))
         statsPerType.get(annotType).put(
                 text,
-                new Integer(
-                        statsPerType.get(annotType).get(text).intValue() + 1));
-      else statsPerType.get(annotType).put(text, new Integer(1));
+                statsPerType.get(annotType).get(text).intValue() + 1);
+      else statsPerType.get(annotType).put(text, 1);
 
       // also collect stats for the individual tokens in the name to
       // identify the most
@@ -197,9 +196,9 @@
           if(statsPerType.get(annotType).containsKey(theString))
             statsPerType.get(annotType).put(
                     theString,
-                    new Integer(statsPerType.get(annotType).get(theString)
-                            .intValue() + 1));
-          else statsPerType.get(annotType).put(theString, new Integer(1));
+                    statsPerType.get(annotType).get(theString)
+                            .intValue() + 1);
+          else statsPerType.get(annotType).put(theString, 1);
         }
       }
 
@@ -229,22 +228,23 @@
   }
 
   protected void printStats() {
+    
     try {
       for(int i = 0; i < annotationTypes.size(); i++) {
         if(!statsPerType.containsKey(annotationTypes.get(i))) continue;
-        BufferedWriter writer =
+        try (BufferedWriter writer =
                 new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
-                        annotationTypes.get(i) + ".stats.lst"), "UTF-8"));
-        Map<String,Integer> stats = statsPerType.get(annotationTypes.get(i));
-        Iterator<String> stringsIter = stats.keySet().iterator();
-        while(stringsIter.hasNext()) {
-          String string = stringsIter.next();
-          writer.write(string);
-          writer.write("$");
-          writer.write(stats.get(string).toString());
-          writer.newLine();
+                        annotationTypes.get(i) + ".stats.lst"), "UTF-8"));){
+          Map<String,Integer> stats = statsPerType.get(annotationTypes.get(i));
+          
+          for(Map.Entry<String,Integer> entry : stats.entrySet()) {
+            String string = entry.getKey();
+            writer.write(string);
+            writer.write("$");
+            writer.write(entry.getValue().toString());
+            writer.newLine();
+          }
         }
-        writer.close();
       }
     } catch(IOException ioe) {
       throw new RuntimeException(ioe.getMessage());

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to