package de.lmu.ifi.dbs.elki.result.combinators;

import java.util.ArrayList;
import java.util.Collection;

import de.lmu.ifi.dbs.elki.result.AnnotationResult;
import de.lmu.ifi.dbs.elki.utilities.pairs.Pair;

/**
 * AnnotationCombiner is a class that combines multiple Annotation Results into one.
 * 
 * @author Erich Schubert
 *
 * @param <T>
 */
public class AnnotationCombiner<T> implements AnnotationResult<T> {
  /**
   * Results to combine
   */
  private Collection<AnnotationResult<T>> results = new ArrayList<AnnotationResult<T>>();
  
  /**
   * Constructor
   */
  public AnnotationCombiner() {
    this(new ArrayList<AnnotationResult<T>>());
  }
  
  /**
   * Constructor with a list of results to combine.
   * 
   * @param results
   */
  public AnnotationCombiner(Collection<AnnotationResult<T>> results) {
    super();
    this.results = results;
  }

  /**
   * Add an annotation result to the result list.
   * 
   * @param result
   */
  public void addAnnotationResult(AnnotationResult<T> result) {
    this.results.add(result);
  }

  /**
   * Retrieve all annotations and return them as combined array.
   */
  @Override
  public Pair<String, T>[] getAnnotations(Integer objID) {
    ArrayList<Pair<String, T>> annotations = new ArrayList<Pair<String, T>>();
    for (AnnotationResult<T> result : results) {
        Pair<String, T>[] newannotations = result.getAnnotations(objID);
        for (Pair<String, T> newann : newannotations)
          annotations.add(newann);
      }
    Pair<String, T>[] result = Pair.newArray(0);
    return annotations.toArray(result);
  }
}

@@ -285,16 +285,19 @@
 lts into
+%0A *
  one.%0A *
@@ -326,16 +326,17 @@
 ubert%0A *
+ 
 %0A * @par
@@ -540,18 +540,16 @@
 %3CT%3E%3E();%0A
-  
 %0A  /**%0A 
@@ -654,18 +654,16 @@
 ));%0A  %7D%0A
-  
 %0A  /**%0A 
@@ -1282,17 +1282,16 @@
 %0A    for
- 
 (Annotat
@@ -1319,24 +1319,51 @@
  results) %7B%0A
+      if(result != null) %7B%0A
         Pair
@@ -1434,17 +1434,16 @@
      for
- 
 (Pair%3CSt
@@ -1475,16 +1475,18 @@
 tations)
+ %7B
 %0A       
@@ -1513,18 +1513,34 @@
 ewann);%0A
-
   
+      %7D%0A      %7D%0A
     %7D%0A  

Fix null pointer exception in annotation combiner.