package com.bbn.kbp.events2014;

import com.google.common.base.Optional;

import static com.google.common.base.Preconditions.checkNotNull;

public final class ScoringData {

  private final AnswerKey answerKey;
  private final ArgumentOutput argumentOutput;
  private final ResponseLinking systemLinking;
  private final ResponseLinking referenceLinking;

  protected ScoringData(ArgumentOutput argumentOutput, AnswerKey answerKey,
      ResponseLinking systemLinking, ResponseLinking referenceLinking) {
    this.answerKey = answerKey;
    this.argumentOutput = argumentOutput;
    // nullable
    this.systemLinking = systemLinking;
    // nullable
    this.referenceLinking = referenceLinking;
  }

  public Optional<AnswerKey> answerKey() {
    return Optional.fromNullable(answerKey);
  }

  public Optional<ArgumentOutput> systemOutput() {
    return Optional.fromNullable(argumentOutput);
  }

  public Optional<ResponseLinking> systemLinking() {
    return Optional.fromNullable(systemLinking);
  }

  public Optional<ResponseLinking> referenceLinking() {
    return Optional.fromNullable(referenceLinking);
  }

  public static Builder builder() {
    return new Builder();
  }

  public Builder modifiedCopy() {
    Builder ret = new Builder();
    if (answerKey != null) {
      ret. withAnswerKey(answerKey);
    }
    if (argumentOutput != null) {
      ret.withSystemOutput(argumentOutput);
    }
    if (systemLinking != null) {
      ret.withSystemLinking(systemLinking);
    }
    if (referenceLinking != null) {
      ret.withReferenceLinking(referenceLinking);
    }
    return ret;
  }

  public static final class Builder {
    private AnswerKey answerKey = null;
    private ArgumentOutput argumentOutput = null;
    private ResponseLinking systemLinking = null;
    private ResponseLinking referenceLinking = null;

    private Builder() {
    }

    public Builder withAnswerKey(AnswerKey answerKey) {
      this.answerKey = checkNotNull(answerKey);
      return this;
    }

    public Builder withSystemOutput(ArgumentOutput argumentOutput) {
      this.argumentOutput = checkNotNull(argumentOutput);
      return this;
    }

    public Builder withSystemLinking(ResponseLinking systemLinking) {
      this.systemLinking = checkNotNull(systemLinking);
      return this;
    }

    public Builder withReferenceLinking(ResponseLinking referenceLinking) {
      this.referenceLinking = checkNotNull(referenceLinking);
      return this;
    }

    public ScoringData build() {
      return new ScoringData(argumentOutput, answerKey, systemLinking, referenceLinking);
    }
  }
}

@@ -41,37 +41,208 @@
 com.
-google.common.base.Optional;%0A
+bbn.bue.common.symbols.Symbol;%0A%0Aimport com.google.common.base.Optional;%0Aimport com.google.common.collect.Sets;%0A%0Aimport java.util.Set;%0A%0Aimport static com.google.common.base.Preconditions.checkArgument;
 %0Aimp
@@ -861,16 +861,40 @@
 inking;%0A
+    checkDocIDsMatch();%0A
   %7D%0A%0A  p
@@ -2790,10 +2790,553 @@
   %7D%0A  %7D%0A
+%0A%0A  private void checkDocIDsMatch() %7B%0A    final Set%3CSymbol%3E docIDsPresent = Sets.newHashSet();%0A    if (answerKey != null) %7B%0A      docIDsPresent.add(answerKey.docId());%0A    %7D%0A    if (argumentOutput != null) %7B%0A      docIDsPresent.add(argumentOutput.docId());%0A    %7D%0A    if (systemLinking != null) %7B%0A      docIDsPresent.add(systemLinking.docID());%0A    %7D%0A    if (referenceLinking != null) %7B%0A      docIDsPresent.add(referenceLinking.docID());%0A    %7D%0A    checkArgument(docIDsPresent.size() %3C 2, %22ScoringData has mixed docIDs: %25s%22, docIDsPresent);%0A  %7D%0A
 %7D%0A

Enforce the document IDs match for all components of a ScoringData