You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2011/10/06 21:34:53 UTC

svn commit: r1179782 - /incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java

Author: colen
Date: Thu Oct  6 19:34:53 2011
New Revision: 1179782

URL: http://svn.apache.org/viewvc?rev=1179782&view=rev
Log:
OPENNLP-316 Evaluator should check if the monitor list element is not null.

Modified:
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java?rev=1179782&r1=1179781&r2=1179782&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java Thu Oct  6 19:34:53 2011
@@ -19,7 +19,8 @@
 package opennlp.tools.util.eval;
 
 import java.io.IOException;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import opennlp.tools.util.ObjectStream;
@@ -34,9 +35,18 @@ public abstract class Evaluator<T> {
 
   private List<EvaluationMonitor<T>> listeners;
   
-  public Evaluator(EvaluationMonitor<T>... listeners) {
-    if(listeners != null) {
-      this.listeners = Arrays.asList(listeners);
+  public Evaluator(EvaluationMonitor<T>... aListeners) {
+    if (aListeners != null) {
+      List<EvaluationMonitor<T>> listenersList = new ArrayList<EvaluationMonitor<T>>(
+          aListeners.length);
+      for (EvaluationMonitor<T> evaluationMonitor : aListeners) {
+        if (evaluationMonitor != null) {
+          listenersList.add(evaluationMonitor);
+        }
+      }
+      listeners = Collections.unmodifiableList(listenersList);
+    } else {
+      listeners = Collections.emptyList();
     }
   }
   
@@ -70,7 +80,7 @@ public abstract class Evaluator<T> {
    */
   public void evaluateSample(T sample) {
     T predicted = processSample(sample);
-    if(listeners != null) {
+    if(!listeners.isEmpty()) {
       if(sample.equals(predicted)) {
         for (EvaluationMonitor<T> listener : listeners) {
           listener.correctlyClassified(predicted, predicted);