package com.bbn.kbp.events2014.io;

import com.bbn.bue.common.TextGroupPublicImmutable;
import com.bbn.bue.common.symbols.Symbol;
import com.bbn.kbp.events2014.AssessedQuery2016;
import com.bbn.kbp.events2014.QueryResponse2016;
import com.bbn.kbp.events2014.QueryResponse2016Functions;

import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import org.immutables.func.Functional;
import org.immutables.value.Value;

/**
 * A store for 2016 Queries, supporting reading/writing to/from a single file
 */
@TextGroupPublicImmutable
@Value.Immutable
@Functional
public abstract class _QueryStore2016 {

  public ImmutableSet<Symbol> queryIDs() {
    return FluentIterable.from(queries()).index(QueryResponse2016Functions.queryID()).keySet();
  }

  public ImmutableSet<Symbol> docIDs() {
    return FluentIterable.from(queries()).index(QueryResponse2016Functions.docID()).keySet();
  }

  public ImmutableSet<Symbol> systemIDs() {
    return FluentIterable.from(queries()).index(QueryResponse2016Functions.systemID()).keySet();
  }

  // may never contain an AssessedQuery2016 with an assessment of QueryAssessment2016.UNASSASSED
  public abstract ImmutableMap<QueryResponse2016, String> metadata();

  public abstract ImmutableMap<QueryResponse2016, AssessedQuery2016> assessments();

  public abstract ImmutableSet<QueryResponse2016> queries();
}

@@ -168,24 +168,75 @@
 dQuery2016;%0A
+import com.bbn.kbp.events2014.QueryAssessment2016;%0A
 import com.b
@@ -554,89 +554,189 @@
 e;%0A%0A
-/**%0A * A store for 2016 Queries, supporting reading/writing to/from a single file
+import static com.google.common.base.Preconditions.checkState;%0A%0A/**%0A * An immutable collection of %7B@link QueryResponse2016%7D, %7B@link QueryAssessment2016%7D, and associated%0A * metadata.
 %0A */
@@ -832,16 +832,92 @@
 2016 %7B%0A%0A
+  /**%0A   * @return A derived set from %7B@link #queries()%7D of query IDs%0A   */%0A
   public
@@ -1044,32 +1044,111 @@
 .keySet();%0A  %7D%0A%0A
+  /**%0A   * @return A derived set from %7B@link #queries()%7D of Document IDs%0A   */%0A
   public Immutab
@@ -1271,16 +1271,93 @@
 );%0A  %7D%0A%0A
+  /**%0A   * @return A derived set from %7B@link #queries()%7D of System IDs%0A   */%0A
   public
@@ -1500,173 +1500,1109 @@
 %0A%0A  
-// may never contain an AssessedQuery2016 with an assessment of QueryAssessment2016.UNASSASSED%0A  public abstract ImmutableMap%3CQueryResponse2016, String%3E metadata();%0A
+@Value.Check%0A  protected void check() %7B%0A    checkState(queries().containsAll(metadata().keySet()),%0A        %22Metadata contained an unknown query; error in constructing the store!%22);%0A    checkState(queries().containsAll(assessments().keySet()),%0A        %22Assessments contained an unknown query; error in constructing the store!%22);%0A    for (final QueryResponse2016 q : assessments().keySet()) %7B%0A      checkState(assessments().get(q).query().equals(q),%0A          %22Query %22 + q + %22 mapped to an incorrect assessment %22 + assessments().get(q));%0A      checkState(!assessments().get(q).assessment().equals(QueryAssessment2016.UNASSASSED),%0A          %22No storing of UNASSESSED queries in the assessments allowed%22);%0A    %7D%0A  %7D%0A%0A%0A  /**%0A   * A map of %7B@link QueryResponse2016%7D to associated metadata, if any. The map may contain null%0A   * entries.%0A   */%0A  public abstract ImmutableMap%3CQueryResponse2016, String%3E metadata();%0A%0A  /**%0A   * A map of %7B@link QueryResponse2016%7D to %7B@link AssessedQuery2016%7D may never contain an %7B@link%0A   * AssessedQuery2016%7D with an assessment of %7B@link QueryAssessment2016#UNASSASSED%7D%0A   */
 %0A  p

add documentation and add explicit immutable check for certain invariants upon creation