package edu.washington.escience.myria.api.encoding;

import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;

import edu.washington.escience.myria.Schema;
import edu.washington.escience.myria.Type;
import edu.washington.escience.myria.expression.Expression;
import edu.washington.escience.myria.expression.ExpressionOperator;

/**
 * Holds the AST and output name.
 */
public final class ExpressionEncoding extends MyriaApiEncoding implements Serializable {
  /***/
  private static final long serialVersionUID = 1L;

  @JsonProperty
  private final String outputName;

  @JsonProperty
  private final ExpressionOperator rootExpressionOperator;

  private static final ImmutableList<String> requiredFields = ImmutableList.of("outputName", "rootExpressionOperator");

  public ExpressionEncoding() {
    outputName = null;
    rootExpressionOperator = null;
  }

  public ExpressionEncoding(String outputName, ExpressionOperator rootExpressionOperator) {
    this.outputName = outputName;
    this.rootExpressionOperator = rootExpressionOperator;
  }

  @Override
  protected List<String> getRequiredFields() {
    return requiredFields;
  }

  /**
   * @param schema the input schema
   * @return the type of the output of the expression
   */
  public Type getOutputType(final Schema schema) {
    return rootExpressionOperator.getOutputType(schema);
  }

  public String getJavaString(final Schema schema) {
    return rootExpressionOperator.getJavaString(schema);
  }

  public Expression construct() {
    return new Expression(outputName, this);
  }
}
@@ -857,30 +857,157 @@
 rator%22);%0A%0A  
-public
+/**%0A   * This is not really unused, it's used automagically by Jackson deserialization.%0A   */%0A  @SuppressWarnings(%22unused%22)%0A  private
  ExpressionE
@@ -1109,16 +1109,22 @@
 ncoding(
+final 
 String o
@@ -1133,16 +1133,22 @@
 putName,
+ final
  Express

make the default constructor private