You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2017/06/28 10:02:10 UTC

[1/2] opennlp git commit: OPENNLP-1091: Fixing some issues found with FindBugs and IDE

Repository: opennlp
Updated Branches:
  refs/heads/master 08e163ca5 -> 3e66f1b6c


http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java
index 1143af1..b6d1698 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java
@@ -49,17 +49,18 @@ public class NameFinderEventStreamTest {
     NameSample nameSample = new NameSample(SENTENCE,
         new Span[]{new Span(0, 2, "person")}, false);
 
-    ObjectStream<Event> eventStream = new NameFinderEventStream(
-        ObjectStreamUtils.createObjectStream(nameSample));
+    try (ObjectStream<Event> eventStream = new NameFinderEventStream(
+        ObjectStreamUtils.createObjectStream(nameSample))) {
 
-    Assert.assertEquals("person-" + NameFinderME.START, eventStream.read().getOutcome());
-    Assert.assertEquals("person-" + NameFinderME.CONTINUE, eventStream.read().getOutcome());
+      Assert.assertEquals("person-" + NameFinderME.START, eventStream.read().getOutcome());
+      Assert.assertEquals("person-" + NameFinderME.CONTINUE, eventStream.read().getOutcome());
 
-    for (int i = 0; i < 10; i++) {
-      Assert.assertEquals(NameFinderME.OTHER, eventStream.read().getOutcome());
-    }
+      for (int i = 0; i < 10; i++) {
+        Assert.assertEquals(NameFinderME.OTHER, eventStream.read().getOutcome());
+      }
 
-    Assert.assertNull(eventStream.read());
+      Assert.assertNull(eventStream.read());
+    }
   }
 
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/parser/ChunkSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/parser/ChunkSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/parser/ChunkSampleStreamTest.java
index 65447b1..2523005 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/parser/ChunkSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/parser/ChunkSampleStreamTest.java
@@ -32,66 +32,67 @@ public class ChunkSampleStreamTest {
 
   @Test
   public void testConvertParseToPosSample() throws IOException {
-    ObjectStream<ChunkSample> chunkSampleStream = new ChunkSampleStream(new ParseSampleStream(
-        ObjectStreamUtils.createObjectStream(ParseTest.PARSE_STRING)));
+    try (ObjectStream<ChunkSample> chunkSampleStream = new ChunkSampleStream(new ParseSampleStream(
+        ObjectStreamUtils.createObjectStream(ParseTest.PARSE_STRING)))) {
 
-    ChunkSample sample = chunkSampleStream.read();
+      ChunkSample sample = chunkSampleStream.read();
 
-    assertEquals("She", sample.getSentence()[0]);
-    assertEquals("PRP", sample.getTags()[0]);
-    assertEquals("S-NP", sample.getPreds()[0]);
-    assertEquals("was", sample.getSentence()[1]);
-    assertEquals("VBD", sample.getTags()[1]);
-    assertEquals("O", sample.getPreds()[1]);
-    assertEquals("just", sample.getSentence()[2]);
-    assertEquals("RB", sample.getTags()[2]);
-    assertEquals("S-ADVP", sample.getPreds()[2]);
-    assertEquals("another", sample.getSentence()[3]);
-    assertEquals("DT", sample.getTags()[3]);
-    assertEquals("S-NP", sample.getPreds()[3]);
-    assertEquals("freighter", sample.getSentence()[4]);
-    assertEquals("NN", sample.getTags()[4]);
-    assertEquals("C-NP", sample.getPreds()[4]);
-    assertEquals("from", sample.getSentence()[5]);
-    assertEquals("IN", sample.getTags()[5]);
-    assertEquals("O", sample.getPreds()[5]);
-    assertEquals("the", sample.getSentence()[6]);
-    assertEquals("DT", sample.getTags()[6]);
-    assertEquals("S-NP", sample.getPreds()[6]);
-    assertEquals("States", sample.getSentence()[7]);
-    assertEquals("NNPS", sample.getTags()[7]);
-    assertEquals("C-NP", sample.getPreds()[7]);
-    assertEquals(",", sample.getSentence()[8]);
-    assertEquals(",", sample.getTags()[8]);
-    assertEquals("O", sample.getPreds()[8]);
-    assertEquals("and", sample.getSentence()[9]);
-    assertEquals("CC", sample.getTags()[9]);
-    assertEquals("O", sample.getPreds()[9]);
-    assertEquals("she", sample.getSentence()[10]);
-    assertEquals("PRP", sample.getTags()[10]);
-    assertEquals("S-NP", sample.getPreds()[10]);
-    assertEquals("seemed", sample.getSentence()[11]);
-    assertEquals("VBD", sample.getTags()[11]);
-    assertEquals("O", sample.getPreds()[11]);
-    assertEquals("as", sample.getSentence()[12]);
-    assertEquals("RB", sample.getTags()[12]);
-    assertEquals("S-ADJP", sample.getPreds()[12]);
-    assertEquals("commonplace", sample.getSentence()[13]);
-    assertEquals("JJ", sample.getTags()[13]);
-    assertEquals("C-ADJP", sample.getPreds()[13]);
-    assertEquals("as", sample.getSentence()[14]);
-    assertEquals("IN", sample.getTags()[14]);
-    assertEquals("O", sample.getPreds()[14]);
-    assertEquals("her", sample.getSentence()[15]);
-    assertEquals("PRP$", sample.getTags()[15]);
-    assertEquals("S-NP", sample.getPreds()[15]);
-    assertEquals("name", sample.getSentence()[16]);
-    assertEquals("NN", sample.getTags()[16]);
-    assertEquals("C-NP", sample.getPreds()[16]);
-    assertEquals(".", sample.getSentence()[17]);
-    assertEquals(".", sample.getTags()[17]);
-    assertEquals("O", sample.getPreds()[17]);
+      assertEquals("She", sample.getSentence()[0]);
+      assertEquals("PRP", sample.getTags()[0]);
+      assertEquals("S-NP", sample.getPreds()[0]);
+      assertEquals("was", sample.getSentence()[1]);
+      assertEquals("VBD", sample.getTags()[1]);
+      assertEquals("O", sample.getPreds()[1]);
+      assertEquals("just", sample.getSentence()[2]);
+      assertEquals("RB", sample.getTags()[2]);
+      assertEquals("S-ADVP", sample.getPreds()[2]);
+      assertEquals("another", sample.getSentence()[3]);
+      assertEquals("DT", sample.getTags()[3]);
+      assertEquals("S-NP", sample.getPreds()[3]);
+      assertEquals("freighter", sample.getSentence()[4]);
+      assertEquals("NN", sample.getTags()[4]);
+      assertEquals("C-NP", sample.getPreds()[4]);
+      assertEquals("from", sample.getSentence()[5]);
+      assertEquals("IN", sample.getTags()[5]);
+      assertEquals("O", sample.getPreds()[5]);
+      assertEquals("the", sample.getSentence()[6]);
+      assertEquals("DT", sample.getTags()[6]);
+      assertEquals("S-NP", sample.getPreds()[6]);
+      assertEquals("States", sample.getSentence()[7]);
+      assertEquals("NNPS", sample.getTags()[7]);
+      assertEquals("C-NP", sample.getPreds()[7]);
+      assertEquals(",", sample.getSentence()[8]);
+      assertEquals(",", sample.getTags()[8]);
+      assertEquals("O", sample.getPreds()[8]);
+      assertEquals("and", sample.getSentence()[9]);
+      assertEquals("CC", sample.getTags()[9]);
+      assertEquals("O", sample.getPreds()[9]);
+      assertEquals("she", sample.getSentence()[10]);
+      assertEquals("PRP", sample.getTags()[10]);
+      assertEquals("S-NP", sample.getPreds()[10]);
+      assertEquals("seemed", sample.getSentence()[11]);
+      assertEquals("VBD", sample.getTags()[11]);
+      assertEquals("O", sample.getPreds()[11]);
+      assertEquals("as", sample.getSentence()[12]);
+      assertEquals("RB", sample.getTags()[12]);
+      assertEquals("S-ADJP", sample.getPreds()[12]);
+      assertEquals("commonplace", sample.getSentence()[13]);
+      assertEquals("JJ", sample.getTags()[13]);
+      assertEquals("C-ADJP", sample.getPreds()[13]);
+      assertEquals("as", sample.getSentence()[14]);
+      assertEquals("IN", sample.getTags()[14]);
+      assertEquals("O", sample.getPreds()[14]);
+      assertEquals("her", sample.getSentence()[15]);
+      assertEquals("PRP$", sample.getTags()[15]);
+      assertEquals("S-NP", sample.getPreds()[15]);
+      assertEquals("name", sample.getSentence()[16]);
+      assertEquals("NN", sample.getTags()[16]);
+      assertEquals("C-NP", sample.getPreds()[16]);
+      assertEquals(".", sample.getSentence()[17]);
+      assertEquals(".", sample.getTags()[17]);
+      assertEquals("O", sample.getPreds()[17]);
 
-    assertNull(chunkSampleStream.read());
+      assertNull(chunkSampleStream.read());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/parser/PosSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/parser/PosSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/parser/PosSampleStreamTest.java
index bcbc975..49ba630 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/parser/PosSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/parser/PosSampleStreamTest.java
@@ -31,48 +31,49 @@ public class PosSampleStreamTest {
   @Test
   public void testConvertParseToPosSample() throws IOException {
 
-    ObjectStream<POSSample> posSampleStream = new PosSampleStream(new ParseSampleStream(
-        ObjectStreamUtils.createObjectStream(ParseTest.PARSE_STRING)));
+    try (ObjectStream<POSSample> posSampleStream = new PosSampleStream(new ParseSampleStream(
+        ObjectStreamUtils.createObjectStream(ParseTest.PARSE_STRING)))) {
 
-    POSSample sample = posSampleStream.read();
+      POSSample sample = posSampleStream.read();
 
-    Assert.assertEquals("PRP", sample.getTags()[0]);
-    Assert.assertEquals("She", sample.getSentence()[0]);
-    Assert.assertEquals("VBD", sample.getTags()[1]);
-    Assert.assertEquals("was", sample.getSentence()[1]);
-    Assert.assertEquals("RB", sample.getTags()[2]);
-    Assert.assertEquals("just", sample.getSentence()[2]);
-    Assert.assertEquals("DT", sample.getTags()[3]);
-    Assert.assertEquals("another", sample.getSentence()[3]);
-    Assert.assertEquals("NN", sample.getTags()[4]);
-    Assert.assertEquals("freighter", sample.getSentence()[4]);
-    Assert.assertEquals("IN", sample.getTags()[5]);
-    Assert.assertEquals("from", sample.getSentence()[5]);
-    Assert.assertEquals("DT", sample.getTags()[6]);
-    Assert.assertEquals("the", sample.getSentence()[6]);
-    Assert.assertEquals("NNPS", sample.getTags()[7]);
-    Assert.assertEquals("States", sample.getSentence()[7]);
-    Assert.assertEquals(",", sample.getTags()[8]);
-    Assert.assertEquals(",", sample.getSentence()[8]);
-    Assert.assertEquals("CC", sample.getTags()[9]);
-    Assert.assertEquals("and", sample.getSentence()[9]);
-    Assert.assertEquals("PRP", sample.getTags()[10]);
-    Assert.assertEquals("she", sample.getSentence()[10]);
-    Assert.assertEquals("VBD", sample.getTags()[11]);
-    Assert.assertEquals("seemed", sample.getSentence()[11]);
-    Assert.assertEquals("RB", sample.getTags()[12]);
-    Assert.assertEquals("as", sample.getSentence()[12]);
-    Assert.assertEquals("JJ", sample.getTags()[13]);
-    Assert.assertEquals("commonplace", sample.getSentence()[13]);
-    Assert.assertEquals("IN", sample.getTags()[14]);
-    Assert.assertEquals("as", sample.getSentence()[14]);
-    Assert.assertEquals("PRP$", sample.getTags()[15]);
-    Assert.assertEquals("her", sample.getSentence()[15]);
-    Assert.assertEquals("NN", sample.getTags()[16]);
-    Assert.assertEquals("name", sample.getSentence()[16]);
-    Assert.assertEquals(".", sample.getTags()[17]);
-    Assert.assertEquals(".", sample.getSentence()[17]);
+      Assert.assertEquals("PRP", sample.getTags()[0]);
+      Assert.assertEquals("She", sample.getSentence()[0]);
+      Assert.assertEquals("VBD", sample.getTags()[1]);
+      Assert.assertEquals("was", sample.getSentence()[1]);
+      Assert.assertEquals("RB", sample.getTags()[2]);
+      Assert.assertEquals("just", sample.getSentence()[2]);
+      Assert.assertEquals("DT", sample.getTags()[3]);
+      Assert.assertEquals("another", sample.getSentence()[3]);
+      Assert.assertEquals("NN", sample.getTags()[4]);
+      Assert.assertEquals("freighter", sample.getSentence()[4]);
+      Assert.assertEquals("IN", sample.getTags()[5]);
+      Assert.assertEquals("from", sample.getSentence()[5]);
+      Assert.assertEquals("DT", sample.getTags()[6]);
+      Assert.assertEquals("the", sample.getSentence()[6]);
+      Assert.assertEquals("NNPS", sample.getTags()[7]);
+      Assert.assertEquals("States", sample.getSentence()[7]);
+      Assert.assertEquals(",", sample.getTags()[8]);
+      Assert.assertEquals(",", sample.getSentence()[8]);
+      Assert.assertEquals("CC", sample.getTags()[9]);
+      Assert.assertEquals("and", sample.getSentence()[9]);
+      Assert.assertEquals("PRP", sample.getTags()[10]);
+      Assert.assertEquals("she", sample.getSentence()[10]);
+      Assert.assertEquals("VBD", sample.getTags()[11]);
+      Assert.assertEquals("seemed", sample.getSentence()[11]);
+      Assert.assertEquals("RB", sample.getTags()[12]);
+      Assert.assertEquals("as", sample.getSentence()[12]);
+      Assert.assertEquals("JJ", sample.getTags()[13]);
+      Assert.assertEquals("commonplace", sample.getSentence()[13]);
+      Assert.assertEquals("IN", sample.getTags()[14]);
+      Assert.assertEquals("as", sample.getSentence()[14]);
+      Assert.assertEquals("PRP$", sample.getTags()[15]);
+      Assert.assertEquals("her", sample.getSentence()[15]);
+      Assert.assertEquals("NN", sample.getTags()[16]);
+      Assert.assertEquals("name", sample.getSentence()[16]);
+      Assert.assertEquals(".", sample.getTags()[17]);
+      Assert.assertEquals(".", sample.getSentence()[17]);
 
-    Assert.assertNull(posSampleStream.read());
+      Assert.assertNull(posSampleStream.read());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/postag/POSSampleEventStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/postag/POSSampleEventStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/postag/POSSampleEventStreamTest.java
index fdc9d46..7ebc84b 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/postag/POSSampleEventStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/postag/POSSampleEventStreamTest.java
@@ -39,13 +39,13 @@ public class POSSampleEventStreamTest {
 
     POSSample sample = POSSample.parse(sentence);
 
-    ObjectStream<Event> eventStream = new POSSampleEventStream(
-        ObjectStreamUtils.createObjectStream(sample));
-
-    Assert.assertEquals("DT", eventStream.read().getOutcome());
-    Assert.assertEquals("VBZ", eventStream.read().getOutcome());
-    Assert.assertEquals("JJ", eventStream.read().getOutcome());
-    Assert.assertEquals(".", eventStream.read().getOutcome());
-    Assert.assertNull(eventStream.read());
+    try (ObjectStream<Event> eventStream = new POSSampleEventStream(
+        ObjectStreamUtils.createObjectStream(sample))) {
+      Assert.assertEquals("DT", eventStream.read().getOutcome());
+      Assert.assertEquals("VBZ", eventStream.read().getOutcome());
+      Assert.assertEquals("JJ", eventStream.read().getOutcome());
+      Assert.assertEquals(".", eventStream.read().getOutcome());
+      Assert.assertNull(eventStream.read());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/postag/WordTagSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/postag/WordTagSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/postag/WordTagSampleStreamTest.java
index 01b96fc..4c82e13 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/postag/WordTagSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/postag/WordTagSampleStreamTest.java
@@ -37,29 +37,29 @@ public class WordTagSampleStreamTest {
     Collection<String> sampleString = new ArrayList<>(1);
     sampleString.add("This_x1 is_x2 a_x3 test_x4 sentence_x5 ._x6");
 
-    WordTagSampleStream stream =
-        new WordTagSampleStream(new CollectionObjectStream<>(sampleString));
+    try (WordTagSampleStream stream =
+        new WordTagSampleStream(new CollectionObjectStream<>(sampleString))) {
+      POSSample sample = stream.read();
+      String[] words = sample.getSentence();
 
-    POSSample sample = stream.read();
-    String[] words = sample.getSentence();
+      Assert.assertEquals("This", words[0]);
+      Assert.assertEquals("is", words[1]);
+      Assert.assertEquals("a", words[2]);
+      Assert.assertEquals("test", words[3]);
+      Assert.assertEquals("sentence", words[4]);
+      Assert.assertEquals(".", words[5]);
 
-    Assert.assertEquals("This", words[0]);
-    Assert.assertEquals("is", words[1]);
-    Assert.assertEquals("a", words[2]);
-    Assert.assertEquals("test", words[3]);
-    Assert.assertEquals("sentence", words[4]);
-    Assert.assertEquals(".", words[5]);
+      String[] tags = sample.getTags();
+      Assert.assertEquals("x1", tags[0]);
+      Assert.assertEquals("x2", tags[1]);
+      Assert.assertEquals("x3", tags[2]);
+      Assert.assertEquals("x4", tags[3]);
+      Assert.assertEquals("x5", tags[4]);
+      Assert.assertEquals("x6", tags[5]);
 
-    String[] tags = sample.getTags();
-    Assert.assertEquals("x1", tags[0]);
-    Assert.assertEquals("x2", tags[1]);
-    Assert.assertEquals("x3", tags[2]);
-    Assert.assertEquals("x4", tags[3]);
-    Assert.assertEquals("x5", tags[4]);
-    Assert.assertEquals("x6", tags[5]);
-
-    Assert.assertNull(stream.read());
-    stream.reset();
-    Assert.assertNotNull(stream.read());
+      Assert.assertNull(stream.read());
+      stream.reset();
+      Assert.assertNotNull(stream.read());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokSpanEventStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokSpanEventStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokSpanEventStreamTest.java
index 172e7db..789a504 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokSpanEventStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokSpanEventStreamTest.java
@@ -42,15 +42,16 @@ public class TokSpanEventStreamTest {
 
     ObjectStream<TokenSample> tokenSampleStream = new TokenSampleStream(sentenceStream);
 
-    ObjectStream<Event> eventStream = new TokSpanEventStream(tokenSampleStream, false);
+    try (ObjectStream<Event> eventStream = new TokSpanEventStream(tokenSampleStream, false)) {
 
-    Assert.assertEquals(TokenizerME.SPLIT, eventStream.read().getOutcome());
-    Assert.assertEquals(TokenizerME.NO_SPLIT, eventStream.read().getOutcome());
-    Assert.assertEquals(TokenizerME.NO_SPLIT, eventStream.read().getOutcome());
-    Assert.assertEquals(TokenizerME.SPLIT, eventStream.read().getOutcome());
-    Assert.assertEquals(TokenizerME.SPLIT, eventStream.read().getOutcome());
+      Assert.assertEquals(TokenizerME.SPLIT, eventStream.read().getOutcome());
+      Assert.assertEquals(TokenizerME.NO_SPLIT, eventStream.read().getOutcome());
+      Assert.assertEquals(TokenizerME.NO_SPLIT, eventStream.read().getOutcome());
+      Assert.assertEquals(TokenizerME.SPLIT, eventStream.read().getOutcome());
+      Assert.assertEquals(TokenizerME.SPLIT, eventStream.read().getOutcome());
 
-    Assert.assertNull(eventStream.read());
-    Assert.assertNull(eventStream.read());
+      Assert.assertNull(eventStream.read());
+      Assert.assertNull(eventStream.read());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java
index 84f5f10..f811b0d 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java
@@ -96,19 +96,19 @@ public class TokenSampleStreamTest {
   public void testParsingWhitespaceAndSeparatedString() throws IOException {
     String sampleTokens = "a b<SPLIT>c d<SPLIT>e";
 
-    ObjectStream<TokenSample> sampleTokenStream = new TokenSampleStream(
-        ObjectStreamUtils.createObjectStream(sampleTokens));
+    try (ObjectStream<TokenSample> sampleTokenStream = new TokenSampleStream(
+        ObjectStreamUtils.createObjectStream(sampleTokens))) {
+      TokenSample tokenSample = sampleTokenStream.read();
 
-    TokenSample tokenSample = sampleTokenStream.read();
-
-    Span[] tokenSpans = tokenSample.getTokenSpans();
+      Span[] tokenSpans = tokenSample.getTokenSpans();
 
-    Assert.assertEquals(5, tokenSpans.length);
+      Assert.assertEquals(5, tokenSpans.length);
 
-    Assert.assertEquals("a", tokenSpans[0].getCoveredText(tokenSample.getText()));
-    Assert.assertEquals("b", tokenSpans[1].getCoveredText(tokenSample.getText()));
-    Assert.assertEquals("c", tokenSpans[2].getCoveredText(tokenSample.getText()));
-    Assert.assertEquals("d", tokenSpans[3].getCoveredText(tokenSample.getText()));
-    Assert.assertEquals("e", tokenSpans[4].getCoveredText(tokenSample.getText()));
+      Assert.assertEquals("a", tokenSpans[0].getCoveredText(tokenSample.getText()));
+      Assert.assertEquals("b", tokenSpans[1].getCoveredText(tokenSample.getText()));
+      Assert.assertEquals("c", tokenSpans[2].getCoveredText(tokenSample.getText()));
+      Assert.assertEquals("d", tokenSpans[3].getCoveredText(tokenSample.getText()));
+      Assert.assertEquals("e", tokenSpans[4].getCoveredText(tokenSample.getText()));
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/util/AbstractEventStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/util/AbstractEventStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/util/AbstractEventStreamTest.java
index 0470fc2..d4855b4 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/util/AbstractEventStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/util/AbstractEventStreamTest.java
@@ -46,15 +46,15 @@ public class AbstractEventStreamTest {
     samples.add(RESULT.EMPTY);
     samples.add(RESULT.EVENTS);
 
-    TestEventStream eventStream = new TestEventStream(new CollectionObjectStream<>(samples));
+    try (TestEventStream eventStream = new TestEventStream(new CollectionObjectStream<>(samples))) {
+      int eventCounter = 0;
 
-    int eventCounter = 0;
+      while (eventStream.read() != null) {
+        eventCounter++;
+      }
 
-    while (eventStream.read() != null) {
-      eventCounter++;
+      Assert.assertEquals(2, eventCounter);
     }
-
-    Assert.assertEquals(2, eventCounter);
   }
 
   /**
@@ -67,15 +67,16 @@ public class AbstractEventStreamTest {
     List<RESULT> samples = new ArrayList<>();
     samples.add(RESULT.EMPTY);
 
-    TestEventStream eventStream = new TestEventStream(new CollectionObjectStream<>(samples));
-    Assert.assertNull(eventStream.read());
+    try (TestEventStream eventStream = new TestEventStream(new CollectionObjectStream<>(samples))) {
+      Assert.assertNull(eventStream.read());
 
-    // now check if it can handle multiple empty event iterators
-    samples.add(RESULT.EMPTY);
-    samples.add(RESULT.EMPTY);
-
-    eventStream = new TestEventStream(new CollectionObjectStream<>(samples));
-    Assert.assertNull(eventStream.read());
+      // now check if it can handle multiple empty event iterators
+      samples.add(RESULT.EMPTY);
+      samples.add(RESULT.EMPTY);
+    }
+    try (TestEventStream eventStream = new TestEventStream(new CollectionObjectStream<>(samples))) {
+      Assert.assertNull(eventStream.read());
+    }
   }
 
   private enum RESULT {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/util/ParagraphStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/util/ParagraphStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/util/ParagraphStreamTest.java
index 3d0c117..26a333c 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/util/ParagraphStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/util/ParagraphStreamTest.java
@@ -26,31 +26,30 @@ public class ParagraphStreamTest {
 
   @Test
   public void testSimpleReading() throws IOException {
-    ParagraphStream paraStream = new ParagraphStream(
-            ObjectStreamUtils.createObjectStream("1", "2", "", "", "4", "5"));
-
-    Assert.assertEquals("1\n2\n", paraStream.read());
-    Assert.assertEquals("4\n5\n", paraStream.read());
-    Assert.assertNull(paraStream.read());
-
-    paraStream = new ParagraphStream(
-            ObjectStreamUtils.createObjectStream("1", "2", "", "", "4", "5", ""));
-
-    Assert.assertEquals("1\n2\n", paraStream.read());
-    Assert.assertEquals("4\n5\n", paraStream.read());
-    Assert.assertNull(paraStream.read());
+    try (ParagraphStream paraStream = new ParagraphStream(
+            ObjectStreamUtils.createObjectStream("1", "2", "", "", "4", "5"))) {
+      Assert.assertEquals("1\n2\n", paraStream.read());
+      Assert.assertEquals("4\n5\n", paraStream.read());
+      Assert.assertNull(paraStream.read());
+    }
+    try (ParagraphStream paraStream = new ParagraphStream(
+              ObjectStreamUtils.createObjectStream("1", "2", "", "", "4", "5", ""))) {
+      Assert.assertEquals("1\n2\n", paraStream.read());
+      Assert.assertEquals("4\n5\n", paraStream.read());
+      Assert.assertNull(paraStream.read());
+    }
   }
 
   @Test
   public void testReset() throws IOException {
-    ParagraphStream paraStream = new ParagraphStream(
-            ObjectStreamUtils.createObjectStream("1", "2", "", "", "4", "5", ""));
-
-    Assert.assertEquals("1\n2\n", paraStream.read());
-    paraStream.reset();
-
-    Assert.assertEquals("1\n2\n", paraStream.read());
-    Assert.assertEquals("4\n5\n", paraStream.read());
-    Assert.assertNull(paraStream.read());
+    try (ParagraphStream paraStream = new ParagraphStream(
+            ObjectStreamUtils.createObjectStream("1", "2", "", "", "4", "5", ""))) {
+      Assert.assertEquals("1\n2\n", paraStream.read());
+      paraStream.reset();
+
+      Assert.assertEquals("1\n2\n", paraStream.read());
+      Assert.assertEquals("4\n5\n", paraStream.read());
+      Assert.assertNull(paraStream.read());
+    }
   }
 }


[2/2] opennlp git commit: OPENNLP-1091: Fixing some issues found with FindBugs and IDE

Posted by jo...@apache.org.
OPENNLP-1091: Fixing some issues found with FindBugs and IDE

closes #229


Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/3e66f1b6
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/3e66f1b6
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/3e66f1b6

Branch: refs/heads/master
Commit: 3e66f1b6c4efc96421d43ff3dfa00686e72e6d8a
Parents: 08e163c
Author: Bruno P. Kinoshita <br...@yahoo.com.br>
Authored: Sat Jun 10 01:28:29 2017 +1200
Committer: Jörn Kottmann <jo...@apache.org>
Committed: Wed Jun 28 12:00:29 2017 +0200

----------------------------------------------------------------------
 .../tools/cmdline/AbstractTypedParamTool.java   |   1 -
 .../opennlp/tools/cmdline/ArgumentParser.java   |   4 +-
 .../main/java/opennlp/tools/cmdline/CLI.java    |   4 +-
 .../cmdline/FineGrainedReportListener.java      |  39 +++--
 .../tools/cmdline/GenerateManualTool.java       |  20 +--
 .../cmdline/entitylinker/EntityLinkerTool.java  |   6 +-
 .../sentdetect/SentenceDetectorTool.java        |   5 +-
 .../tokenizer/DictionaryDetokenizerTool.java    |  28 ++--
 .../tools/doccat/NGramFeatureGenerator.java     |   8 +-
 .../formats/brat/BratAnnotationStream.java      |   6 -
 .../tools/formats/conllu/ConlluStream.java      |  22 +--
 .../frenchtreebank/ConstitDocumentHandler.java  |   2 +-
 .../IrishSentenceBankDocument.java              |   6 +-
 .../tools/ml/maxent/io/GISModelWriter.java      |   2 +-
 .../tools/ml/maxent/quasinewton/QNTrainer.java  |   2 +-
 .../opennlp/tools/ml/model/ComparableEvent.java |  91 ++++++-----
 .../tools/ml/model/ComparablePredicate.java     |  39 ++++-
 .../tools/ml/naivebayes/LogProbabilities.java   |  25 +--
 .../ml/naivebayes/NaiveBayesModelWriter.java    |   1 +
 .../tools/ml/naivebayes/Probabilities.java      |  20 ++-
 .../ml/perceptron/PerceptronModelWriter.java    |   1 +
 .../opennlp/tools/namefind/RegexNameFinder.java |   4 +-
 .../namefind/TokenNameFinderCrossValidator.java |   6 +-
 .../opennlp/tools/ngram/NGramGenerator.java     |  12 +-
 .../tools/parser/AbstractContextGenerator.java  |   2 +-
 .../main/java/opennlp/tools/parser/Parse.java   |  11 +-
 .../opennlp/tools/parser/ParserEvaluator.java   |   3 +-
 .../opennlp/tools/parser/lang/en/HeadRules.java |   7 +-
 .../parser/lang/es/AncoraSpanishHeadRules.java  |   7 +-
 .../main/java/opennlp/tools/util/Sequence.java  |  30 +++-
 .../main/java/opennlp/tools/util/TokenTag.java  |   2 +-
 .../opennlp/tools/util/TrainingParameters.java  |   6 +-
 .../util/featuregen/CachedFeatureGenerator.java |   1 -
 .../POSTaggerNameFeatureGenerator.java          |   4 +-
 .../opennlp/tools/util/model/BaseModel.java     |  28 ++--
 .../formats/ConllXPOSSampleStreamTest.java      | 162 +++++++++----------
 .../formats/ad/ADChunkSampleStreamTest.java     |  13 +-
 .../formats/ad/ADNameSampleStreamTest.java      |  15 +-
 .../tools/formats/ad/ADPOSSampleStreamTest.java |  81 +++++-----
 .../formats/ad/ADSentenceSampleStreamTest.java  |  17 +-
 .../ConstitParseSampleStreamTest.java           |  30 ++--
 .../tools/ml/model/FileEventStreamTest.java     |  38 +++--
 .../ml/model/RealValueFileEventStreamTest.java  |  38 +++--
 .../namefind/NameFinderEventStreamTest.java     |  17 +-
 .../tools/parser/ChunkSampleStreamTest.java     | 117 +++++++-------
 .../tools/parser/PosSampleStreamTest.java       |  81 +++++-----
 .../tools/postag/POSSampleEventStreamTest.java  |  16 +-
 .../tools/postag/WordTagSampleStreamTest.java   |  42 ++---
 .../tools/tokenize/TokSpanEventStreamTest.java  |  17 +-
 .../tools/tokenize/TokenSampleStreamTest.java   |  22 +--
 .../tools/util/AbstractEventStreamTest.java     |  29 ++--
 .../opennlp/tools/util/ParagraphStreamTest.java |  43 +++--
 52 files changed, 637 insertions(+), 596 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java
index 86f0a10..2a84f89 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java
@@ -38,7 +38,6 @@ public abstract class AbstractTypedParamTool<T, P> extends TypedCmdLineTool<T> {
     this.paramsClass = paramsClass;
   }
 
-  @SuppressWarnings({"unchecked"})
   public String getHelp(String format) {
     if ("".equals(format) || StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) {
       return getBasicHelp(paramsClass,

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java
index e05a682..4d028cd 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java
@@ -136,7 +136,7 @@ public class ArgumentParser {
           throw new TerminateToolException(1,  String.format(INVALID_ARG, argName, argValue) +
               "Character should have size 1.");
         }
-        return new Character(chars[0]);
+        return Character.valueOf(chars[0]);
       }
       return null;
     }
@@ -236,7 +236,6 @@ public class ArgumentParser {
    * @param argProxyInterface interface with parameter descriptions
    * @return the help message usage string
    */
-  @SuppressWarnings({"unchecked"})
   public static <T> String createUsage(Class<T> argProxyInterface) {
     return createUsage(new Class[]{argProxyInterface});
   }
@@ -400,7 +399,6 @@ public class ArgumentParser {
    * @param argProxyInterface interface with parameters description
    * @return true, if arguments are valid
    */
-  @SuppressWarnings({"unchecked"})
   public static <T> boolean validateArguments(String[] args, Class<T> argProxyInterface) {
     return validateArguments(args, new Class[]{argProxyInterface});
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java
index c828e26..487bfcf 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java
@@ -244,7 +244,7 @@ public final class CLI {
       if ((0 == toolArguments.length && tool.hasParams()) ||
           0 < toolArguments.length && "help".equals(toolArguments[0])) {
         if (tool instanceof TypedCmdLineTool) {
-          System.out.println(((TypedCmdLineTool) tool).getHelp(formatName));
+          System.out.println(((TypedCmdLineTool<?>) tool).getHelp(formatName));
         } else if (tool instanceof BasicCmdLineTool) {
           System.out.println(tool.getHelp());
         }
@@ -253,7 +253,7 @@ public final class CLI {
       }
 
       if (tool instanceof TypedCmdLineTool) {
-        ((TypedCmdLineTool) tool).run(formatName, toolArguments);
+        ((TypedCmdLineTool<?>) tool).run(formatName, toolArguments);
       } else if (tool instanceof BasicCmdLineTool) {
         if (-1 == idx) {
           ((BasicCmdLineTool) tool).run(toolArguments);

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/cmdline/FineGrainedReportListener.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/FineGrainedReportListener.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/FineGrainedReportListener.java
index 75b84aa..c28c694 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/FineGrainedReportListener.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/FineGrainedReportListener.java
@@ -30,6 +30,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
@@ -497,19 +498,17 @@ public abstract class FineGrainedReportListener {
       this.categoryAccuracy = new HashMap<>();
 
       // compute grouped categories
-      for (String key :
-          confusionMatrix.keySet()) {
-        String category;
+      for (Entry<String, ConfusionMatrixLine> entry : confusionMatrix.entrySet()) {
+        final String key = entry.getKey();
+        final ConfusionMatrixLine confusionMatrixLine = entry.getValue();
+        final String category;
         if (key.contains("-")) {
           category = key.split("-")[0];
         } else {
           category = key;
         }
-        if (!categoryAccuracy.containsKey(category)) {
-          categoryAccuracy.put(category, 0.0);
-        }
-        categoryAccuracy.put(category,
-            categoryAccuracy.get(category) + confusionMatrix.get(key).getAccuracy());
+        double currentAccuracy = categoryAccuracy.getOrDefault(category, 0.0d);
+        categoryAccuracy.put(category, currentAccuracy + confusionMatrixLine.getAccuracy());
       }
     }
 
@@ -557,7 +556,7 @@ public abstract class FineGrainedReportListener {
             return -1;
           }
         }
-        if (t1 == t2) {
+        if (t1.equals(t2)) {
           return o1.compareTo(o2);
         }
         if (t2 > t1) {
@@ -572,7 +571,7 @@ public abstract class FineGrainedReportListener {
     return new MatrixLabelComparator(confusionMatrix);
   }
 
-  public class SimpleLabelComparator implements Comparator<String> {
+  public static class SimpleLabelComparator implements Comparator<String> {
 
     private Map<String, Counter> map;
 
@@ -611,19 +610,17 @@ public abstract class FineGrainedReportListener {
       this.categoryCounter = new HashMap<>();
 
       // compute grouped categories
-      for (String key :
-          labelCounter.keySet()) {
-        String category;
+      for (Entry<String, Counter> entry : labelCounter.entrySet()) {
+        final String key = entry.getKey();
+        final Counter value = entry.getValue();
+        final String category;
         if (key.contains("-")) {
           category = key.split("-")[0];
         } else {
           category = key;
         }
-        if (!categoryCounter.containsKey(category)) {
-          categoryCounter.put(category, 0);
-        }
-        categoryCounter.put(category,
-            categoryCounter.get(category) + labelCounter.get(key).value());
+        int currentCount = categoryCounter.getOrDefault(category, 0);
+        categoryCounter.put(category, currentCount + value.value());
       }
     }
 
@@ -671,7 +668,7 @@ public abstract class FineGrainedReportListener {
             return -1;
           }
         }
-        if (t1 == t2) {
+        if (t1.equals(t2)) {
           return o1.compareTo(o2);
         }
         if (t2 > t1) {
@@ -726,9 +723,9 @@ public abstract class FineGrainedReportListener {
      */
     public double getAccuracy() {
       // we save the accuracy because it is frequently used by the comparator
-      if (acc == -1) {
+      if (Math.abs(acc - 1.0d) < 0.0000000001) {
         if (total == 0)
-          acc = 0;
+          acc = 0.0d;
         acc = (double) correct / (double) total;
       }
       return acc;

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
index 36bb951..8fd5fd3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
@@ -24,6 +24,7 @@ import java.io.StringReader;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.StringTokenizer;
 
@@ -46,8 +47,9 @@ public class GenerateManualTool {
 
     // organize by package name
     LinkedHashMap<String, Map<String, CmdLineTool>> packageNameToolMap = new LinkedHashMap<>();
-    for (String toolName : CLI.getToolLookupMap().keySet()) {
-      CmdLineTool tool = CLI.getToolLookupMap().get(toolName);
+    for (Entry<String, CmdLineTool> entry : CLI.getToolLookupMap().entrySet()) {
+      final String toolName = entry.getKey();
+      final CmdLineTool tool = entry.getValue();
       String packageName = tool.getClass().getPackage().getName();
       packageName = packageName.substring(packageName.lastIndexOf(".") + 1);
 
@@ -59,8 +61,8 @@ public class GenerateManualTool {
     }
 
     // add tools grouped by package
-    for (String grouName : packageNameToolMap.keySet()) {
-      appendToolGroup(grouName, packageNameToolMap.get(grouName), sb);
+    for (Entry<String, Map<String, CmdLineTool>> entry : packageNameToolMap.entrySet()) {
+      appendToolGroup(entry.getKey(), entry.getValue(), sb);
     }
 
     // footer
@@ -92,8 +94,8 @@ public class GenerateManualTool {
     sb.append("<section id='tools.cli.").append(groupName).append("'>\n\n");
     sb.append("<title>").append(firstCaps(groupName)).append("</title>\n\n");
 
-    for (String toolName : toolsMap.keySet()) {
-      appendTool(groupName, toolName, toolsMap.get(toolName), sb);
+    for (Entry<String, CmdLineTool> entry : toolsMap.entrySet()) {
+      appendTool(groupName, entry.getKey(), entry.getValue(), sb);
     }
 
     sb.append("</section>\n\n");
@@ -124,7 +126,6 @@ public class GenerateManualTool {
     sb.append("</section>\n\n");
   }
 
-  @SuppressWarnings("unchecked")
   private static void appendHelpForTool(TypedCmdLineTool<?> tool,
       StringBuilder sb) {
     Class<?> type = tool.type;
@@ -153,8 +154,9 @@ public class GenerateManualTool {
             "<entry>Optional</entry><entry>Description</entry></row></thead>\n");
     sb.append("<tbody>\n");
 
-    for (String format : formatArguments.keySet()) {
-      List<Argument> arguments = formatArguments.get(format);
+    for (Entry<String, List<Argument>> entry : formatArguments.entrySet()) {
+      final String format = entry.getKey();
+      final List<Argument> arguments = entry.getValue();
       int i = 0;
       for (Argument argument : arguments) {
         sb.append("<row>\n");

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java
index 7f2d334..985e37e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java
@@ -79,10 +79,8 @@ public class EntityLinkerTool extends BasicCmdLineTool {
       PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
       perfMon.start();
 
-      try {
-
-        ObjectStream<String> untokenizedLineStream = new PlainTextByLineStream(
-            new SystemInputStreamFactory(), SystemInputStreamFactory.encoding());
+      try (ObjectStream<String> untokenizedLineStream = new PlainTextByLineStream(
+          new SystemInputStreamFactory(), SystemInputStreamFactory.encoding())) {
 
         List<NameSample> document = new ArrayList<>();
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTool.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTool.java
index 9b759b4..b4dd124 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTool.java
@@ -62,9 +62,8 @@ public final class SentenceDetectorTool extends BasicCmdLineTool {
       PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
       perfMon.start();
 
-      try {
-        ObjectStream<String> paraStream = new ParagraphStream(new PlainTextByLineStream(
-            new SystemInputStreamFactory(), SystemInputStreamFactory.encoding()));
+      try (ObjectStream<String> paraStream = new ParagraphStream(new PlainTextByLineStream(
+            new SystemInputStreamFactory(), SystemInputStreamFactory.encoding()))) {
 
         String para;
         while ((para = paraStream.read()) != null) {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/DictionaryDetokenizerTool.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/DictionaryDetokenizerTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/DictionaryDetokenizerTool.java
index 30f408b..f06c67a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/DictionaryDetokenizerTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/DictionaryDetokenizerTool.java
@@ -38,8 +38,6 @@ public final class DictionaryDetokenizerTool extends BasicCmdLineTool {
   }
 
   public void run(String[] args) {
-
-
     if (args.length != 1) {
       System.out.println(getHelp());
     } else {
@@ -47,30 +45,28 @@ public final class DictionaryDetokenizerTool extends BasicCmdLineTool {
         Detokenizer detokenizer = new DictionaryDetokenizer(
             new DetokenizationDictionaryLoader().load(new File(args[0])));
 
-        ObjectStream<String> tokenizedLineStream =
-            new PlainTextByLineStream(new SystemInputStreamFactory(), SystemInputStreamFactory.encoding());
-
-        PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
-        perfMon.start();
+        try (ObjectStream<String> tokenizedLineStream =
+            new PlainTextByLineStream(new SystemInputStreamFactory(), SystemInputStreamFactory.encoding())) {
 
+          PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
+          perfMon.start();
 
-        String tokenizedLine;
-        while ((tokenizedLine = tokenizedLineStream.read()) != null) {
+          String tokenizedLine;
+          while ((tokenizedLine = tokenizedLineStream.read()) != null) {
 
-          // white space tokenize line
-          String[] tokens = WhitespaceTokenizer.INSTANCE.tokenize(tokenizedLine);
+            // white space tokenize line
+            String[] tokens = WhitespaceTokenizer.INSTANCE.tokenize(tokenizedLine);
 
-          System.out.println(detokenizer.detokenize(tokens, null));
+            System.out.println(detokenizer.detokenize(tokens, null));
 
-          perfMon.incrementCounter();
+            perfMon.incrementCounter();
+          }
+          perfMon.stopAndPrintFinalResult();
         }
-        perfMon.stopAndPrintFinalResult();
       }
       catch (IOException e) {
         CmdLineUtil.handleStdinIoError(e);
       }
-
-
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java
index 6e1786f..15accdf 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java
@@ -75,12 +75,14 @@ public class NGramFeatureGenerator implements FeatureGenerator {
     List<String> features = new ArrayList<>();
 
     for (int i = 0; i <= text.length - minGram; i++) {
-      String feature = "ng=";
+      final StringBuilder sb = new StringBuilder();
+      sb.append("ng=");
       for (int y = 0; y < maxGram && i + y < text.length; y++) {
-        feature = feature + ":" + text[i + y];
+        sb.append(":");
+        sb.append(text[i + y]);
         int gramCount = y + 1;
         if (maxGram >= gramCount && gramCount >= minGram) {
-          features.add(feature);
+          features.add(sb.toString());
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java
index efeddba..d147179 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java
@@ -225,12 +225,6 @@ public class BratAnnotationStream implements ObjectStream<BratAnnotation> {
             return read();
         }
 
-        if (parser == null) {
-          throw new IOException("Failed to parse ann document with id " + id + ".ann and" +
-              " type class, no parser registered: " + tokens[BratAnnotationParser.TYPE_OFFSET]
-              .getCoveredText(line).toString());
-        }
-
         try {
           return parser.parse(tokens, line);
         }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluStream.java
index 4dd204f..9229881 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluStream.java
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.stream.Collectors;
 
 import opennlp.tools.util.InputStreamFactory;
@@ -96,15 +97,15 @@ public class ConlluStream implements ObjectStream<ConlluSentence> {
 
 
     // 1. Find contractions
-    Map<String, Integer> index = new HashMap();
-    Map<String, List<String>> contractions = new HashMap();
-    List<String> linesToDelete = new ArrayList();
+    Map<String, Integer> index = new HashMap<>();
+    Map<String, List<String>> contractions = new HashMap<>();
+    List<String> linesToDelete = new ArrayList<>();
 
     for (int i = 0; i < lines.size(); i++) {
       ConlluWordLine line = lines.get(i);
       index.put(line.getId(), i);
       if (line.getId().contains("-")) {
-        List<String> expandedContractions = new ArrayList();
+        List<String> expandedContractions = new ArrayList<>();
         String[] ids = line.getId().split("-");
         int start = Integer.parseInt(ids[0]);
         int end = Integer.parseInt(ids[1]);
@@ -118,14 +119,17 @@ public class ConlluStream implements ObjectStream<ConlluSentence> {
     }
 
     // 2. Merge annotation
-    for (String contractionId: contractions.keySet()) {
-      ConlluWordLine contraction = lines.get(index.get(contractionId));
-      List<ConlluWordLine> expandedParts = new ArrayList();
-      for (String id : contractions.get(contractionId)) {
+    for (Entry<String, List<String>> entry : contractions.entrySet()) {
+      final String contractionId = entry.getKey();
+      final List<String> expandedContractions = entry.getValue();
+      int contractionIndex = index.get(contractionId);
+      ConlluWordLine contraction = lines.get(contractionIndex);
+      List<ConlluWordLine> expandedParts = new ArrayList<>();
+      for (String id : expandedContractions) {
         expandedParts.add(lines.get(index.get(id)));
       }
       ConlluWordLine merged = mergeAnnotation(contraction, expandedParts);
-      lines.set(index.get(contractionId), merged);
+      lines.set(contractionIndex, merged);
     }
 
     // 3. Delete the expanded parts

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java b/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java
index f59ab51..3f544e9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitDocumentHandler.java
@@ -111,7 +111,7 @@ class ConstitDocumentHandler extends DefaultHandler {
       else {
         String catint = attributes.getValue("catint");
         if (catint != null) {
-          type = cat + (catint != null ? catint : "");
+          type = cat + catint;
         }
         else {
           type = cat + subcat;

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankDocument.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankDocument.java b/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankDocument.java
index 2fe9231..4343b7f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankDocument.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankDocument.java
@@ -27,6 +27,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -240,8 +241,9 @@ public class IrishSentenceBankDocument {
             }
           }
           IrishSentenceBankFlex[] flexa = new IrishSentenceBankFlex[flexes];
-          for (Integer flexidx : toks.keySet()) {
-            String left = toks.get(flexidx);
+          for (Entry<Integer, String> entry : toks.entrySet()) {
+            final Integer flexidx = entry.getKey();
+            final String left = entry.getValue();
             if (flx.get(flexidx) == null) {
               flexa = null;
               break;

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java
index 3fdeaf0..dd1213b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java
@@ -94,7 +94,7 @@ public abstract class GISModelWriter extends AbstractModelWriter {
     writeInt(compressed.size());
 
     for (List<ComparablePredicate> aCompressed : compressed) {
-      writeUTF(aCompressed.size() + ((List) aCompressed).get(0).toString());
+      writeUTF(aCompressed.size() + ((List<?>) aCompressed).get(0).toString());
     }
 
     // the mapping from predicate names to their integer indexes

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java
index daa90a4..c1174d1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java
@@ -217,7 +217,7 @@ public class QNTrainer extends AbstractEventTrainer {
   /**
    * For measuring model's training accuracy
    */
-  private class ModelEvaluator implements Evaluator {
+  private static class ModelEvaluator implements Evaluator {
 
     private DataIndexer indexer;
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparableEvent.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparableEvent.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparableEvent.java
index 0493253..5f426f4 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparableEvent.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparableEvent.java
@@ -17,6 +17,8 @@
 
 package opennlp.tools.ml.model;
 
+import java.util.Arrays;
+import java.util.Objects;
 
 /**
  * A maxent event representation which we can use to sort based on the
@@ -41,45 +43,66 @@ public class ComparableEvent implements Comparable<ComparableEvent> {
 
   public int compareTo(ComparableEvent ce) {
 
-    if (outcome < ce.outcome)
-      return -1;
-    else if (outcome > ce.outcome)
-      return 1;
+    int compareOutcome = Integer.compare(outcome, ce.outcome);
+    if (compareOutcome != 0) {
+      return compareOutcome;
+    }
 
-    int smallerLength = predIndexes.length > ce.predIndexes.length ? ce.predIndexes.length
-        : predIndexes.length;
+    int smallerLength = Math.min(predIndexes.length, ce.predIndexes.length);
 
     for (int i = 0; i < smallerLength; i++) {
-      if (predIndexes[i] < ce.predIndexes[i])
-        return -1;
-      else if (predIndexes[i] > ce.predIndexes[i])
-        return 1;
+      int comparePredIndexes = Integer.compare(predIndexes[i], ce.predIndexes[i]);
+      if (comparePredIndexes != 0) {
+        return comparePredIndexes;
+      }
       if (values != null && ce.values != null) {
-        if (values[i] < ce.values[i])
-          return -1;
-        else if (values[i] > ce.values[i])
-          return 1;
+        float compareValues = Float.compare(values[i], ce.values[i]);
+        if (!Float.valueOf(compareValues).equals(Float.valueOf(0.0f))) {
+          return (int) compareValues;
+        }
       } else if (values != null) {
-        if (values[i] < 1)
-          return -1;
-        else if (values[i] > 1)
-          return 1;
+        float compareValues = Float.compare(values[i], 1.0f);
+        if (!Float.valueOf(compareValues).equals(Float.valueOf(0.0f))) {
+          return (int) compareValues;
+        }
       } else if (ce.values != null) {
-        if (1 < ce.values[i])
-          return -1;
-        else if (1 > ce.values[i])
-          return 1;
+        float compareValues = Float.compare(1.0f, ce.values[i]);
+        if (!Float.valueOf(compareValues).equals(Float.valueOf(0.0f))) {
+          return (int) compareValues;
+        }
       }
     }
 
-    if (predIndexes.length < ce.predIndexes.length)
-      return -1;
-    else if (predIndexes.length > ce.predIndexes.length)
-      return 1;
+    int comparePredIndexesLength = Integer.compare(predIndexes.length, ce.predIndexes.length);
+    if (comparePredIndexesLength != 0) {
+      return comparePredIndexesLength;
+    }
 
     return 0;
   }
 
+  @Override
+  public boolean equals(Object obj) {
+
+    if (this == obj)
+      return true;
+
+    if (obj instanceof ComparableEvent) {
+      ComparableEvent other = (ComparableEvent) obj;
+      return outcome == other.outcome &&
+          Arrays.equals(predIndexes, other.predIndexes) &&
+          seen == other.seen &&
+          Arrays.equals(values, other.values);
+    }
+
+    return false;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(outcome, Arrays.hashCode(predIndexes), seen, Arrays.hashCode(values));
+  }
+
   public String toString() {
     StringBuilder s = new StringBuilder().append(outcome).append(":");
     for (int i = 0; i < predIndexes.length; i++) {
@@ -91,21 +114,5 @@ public class ComparableEvent implements Comparable<ComparableEvent> {
     return s.toString();
   }
 
-  private void sort(int[] pids, float[] values) {
-    for (int mi = 0; mi < pids.length; mi++) {
-      int min = mi;
-      for (int pi = mi + 1; pi < pids.length; pi++) {
-        if (pids[min] > pids[pi]) {
-          min = pi;
-        }
-      }
-      int pid = pids[mi];
-      pids[mi] = pids[min];
-      pids[min] = pid;
-      float val = values[mi];
-      values[mi] = values[min];
-      values[min] = val;
-    }
-  }
 }
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparablePredicate.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparablePredicate.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparablePredicate.java
index 898229a..5e21065 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparablePredicate.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/ComparablePredicate.java
@@ -17,6 +17,9 @@
 
 package opennlp.tools.ml.model;
 
+import java.util.Arrays;
+import java.util.Objects;
+
 /**
  * A maxent predicate representation which we can use to sort based on the
  * outcomes. This allows us to make the mapping of features to their parameters
@@ -34,20 +37,44 @@ public class ComparablePredicate implements Comparable<ComparablePredicate> {
   }
 
   public int compareTo(ComparablePredicate cp) {
-    int smallerLength = outcomes.length > cp.outcomes.length ?
-        cp.outcomes.length : outcomes.length;
+    int smallerLength = Math.min(outcomes.length, cp.outcomes.length);
 
     for (int i = 0; i < smallerLength; i++) {
-      if (outcomes[i] < cp.outcomes[i]) return -1;
-      else if (outcomes[i] > cp.outcomes[i]) return 1;
+      int compareOutcomes = Integer.compare(outcomes[i], cp.outcomes[i]);
+      if (compareOutcomes != 0) {
+        return compareOutcomes;
+      }
     }
 
-    if (outcomes.length < cp.outcomes.length) return -1;
-    else if (outcomes.length > cp.outcomes.length) return 1;
+    int compareOutcomesLength = Integer.compare(outcomes.length, cp.outcomes.length);
+    if (compareOutcomesLength != 0) {
+      return compareOutcomesLength;
+    }
 
     return 0;
   }
 
+  @Override
+  public int hashCode() {
+    return Objects.hash(name, Arrays.hashCode(outcomes), Arrays.hashCode(params));
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+
+    if (this == obj)
+      return true;
+
+    if (obj instanceof ComparablePredicate) {
+      ComparablePredicate other = (ComparablePredicate) obj;
+      return Objects.equals(name, other.name) &&
+          Arrays.equals(outcomes, other.outcomes) &&
+          Arrays.equals(params, other.params);
+    }
+
+    return false;
+  }
+
   public String toString() {
     StringBuilder s = new StringBuilder();
     for (int outcome : outcomes) {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java
index 0e4b0df..e1464f9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java
@@ -19,6 +19,7 @@ package opennlp.tools.ml.naivebayes;
 
 import java.util.ArrayList;
 import java.util.Map;
+import java.util.Map.Entry;
 
 /**
  * Class implementing the probability distribution over labels returned by
@@ -101,15 +102,16 @@ public class LogProbabilities<T> extends Probabilities<T> {
       return normalised;
     Map<T, Double> temp = createMapDataStructure();
     double highestLogProbability = Double.NEGATIVE_INFINITY;
-    for (T t : map.keySet()) {
-      Double p = map.get(t);
+    for (Entry<T, Double> entry : map.entrySet()) {
+      final Double p = entry.getValue();
       if (p != null && p > highestLogProbability) {
         highestLogProbability = p;
       }
     }
     double sum = 0;
-    for (T t : map.keySet()) {
-      Double p = map.get(t);
+    for (Entry<T, Double> entry : map.entrySet()) {
+      T t = entry.getKey();
+      Double p = entry.getValue();
       if (p != null) {
         double temp_p = Math.exp(p - highestLogProbability);
         if (!Double.isNaN(temp_p)) {
@@ -118,8 +120,9 @@ public class LogProbabilities<T> extends Probabilities<T> {
         }
       }
     }
-    for (T t : temp.keySet()) {
-      Double p = temp.get(t);
+    for (Entry<T, Double> entry : temp.entrySet()) {
+      final T t = entry.getKey();
+      final Double p = entry.getValue();
       if (p != null && sum > Double.MIN_VALUE) {
         temp.put(t, p / sum);
       }
@@ -162,8 +165,9 @@ public class LogProbabilities<T> extends Probabilities<T> {
   public void discardCountsBelow(double i) {
     i = Math.log(i);
     ArrayList<T> labelsToRemove = new ArrayList<>();
-    for (T label : map.keySet()) {
-      Double sum = map.get(label);
+    for (Entry<T, Double> entry : map.entrySet()) {
+      final T label = entry.getKey();
+      Double sum = entry.getValue();
       if (sum == null) sum = Double.NEGATIVE_INFINITY;
       if (sum < i)
         labelsToRemove.add(label);
@@ -190,8 +194,9 @@ public class LogProbabilities<T> extends Probabilities<T> {
   public T getMax() {
     double max = Double.NEGATIVE_INFINITY;
     T maxT = null;
-    for (T t : map.keySet()) {
-      Double temp = map.get(t);
+    for (Entry<T, Double> entry : map.entrySet()) {
+      final T t = entry.getKey();
+      final Double temp = entry.getValue();
       if (temp >= max) {
         max = temp;
         maxT = t;

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java
index 60efbaa..e5a632c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import opennlp.tools.ml.model.AbstractModel;
 import opennlp.tools.ml.model.AbstractModelWriter;

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java
index 50994b9..55357c5 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
 /**
@@ -146,14 +147,15 @@ public abstract class Probabilities<T> {
       return normalised;
     Map<T, Double> temp = createMapDataStructure();
     double sum = 0;
-    for (T t : map.keySet()) {
-      Double p = map.get(t);
+    for (Entry<T, Double> entry : map.entrySet()) {
+      Double p = entry.getValue();
       if (p != null) {
         sum += p;
       }
     }
-    for (T t : temp.keySet()) {
-      Double p = temp.get(t);
+    for (Entry<T, Double> entry : temp.entrySet()) {
+      T t = entry.getKey();
+      Double p = entry.getValue();
       if (p != null) {
         temp.put(t, p / sum);
       }
@@ -175,8 +177,9 @@ public abstract class Probabilities<T> {
   public T getMax() {
     double max = 0;
     T maxT = null;
-    for (T t : map.keySet()) {
-      Double temp = map.get(t);
+    for (Entry<T, Double> entry : map.entrySet()) {
+      final T t = entry.getKey();
+      final Double temp = entry.getValue();
       if (temp >= max) {
         max = temp;
         maxT = t;
@@ -196,8 +199,9 @@ public abstract class Probabilities<T> {
 
   public void discardCountsBelow(double i) {
     List<T> labelsToRemove = new ArrayList<>();
-    for (T label : map.keySet()) {
-      Double sum = map.get(label);
+    for (Entry<T, Double> entry : map.entrySet()) {
+      T label = entry.getKey();
+      Double sum = entry.getValue();
       if (sum == null) sum = 0.0;
       if (sum < i)
         labelsToRemove.add(label);

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronModelWriter.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronModelWriter.java
index 93f4fcf..2d3bb63 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronModelWriter.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronModelWriter.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import opennlp.tools.ml.model.AbstractModel;
 import opennlp.tools.ml.model.AbstractModelWriter;

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java
index 7d7c6bd..aff3392 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java
@@ -87,7 +87,7 @@ public final class RegexNameFinder implements TokenNameFinder {
 
     Collection<Span> annotations = new LinkedList<>();
 
-    if (mPatterns == null && regexMap != null) {
+    if (regexMap != null) {
       for (Map.Entry<String, Pattern[]> entry : regexMap.entrySet()) {
         for (Pattern mPattern : entry.getValue()) {
           Matcher matcher = mPattern.matcher(sentenceString);
@@ -141,7 +141,7 @@ public final class RegexNameFinder implements TokenNameFinder {
 
   private Span[] getAnnotations(String text) {
     Collection<Span> annotations = new LinkedList<>();
-    if (mPatterns == null && regexMap != null) {
+    if (regexMap != null) {
       for (Map.Entry<String, Pattern[]> entry : regexMap.entrySet()) {
         for (Pattern mPattern : entry.getValue()) {
           Matcher matcher = mPattern.matcher(text);

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java
index df8866f..5e9e662 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java
@@ -34,7 +34,7 @@ import opennlp.tools.util.eval.FMeasure;
 
 public class TokenNameFinderCrossValidator {
 
-  private class DocumentSample {
+  private static class DocumentSample {
 
     private NameSample[] samples;
 
@@ -50,7 +50,7 @@ public class TokenNameFinderCrossValidator {
   /**
    * Reads Name Samples to group them as a document based on the clear adaptive data flag.
    */
-  private class NameToDocumentSampleStream extends FilterObjectStream<NameSample, DocumentSample> {
+  private static class NameToDocumentSampleStream extends FilterObjectStream<NameSample, DocumentSample> {
 
     private NameSample beginSample;
 
@@ -105,7 +105,7 @@ public class TokenNameFinderCrossValidator {
   /**
    * Splits DocumentSample into NameSamples.
    */
-  private class DocumentToNameSampleStream extends FilterObjectStream<DocumentSample, NameSample> {
+  private static class DocumentToNameSampleStream extends FilterObjectStream<DocumentSample, NameSample> {
 
     protected DocumentToNameSampleStream(ObjectStream<DocumentSample> samples) {
       super(samples);

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramGenerator.java
index 19739a6..6c470bc 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramGenerator.java
@@ -42,11 +42,13 @@ public class NGramGenerator {
 
     List<String> outGrams = new ArrayList<>();
     for (int i = 0; i < input.size() - (n - 2); i++) {
-      String gram = "";
+      final StringBuilder sb = new StringBuilder();
       if ((i + n) <= input.size()) {
         for (int x = i; x < (n + i); x++) {
-          gram += input.get(x) + separator;
+          sb.append(input.get(x));
+          sb.append(separator);
         }
+        String gram = sb.toString();
         gram = gram.substring(0, gram.lastIndexOf(separator));
         outGrams.add(gram);
       }
@@ -66,11 +68,13 @@ public class NGramGenerator {
 
     List<String> outGrams = new ArrayList<>();
     for (int i = 0; i < input.length - (n - 2); i++) {
-      String gram = "";
+      final StringBuilder sb = new StringBuilder();
       if ((i + n) <= input.length) {
         for (int x = i; x < (n + i); x++) {
-          gram += input[x] + separator;
+          sb.append(input[x]);
+          sb.append(separator);
         }
+        String gram = sb.toString();
         gram = gram.substring(0, gram.lastIndexOf(separator));
         outGrams.add(gram);
       }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java
index b4b32e3..a1fa576 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractContextGenerator.java
@@ -188,7 +188,7 @@ public abstract class AbstractContextGenerator {
         for (Iterator<Parse> pi = punct2s.iterator(); pi.hasNext();) {
           Parse p = pi.next();
           // String punct = punct(p,c2.index);
-          String punctbo = punctbo(p,c2.index <= 0 ? c2.index - 1 : c2.index);
+          String punctbo = punctbo(p, c2.index);
           //punct(2)
           //TODO consider changing
           //features.add(punct);

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java b/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
index d4265cf..e2b4fba 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
@@ -516,9 +516,6 @@ public class Parse implements Cloneable, Comparable<Parse> {
     parts.add(daughter);
     this.span = new Span(span.getStart(),daughter.getSpan().getEnd());
     this.head = rules.getHead(getChildren(),type);
-    if (head == null) {
-      System.err.println(parts);
-    }
     this.headIndex = head.headIndex;
   }
 
@@ -1039,13 +1036,7 @@ public class Parse implements Cloneable, Comparable<Parse> {
   }
 
   public int compareTo(Parse p) {
-    if (this.getProb() > p.getProb()) {
-      return -1;
-    }
-    else if (this.getProb() < p.getProb()) {
-      return 1;
-    }
-    return 0;
+    return Double.compare(p.getProb(), this.getProb());
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java
index 013a6c1..fddcde7 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java
@@ -101,10 +101,9 @@ public class ParserEvaluator extends Evaluator<Parse> {
     Parse prediction = null;
     if (predictions.length > 0) {
       prediction = predictions[0];
+      fmeasure.updateScores(getConstituencySpans(reference), getConstituencySpans(prediction));
     }
 
-    fmeasure.updateScores(getConstituencySpans(reference), getConstituencySpans(prediction));
-
     return prediction;
   }
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java
index bae7846..5e1ff4b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java
@@ -31,6 +31,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Set;
 import java.util.Stack;
@@ -256,9 +257,9 @@ public class HeadRules implements opennlp.tools.parser.HeadRules, GapLabeler, Se
    */
   public void serialize(Writer writer) throws IOException {
 
-    for (String type : headRules.keySet()) {
-
-      HeadRule headRule = headRules.get(type);
+    for (Entry<String, HeadRule> entry : headRules.entrySet()) {
+      String type = entry.getKey();
+      HeadRule headRule = entry.getValue();
 
       // write num of tags
       writer.write(Integer.toString(headRule.tags.length + 2));

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java
index fad968e..6dc15d1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java
@@ -30,6 +30,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Set;
 import java.util.Stack;
@@ -261,9 +262,9 @@ public class AncoraSpanishHeadRules implements HeadRules, GapLabeler, Serializab
    */
   public void serialize(Writer writer) throws IOException {
 
-    for (String type : headRules.keySet()) {
-
-      HeadRule headRule = headRules.get(type);
+    for (Entry<String, HeadRule> entry : headRules.entrySet()) {
+      String type = entry.getKey();
+      HeadRule headRule = entry.getValue();
 
       // write num of tags
       writer.write(Integer.toString(headRule.tags.length + 2));

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java b/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
index 2cb86c0..5232370 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
@@ -20,6 +20,7 @@ package opennlp.tools.util;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 
 /** Represents a weighted sequence of outcomes. */
 public class Sequence implements Comparable<Sequence> {
@@ -59,14 +60,31 @@ public class Sequence implements Comparable<Sequence> {
   }
 
   public int compareTo(Sequence s) {
-    if (score < s.score)
-      return 1;
-    if (score > s.score)
-      return -1;
-    return 0;
+    return Double.compare(s.score, score);
   }
 
-  /** Adds an outcome and probability to this sequence.
+  @Override
+  public int hashCode() {
+    return Objects.hash(outcomes, probs, score);
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+
+    if (obj instanceof Sequence) {
+      Sequence other = (Sequence) obj;
+      double epsilon = 0.0000001;
+      return Objects.equals(outcomes, other.outcomes) &&
+          Objects.equals(probs, other.probs) &&
+          Math.abs(score - other.score) < epsilon;
+    }
+
+    return false;
+  }
+
+/** Adds an outcome and probability to this sequence.
    * @param outcome the outcome to be added.
    * @param p the probability associated with this outcome.
    */

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/util/TokenTag.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/TokenTag.java b/opennlp-tools/src/main/java/opennlp/tools/util/TokenTag.java
index 2a4377b..a4e7b94 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/TokenTag.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/TokenTag.java
@@ -82,7 +82,7 @@ public class TokenTag {
     } else if (o instanceof TokenTag) {
       return Objects.equals(this.token, ((TokenTag) o).token)
           && Objects.equals(this.tag, ((TokenTag) o).tag)
-          && Objects.equals(this.addtionalData, ((TokenTag) o).addtionalData);
+          && Arrays.equals(this.addtionalData, ((TokenTag) o).addtionalData);
     }
     return false;
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
index 08a1373..6fc351c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
@@ -23,6 +23,7 @@ import java.io.OutputStream;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 
 import opennlp.tools.ml.EventTrainer;
@@ -215,8 +216,9 @@ public class TrainingParameters {
     TrainingParameters params = new TrainingParameters();
     Map<String, Object> settings = getObjectSettings(namespace);
 
-    for (String key: settings.keySet()) {
-      Object value = settings.get(key);
+    for (Entry<String, Object> entry: settings.entrySet()) {
+      String key = entry.getKey();
+      Object value = entry.getValue();;
       if (value instanceof Integer) {
         params.put(key, (Integer)value);
       }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java
index baedfc9..d3f0705 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java
@@ -42,7 +42,6 @@ public class CachedFeatureGenerator implements AdaptiveFeatureGenerator {
     contextsCache = new Cache<>(100);
   }
 
-  @SuppressWarnings("unchecked")
   public void createFeatures(List<String> features, String[] tokens, int index,
       String[] previousOutcomes) {
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/POSTaggerNameFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/POSTaggerNameFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/POSTaggerNameFeatureGenerator.java
index 39c6335..a9a37b5 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/POSTaggerNameFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/POSTaggerNameFeatureGenerator.java
@@ -18,8 +18,8 @@
 
 package opennlp.tools.util.featuregen;
 
+import java.util.Arrays;
 import java.util.List;
-import java.util.Objects;
 
 import opennlp.tools.postag.POSModel;
 import opennlp.tools.postag.POSTagger;
@@ -56,7 +56,7 @@ public class POSTaggerNameFeatureGenerator implements AdaptiveFeatureGenerator {
 
 
   public void createFeatures(List<String> feats, String[] toks, int index, String[] preds) {
-    if (!Objects.equals(this.cachedTokens, toks)) {
+    if (!Arrays.equals(this.cachedTokens, toks)) {
       this.cachedTokens = toks;
       this.cachedTags = this.posTagger.tag(toks);
     }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java b/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
index 31f5079..2cb417f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
@@ -19,7 +19,6 @@ package opennlp.tools.util.model;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -33,6 +32,7 @@ import java.net.URL;
 import java.nio.file.Path;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Properties;
 import java.util.zip.ZipEntry;
@@ -134,8 +134,8 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
 
       // new manifest entries
       Map<String, String> entries = factory.createManifestEntries();
-      for (String key : entries.keySet()) {
-        setManifestProperty(key, entries.get(key));
+      for (Entry<String, String> entry : entries.entrySet()) {
+        setManifestProperty(entry.getKey(), entry.getValue());
       }
     }
 
@@ -554,8 +554,9 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
           "The method BaseModel.loadArtifactSerializers() was not called by BaseModel subclass constructor.");
     }
 
-    for (String name : artifactMap.keySet()) {
-      Object artifact = artifactMap.get(name);
+    for (Entry<String, Object> entry : artifactMap.entrySet()) {
+      final String name = entry.getKey();
+      final Object artifact = entry.getValue();
       if (artifact instanceof SerializableArtifact) {
 
         SerializableArtifact serializableArtifact = (SerializableArtifact) artifact;
@@ -570,10 +571,11 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
 
     ZipOutputStream zip = new ZipOutputStream(out);
 
-    for (String name : artifactMap.keySet()) {
+    for (Entry<String, Object> entry : artifactMap.entrySet()) {
+      String name = entry.getKey();
       zip.putNextEntry(new ZipEntry(name));
 
-      Object artifact = artifactMap.get(name);
+      Object artifact = entry.getValue();
 
       ArtifactSerializer serializer = getArtifactSerializer(name);
 
@@ -619,18 +621,6 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
     return (T) artifact;
   }
 
-  private static byte[] toByteArray(InputStream input) throws IOException {
-    ByteArrayOutputStream output = new ByteArrayOutputStream();
-    byte[] buffer = new byte[1024 * 4];
-    int count = 0;
-    int n;
-    while (-1 != (n = input.read(buffer))) {
-      output.write(buffer, 0, n);
-      count += n;
-    }
-    return output.toByteArray();
-  }
-
   public boolean isLoadedFromSerialized() {
     return isLoadedFromSerialized;
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/formats/ConllXPOSSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/formats/ConllXPOSSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/formats/ConllXPOSSampleStreamTest.java
index 809d785..a386873 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/formats/ConllXPOSSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/formats/ConllXPOSSampleStreamTest.java
@@ -37,126 +37,126 @@ public class ConllXPOSSampleStreamTest {
     InputStreamFactory in = new ResourceAsStreamFactory(ConllXPOSSampleStreamTest.class,
         "/opennlp/tools/formats/conllx.sample");
 
-    ObjectStream<POSSample> sampleStream = new ConllXPOSSampleStream(in,Charset.forName("UTF-8"));
+    try (ObjectStream<POSSample> sampleStream = new ConllXPOSSampleStream(in,Charset.forName("UTF-8"))) {
+      POSSample a = sampleStream.read();
 
-    POSSample a = sampleStream.read();
+      String[] aSentence = a.getSentence();
+      String[] aTags = a.getTags();
 
-    String[] aSentence = a.getSentence();
-    String[] aTags = a.getTags();
+      assertEquals(22, aSentence.length);
+      assertEquals(22, aTags.length);
 
-    assertEquals(22, aSentence.length);
-    assertEquals(22, aTags.length);
+      assertEquals("To", aSentence[0]);
+      assertEquals("AC", aTags[0]);
 
-    assertEquals("To", aSentence[0]);
-    assertEquals("AC", aTags[0]);
+      assertEquals("kendte", aSentence[1]);
+      assertEquals("AN", aTags[1]);
 
-    assertEquals("kendte", aSentence[1]);
-    assertEquals("AN", aTags[1]);
+      assertEquals("russiske", aSentence[2]);
+      assertEquals("AN", aTags[2]);
 
-    assertEquals("russiske", aSentence[2]);
-    assertEquals("AN", aTags[2]);
+      assertEquals("historikere", aSentence[3]);
+      assertEquals("NC", aTags[3]);
 
-    assertEquals("historikere", aSentence[3]);
-    assertEquals("NC", aTags[3]);
+      assertEquals("Andronik", aSentence[4]);
+      assertEquals("NP", aTags[4]);
 
-    assertEquals("Andronik", aSentence[4]);
-    assertEquals("NP", aTags[4]);
+      assertEquals("Andronik", aSentence[5]);
+      assertEquals("NP", aTags[5]);
 
-    assertEquals("Andronik", aSentence[5]);
-    assertEquals("NP", aTags[5]);
+      assertEquals("og", aSentence[6]);
+      assertEquals("CC", aTags[6]);
 
-    assertEquals("og", aSentence[6]);
-    assertEquals("CC", aTags[6]);
+      assertEquals("Igor", aSentence[7]);
+      assertEquals("NP", aTags[7]);
 
-    assertEquals("Igor", aSentence[7]);
-    assertEquals("NP", aTags[7]);
+      assertEquals("Klamkin", aSentence[8]);
+      assertEquals("NP", aTags[8]);
 
-    assertEquals("Klamkin", aSentence[8]);
-    assertEquals("NP", aTags[8]);
+      assertEquals("tror", aSentence[9]);
+      assertEquals("VA", aTags[9]);
 
-    assertEquals("tror", aSentence[9]);
-    assertEquals("VA", aTags[9]);
+      assertEquals("ikke", aSentence[10]);
+      assertEquals("RG", aTags[10]);
 
-    assertEquals("ikke", aSentence[10]);
-    assertEquals("RG", aTags[10]);
+      assertEquals(",", aSentence[11]);
+      assertEquals("XP", aTags[11]);
 
-    assertEquals(",", aSentence[11]);
-    assertEquals("XP", aTags[11]);
+      assertEquals("at", aSentence[12]);
+      assertEquals("CS", aTags[12]);
 
-    assertEquals("at", aSentence[12]);
-    assertEquals("CS", aTags[12]);
+      assertEquals("Rusland", aSentence[13]);
+      assertEquals("NP", aTags[13]);
 
-    assertEquals("Rusland", aSentence[13]);
-    assertEquals("NP", aTags[13]);
+      assertEquals("kan", aSentence[14]);
+      assertEquals("VA", aTags[14]);
 
-    assertEquals("kan", aSentence[14]);
-    assertEquals("VA", aTags[14]);
+      assertEquals("udvikles", aSentence[15]);
+      assertEquals("VA", aTags[15]);
 
-    assertEquals("udvikles", aSentence[15]);
-    assertEquals("VA", aTags[15]);
+      assertEquals("uden", aSentence[16]);
+      assertEquals("SP", aTags[16]);
 
-    assertEquals("uden", aSentence[16]);
-    assertEquals("SP", aTags[16]);
+      assertEquals("en", aSentence[17]);
+      assertEquals("PI", aTags[17]);
 
-    assertEquals("en", aSentence[17]);
-    assertEquals("PI", aTags[17]);
+      assertEquals("\"", aSentence[18]);
+      assertEquals("XP", aTags[18]);
 
-    assertEquals("\"", aSentence[18]);
-    assertEquals("XP", aTags[18]);
+      assertEquals("jernnæve", aSentence[19]);
+      assertEquals("NC", aTags[19]);
 
-    assertEquals("jernnæve", aSentence[19]);
-    assertEquals("NC", aTags[19]);
+      assertEquals("\"", aSentence[20]);
+      assertEquals("XP", aTags[20]);
 
-    assertEquals("\"", aSentence[20]);
-    assertEquals("XP", aTags[20]);
+      assertEquals(".", aSentence[21]);
+      assertEquals("XP", aTags[21]);
 
-    assertEquals(".", aSentence[21]);
-    assertEquals("XP", aTags[21]);
+      POSSample b = sampleStream.read();
 
-    POSSample b = sampleStream.read();
+      String[] bSentence = b.getSentence();
+      String[] bTags = b.getTags();
 
-    String[] bSentence = b.getSentence();
-    String[] bTags = b.getTags();
+      assertEquals(12, bSentence.length);
+      assertEquals(12, bTags.length);
 
-    assertEquals(12, bSentence.length);
-    assertEquals(12, bTags.length);
+      assertEquals("De", bSentence[0]);
+      assertEquals("PP", bTags[0]);
 
-    assertEquals("De", bSentence[0]);
-    assertEquals("PP", bTags[0]);
+      assertEquals("hævder", bSentence[1]);
+      assertEquals("VA", bTags[1]);
 
-    assertEquals("hævder", bSentence[1]);
-    assertEquals("VA", bTags[1]);
+      assertEquals(",", bSentence[2]);
+      assertEquals("XP", bTags[2]);
 
-    assertEquals(",", bSentence[2]);
-    assertEquals("XP", bTags[2]);
+      assertEquals("at", bSentence[3]);
+      assertEquals("CS", bTags[3]);
 
-    assertEquals("at", bSentence[3]);
-    assertEquals("CS", bTags[3]);
+      assertEquals("Ruslands", bSentence[4]);
+      assertEquals("NP", bTags[4]);
 
-    assertEquals("Ruslands", bSentence[4]);
-    assertEquals("NP", bTags[4]);
+      assertEquals("vej", bSentence[5]);
+      assertEquals("NC", bTags[5]);
 
-    assertEquals("vej", bSentence[5]);
-    assertEquals("NC", bTags[5]);
+      assertEquals("til", bSentence[6]);
+      assertEquals("SP", bTags[6]);
 
-    assertEquals("til", bSentence[6]);
-    assertEquals("SP", bTags[6]);
+      assertEquals("demokrati", bSentence[7]);
+      assertEquals("NC", bTags[7]);
 
-    assertEquals("demokrati", bSentence[7]);
-    assertEquals("NC", bTags[7]);
+      assertEquals("går", bSentence[8]);
+      assertEquals("VA", bTags[8]);
 
-    assertEquals("går", bSentence[8]);
-    assertEquals("VA", bTags[8]);
+      assertEquals("gennem", bSentence[9]);
+      assertEquals("SP", bTags[9]);
 
-    assertEquals("gennem", bSentence[9]);
-    assertEquals("SP", bTags[9]);
+      assertEquals("diktatur", bSentence[10]);
+      assertEquals("NC", bTags[10]);
 
-    assertEquals("diktatur", bSentence[10]);
-    assertEquals("NC", bTags[10]);
+      assertEquals(".", bSentence[11]);
+      assertEquals("XP", bTags[11]);
 
-    assertEquals(".", bSentence[11]);
-    assertEquals("XP", bTags[11]);
-
-    assertNull(sampleStream.read());
+      assertNull(sampleStream.read());
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADChunkSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADChunkSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADChunkSampleStreamTest.java
index 580fc05..e45c240 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADChunkSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADChunkSampleStreamTest.java
@@ -68,14 +68,11 @@ public class ADChunkSampleStreamTest {
     InputStreamFactory in = new ResourceAsStreamFactory(
         ADParagraphStreamTest.class, "/opennlp/tools/formats/ad.sample");
 
-    ADChunkSampleStream stream = new ADChunkSampleStream(
-        new PlainTextByLineStream(in, "UTF-8"));
-
-    ChunkSample sample = stream.read();
-
-    while (sample != null) {
-      samples.add(sample);
-      sample = stream.read();
+    try (ADChunkSampleStream stream = new ADChunkSampleStream(new PlainTextByLineStream(in, "UTF-8"))) {
+      ChunkSample sample;
+      while ((sample = stream.read()) != null) {
+        samples.add(sample);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADNameSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADNameSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADNameSampleStreamTest.java
index 2edb0d2..7c2fa04 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADNameSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADNameSampleStreamTest.java
@@ -18,6 +18,7 @@
 package opennlp.tools.formats.ad;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -114,14 +115,12 @@ public class ADNameSampleStreamTest {
     InputStreamFactory in = new ResourceAsStreamFactory(ADParagraphStreamTest.class,
         "/opennlp/tools/formats/ad.sample");
 
-    ADNameSampleStream stream = new ADNameSampleStream(
-        new PlainTextByLineStream(in, "UTF-8"), true);
-
-    NameSample sample = stream.read();
-
-    while (sample != null) {
-      samples.add(sample);
-      sample = stream.read();
+    try (ADNameSampleStream stream =
+            new ADNameSampleStream(new PlainTextByLineStream(in, StandardCharsets.UTF_8), true)) {
+      NameSample sample;
+      while ((sample = stream.read()) != null) {
+        samples.add(sample);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADPOSSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADPOSSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADPOSSampleStreamTest.java
index 51dc0c1..275c774 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADPOSSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADPOSSampleStreamTest.java
@@ -18,6 +18,7 @@
 package opennlp.tools.formats.ad;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -31,79 +32,81 @@ public class ADPOSSampleStreamTest {
   @Test
   public void testSimple() throws IOException {
     // add one sentence with expandME = includeFeats = false
-    ADPOSSampleStream stream = new ADPOSSampleStream(
+    try (ADPOSSampleStream stream = new ADPOSSampleStream(
         new PlainTextByLineStream(new ResourceAsStreamFactory(
             ADParagraphStreamTest.class, "/opennlp/tools/formats/ad.sample"),
-            "UTF-8"), false, false);
+                StandardCharsets.UTF_8), false, false)) {
+      POSSample sample = stream.read();
 
-    POSSample sample = stream.read();
+      Assert.assertEquals(23, sample.getSentence().length);
 
-    Assert.assertEquals(23, sample.getSentence().length);
+      Assert.assertEquals("Inicia", sample.getSentence()[0]);
+      Assert.assertEquals("v-fin", sample.getTags()[0]);
 
-    Assert.assertEquals("Inicia", sample.getSentence()[0]);
-    Assert.assertEquals("v-fin", sample.getTags()[0]);
+      Assert.assertEquals("em", sample.getSentence()[1]);
+      Assert.assertEquals("prp", sample.getTags()[1]);
 
-    Assert.assertEquals("em", sample.getSentence()[1]);
-    Assert.assertEquals("prp", sample.getTags()[1]);
+      Assert.assertEquals("o", sample.getSentence()[2]);
+      Assert.assertEquals("art", sample.getTags()[2]);
 
-    Assert.assertEquals("o", sample.getSentence()[2]);
-    Assert.assertEquals("art", sample.getTags()[2]);
-
-    Assert.assertEquals("Porto_Poesia", sample.getSentence()[9]);
-    Assert.assertEquals("prop", sample.getTags()[9]);
+      Assert.assertEquals("Porto_Poesia", sample.getSentence()[9]);
+      Assert.assertEquals("prop", sample.getTags()[9]);
+    }
   }
 
   @Test
   public void testExpandME() throws IOException {
     // add one sentence with expandME = true
-    ADPOSSampleStream stream = new ADPOSSampleStream(
+    try (ADPOSSampleStream stream = new ADPOSSampleStream(
         new PlainTextByLineStream(new ResourceAsStreamFactory(
             ADParagraphStreamTest.class, "/opennlp/tools/formats/ad.sample"),
-            "UTF-8"), true, false);
+                StandardCharsets.UTF_8), true, false)) {
 
-    POSSample sample = stream.read();
+      POSSample sample = stream.read();
 
-    Assert.assertEquals(27, sample.getSentence().length);
+      Assert.assertEquals(27, sample.getSentence().length);
 
-    Assert.assertEquals("Inicia", sample.getSentence()[0]);
-    Assert.assertEquals("v-fin", sample.getTags()[0]);
+      Assert.assertEquals("Inicia", sample.getSentence()[0]);
+      Assert.assertEquals("v-fin", sample.getTags()[0]);
 
-    Assert.assertEquals("em", sample.getSentence()[1]);
-    Assert.assertEquals("prp", sample.getTags()[1]);
+      Assert.assertEquals("em", sample.getSentence()[1]);
+      Assert.assertEquals("prp", sample.getTags()[1]);
 
-    Assert.assertEquals("o", sample.getSentence()[2]);
-    Assert.assertEquals("art", sample.getTags()[2]);
+      Assert.assertEquals("o", sample.getSentence()[2]);
+      Assert.assertEquals("art", sample.getTags()[2]);
 
-    Assert.assertEquals("Porto", sample.getSentence()[9]);
-    Assert.assertEquals("B-prop", sample.getTags()[9]);
+      Assert.assertEquals("Porto", sample.getSentence()[9]);
+      Assert.assertEquals("B-prop", sample.getTags()[9]);
 
-    Assert.assertEquals("Poesia", sample.getSentence()[10]);
-    Assert.assertEquals("I-prop", sample.getTags()[10]);
+      Assert.assertEquals("Poesia", sample.getSentence()[10]);
+      Assert.assertEquals("I-prop", sample.getTags()[10]);
+    }
   }
 
   @Test
   public void testIncludeFeats() throws IOException {
     // add one sentence with includeFeats = true
-    ADPOSSampleStream stream = new ADPOSSampleStream(
+    try (ADPOSSampleStream stream = new ADPOSSampleStream(
         new PlainTextByLineStream(new ResourceAsStreamFactory(
             ADParagraphStreamTest.class, "/opennlp/tools/formats/ad.sample"),
-            "UTF-8"), false, true);
+                StandardCharsets.UTF_8), false, true)) {
 
-    POSSample sample = stream.read();
+      POSSample sample = stream.read();
 
-    Assert.assertEquals(23, sample.getSentence().length);
+      Assert.assertEquals(23, sample.getSentence().length);
 
-    Assert.assertEquals("Inicia", sample.getSentence()[0]);
-    Assert.assertEquals("v-fin=PR=3S=IND=VFIN", sample.getTags()[0]);
+      Assert.assertEquals("Inicia", sample.getSentence()[0]);
+      Assert.assertEquals("v-fin=PR=3S=IND=VFIN", sample.getTags()[0]);
 
-    Assert.assertEquals("em", sample.getSentence()[1]);
-    Assert.assertEquals("prp", sample.getTags()[1]);
+      Assert.assertEquals("em", sample.getSentence()[1]);
+      Assert.assertEquals("prp", sample.getTags()[1]);
 
-    Assert.assertEquals("o", sample.getSentence()[2]);
-    Assert.assertEquals("art=DET=M=S", sample.getTags()[2]);
+      Assert.assertEquals("o", sample.getSentence()[2]);
+      Assert.assertEquals("art=DET=M=S", sample.getTags()[2]);
 
-    Assert.assertEquals("Porto_Poesia", sample.getSentence()[9]);
-    Assert.assertEquals("prop=M=S", sample.getTags()[9]);
+      Assert.assertEquals("Porto_Poesia", sample.getSentence()[9]);
+      Assert.assertEquals("prop=M=S", sample.getTags()[9]);
+    }
   }
 
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADSentenceSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADSentenceSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADSentenceSampleStreamTest.java
index 392c70c..1268dd1 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADSentenceSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADSentenceSampleStreamTest.java
@@ -18,6 +18,7 @@
 package opennlp.tools.formats.ad;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -54,16 +55,16 @@ public class ADSentenceSampleStreamTest {
     InputStreamFactory in = new ResourceAsStreamFactory(ADSentenceSampleStreamTest.class,
         "/opennlp/tools/formats/ad.sample");
 
-    ADSentenceSampleStream stream = new ADSentenceSampleStream(
-        new PlainTextByLineStream(in, "UTF-8"), true);
+    try (ADSentenceSampleStream stream = new ADSentenceSampleStream(
+          new PlainTextByLineStream(in, StandardCharsets.UTF_8), true)) {
 
-    SentenceSample sample = stream.read();
+      SentenceSample sample;
 
-    while (sample != null) {
-      System.out.println(sample.getDocument());
-      System.out.println("<fim>");
-      samples.add(sample);
-      sample = stream.read();
+      while ((sample = stream.read()) != null) {
+        System.out.println(sample.getDocument());
+        System.out.println("<fim>");
+        samples.add(sample);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamTest.java
index 8fa31be..a9fc656 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamTest.java
@@ -102,28 +102,28 @@ public class ConstitParseSampleStreamTest {
 
   @Test
   public void testThereIsExactlyOneSent() throws IOException {
-    ObjectStream<Parse> samples =
-        new ConstitParseSampleStream(ObjectStreamUtils.createObjectStream(getSample1()));
-
-    Assert.assertNotNull(samples.read());
-    Assert.assertNull(samples.read());
-    Assert.assertNull(samples.read());
+    try (ObjectStream<Parse> samples =
+        new ConstitParseSampleStream(ObjectStreamUtils.createObjectStream(getSample1()))) {
+      Assert.assertNotNull(samples.read());
+      Assert.assertNull(samples.read());
+      Assert.assertNull(samples.read());
+    }
   }
 
   @Test
   public void testTokensAreCorrect() throws IOException {
 
-    ObjectStream<Parse> samples =
-        new ConstitParseSampleStream(ObjectStreamUtils.createObjectStream(getSample1()));
+    try (ObjectStream<Parse> samples =
+        new ConstitParseSampleStream(ObjectStreamUtils.createObjectStream(getSample1()))) {
+      Parse p = samples.read();
 
-    Parse p = samples.read();
+      Parse[] tagNodes = p.getTagNodes();
+      String[] tokens = new String[tagNodes.length];
+      for (int ti = 0; ti < tagNodes.length; ti++) {
+        tokens[ti] = tagNodes[ti].getCoveredText();
+      }
 
-    Parse[] tagNodes = p.getTagNodes();
-    String[] tokens = new String[tagNodes.length];
-    for (int ti = 0; ti < tagNodes.length; ti++) {
-      tokens[ti] = tagNodes[ti].getCoveredText();
+      Assert.assertArrayEquals(sample1Tokens, tokens);
     }
-
-    Assert.assertArrayEquals(sample1Tokens, tokens);
   }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/ml/model/FileEventStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/ml/model/FileEventStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/ml/model/FileEventStreamTest.java
index 3837a25..1344079 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/ml/model/FileEventStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/ml/model/FileEventStreamTest.java
@@ -36,30 +36,28 @@ public class FileEventStreamTest {
 
   @Test
   public void testSimpleReading() throws IOException {
-    FileEventStream feStream = new FileEventStream(new StringReader(EVENTS));
-
-    Assert.assertEquals("other [wc=ic w&c=he,ic n1wc=lc n1w&c=belongs,lc n2wc=lc]",
-            feStream.read().toString());
-    Assert.assertEquals("other [wc=lc w&c=belongs,lc p1wc=ic p1w&c=he,ic n1wc=lc]",
-            feStream.read().toString());
-    Assert.assertEquals("other [wc=lc w&c=to,lc p1wc=lc p1w&c=belongs,lc p2wc=ic]",
-            feStream.read().toString());
-    Assert.assertEquals("org-start [wc=ic w&c=apache,ic p1wc=lc p1w&c=to,lc]",
-            feStream.read().toString());
-    Assert.assertEquals("org-cont [wc=ic w&c=software,ic p1wc=ic p1w&c=apache,ic]",
-            feStream.read().toString());
-    Assert.assertEquals("org-cont [wc=ic w&c=foundation,ic p1wc=ic p1w&c=software,ic]",
-            feStream.read().toString());
-    Assert.assertEquals("other [wc=other w&c=.,other p1wc=ic]",
-            feStream.read().toString());
-    Assert.assertNull(feStream.read());
+    try (FileEventStream feStream = new FileEventStream(new StringReader(EVENTS))) {
+      Assert.assertEquals("other [wc=ic w&c=he,ic n1wc=lc n1w&c=belongs,lc n2wc=lc]",
+              feStream.read().toString());
+      Assert.assertEquals("other [wc=lc w&c=belongs,lc p1wc=ic p1w&c=he,ic n1wc=lc]",
+              feStream.read().toString());
+      Assert.assertEquals("other [wc=lc w&c=to,lc p1wc=lc p1w&c=belongs,lc p2wc=ic]",
+              feStream.read().toString());
+      Assert.assertEquals("org-start [wc=ic w&c=apache,ic p1wc=lc p1w&c=to,lc]",
+              feStream.read().toString());
+      Assert.assertEquals("org-cont [wc=ic w&c=software,ic p1wc=ic p1w&c=apache,ic]",
+              feStream.read().toString());
+      Assert.assertEquals("org-cont [wc=ic w&c=foundation,ic p1wc=ic p1w&c=software,ic]",
+              feStream.read().toString());
+      Assert.assertEquals("other [wc=other w&c=.,other p1wc=ic]",
+              feStream.read().toString());
+      Assert.assertNull(feStream.read());
+    }
   }
 
   @Test
   public void testReset() throws IOException {
-    FileEventStream feStream = new FileEventStream(new StringReader(EVENTS));
-
-    try {
+    try (FileEventStream feStream = new FileEventStream(new StringReader(EVENTS))) {
       feStream.reset();
       Assert.fail("UnsupportedOperationException should be thrown");
     }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/3e66f1b6/opennlp-tools/src/test/java/opennlp/tools/ml/model/RealValueFileEventStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/ml/model/RealValueFileEventStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/ml/model/RealValueFileEventStreamTest.java
index 9474dc6..2b126cc 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/ml/model/RealValueFileEventStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/ml/model/RealValueFileEventStreamTest.java
@@ -36,30 +36,28 @@ public class RealValueFileEventStreamTest {
 
   @Test
   public void testSimpleReading() throws IOException {
-    FileEventStream feStream = new FileEventStream(new StringReader(EVENTS));
-
-    Assert.assertEquals("other [wc=ic=1 w&c=he,ic=2 n1wc=lc=3 n1w&c=belongs,lc=4 n2wc=lc=5]",
-            feStream.read().toString());
-    Assert.assertEquals("other [wc=lc=1 w&c=belongs,lc=2 p1wc=ic=3 p1w&c=he,ic=4 n1wc=lc=5]",
-            feStream.read().toString());
-    Assert.assertEquals("other [wc=lc=1 w&c=to,lc=2 p1wc=lc=3 p1w&c=belongs,lc=4 p2wc=ic=5]",
-            feStream.read().toString());
-    Assert.assertEquals("org-start [wc=ic=1 w&c=apache,ic=2 p1wc=lc=3 p1w&c=to,lc=4]",
-            feStream.read().toString());
-    Assert.assertEquals("org-cont [wc=ic=1 w&c=software,ic=2 p1wc=ic=3 p1w&c=apache,ic=4]",
-            feStream.read().toString());
-    Assert.assertEquals("org-cont [wc=ic=1 w&c=foundation,ic=2 p1wc=ic=3 p1w&c=software,ic=4]",
-            feStream.read().toString());
-    Assert.assertEquals("other [wc=other=1 w&c=.,other=2 p1wc=ic=3]",
-            feStream.read().toString());
-    Assert.assertNull(feStream.read());
+    try (FileEventStream feStream = new FileEventStream(new StringReader(EVENTS))) {
+      Assert.assertEquals("other [wc=ic=1 w&c=he,ic=2 n1wc=lc=3 n1w&c=belongs,lc=4 n2wc=lc=5]",
+              feStream.read().toString());
+      Assert.assertEquals("other [wc=lc=1 w&c=belongs,lc=2 p1wc=ic=3 p1w&c=he,ic=4 n1wc=lc=5]",
+              feStream.read().toString());
+      Assert.assertEquals("other [wc=lc=1 w&c=to,lc=2 p1wc=lc=3 p1w&c=belongs,lc=4 p2wc=ic=5]",
+              feStream.read().toString());
+      Assert.assertEquals("org-start [wc=ic=1 w&c=apache,ic=2 p1wc=lc=3 p1w&c=to,lc=4]",
+              feStream.read().toString());
+      Assert.assertEquals("org-cont [wc=ic=1 w&c=software,ic=2 p1wc=ic=3 p1w&c=apache,ic=4]",
+              feStream.read().toString());
+      Assert.assertEquals("org-cont [wc=ic=1 w&c=foundation,ic=2 p1wc=ic=3 p1w&c=software,ic=4]",
+              feStream.read().toString());
+      Assert.assertEquals("other [wc=other=1 w&c=.,other=2 p1wc=ic=3]",
+              feStream.read().toString());
+      Assert.assertNull(feStream.read());
+    }
   }
 
   @Test
   public void testReset() throws IOException {
-    FileEventStream feStream = new FileEventStream(new StringReader(EVENTS));
-
-    try {
+    try (FileEventStream feStream = new FileEventStream(new StringReader(EVENTS))) {
       feStream.reset();
       Assert.fail("UnsupportedOperationException should be thrown");
     }