package uk.co.bristlecone.voltdb.wrapgen.source;

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

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * Represents a primitive parameter (e.g. <code>int foo</code>) to a stored procedure.
 * 
 * @author christo
 */
public class RunParameterPrimitive implements RunParameter {
  private String typeName;
  private String variableName;

  public static RunParameterPrimitive ofBoolean(String variableName) {
    return of("boolean", variableName);
  }

  public static RunParameterPrimitive ofByte(String variableName) {
    return of("byte", variableName);
  }

  public static RunParameterPrimitive ofShort(String variableName) {
    return of("short", variableName);
  }

  public static RunParameterPrimitive ofInt(String variableName) {
    return of("int", variableName);
  }

  public static RunParameterPrimitive ofLong(String variableName) {
    return of("long", variableName);
  }

  public static RunParameterPrimitive ofChar(String variableName) {
    return of("char", variableName);
  }

  public static RunParameterPrimitive ofFloat(String variableName) {
    return of("float", variableName);
  }

  public static RunParameterPrimitive ofDouble(String variableName) {
    return of("double", variableName);
  }

  public static RunParameterPrimitive of(String primitiveType, String variableName) {
    checkArgument(primitiveType != null, "primitiveType parameter must not be null");
    checkArgument(variableName != null, "variableName parameter must not be null");
    checkArgument(!primitiveType.equals(""), "primitiveType parameter must not be an empty String");
    checkArgument(!variableName.equals(""), "variableName parameter must not be an empty String");
    return new RunParameterPrimitive(primitiveType, variableName);
  }

  private RunParameterPrimitive(String typeName, String variableName) {
    this.typeName = typeName;
    this.variableName = variableName;
  }

  /**
   * @return true, by definition
   */
  @Override
  public boolean isPrimitive() {
    return true;
  }

  @Override
  public String typeName() {
    return typeName;
  }

  @Override
  public String variableName() {
    return variableName;
  }

  public int hashCode() {
    return new HashCodeBuilder(17, 37).append(typeName)
        .append(variableName)
        .toHashCode();
  }

  public boolean equals(Object other) {
    if(other == null) {
      return false;
    }
    if(other == this) {
      return true;
    }
    if(getClass() != other.getClass()) {
      return false;
    }
    RunParameterPrimitive rhs = (RunParameterPrimitive) other;
    return new EqualsBuilder().append(typeName, rhs.typeName())
        .append(variableName, rhs.variableName())
        .isEquals();
  }

  public String toString() {
    return new ToStringBuilder(this).append(typeName)
        .append(variableName)
        .build();
  }
}

@@ -280,16 +280,82 @@
 ilder;%0A%0A
+import uk.co.bristlecone.voltdb.wrapgen.WrapgenRuntimeException;%0A%0A
 /**%0A * R
@@ -2320,32 +2320,575 @@
  typeName;%0A  %7D%0A%0A
+  public Class%3C?%3E typeClass() %7B%0A    switch (typeName()) %7B%0A    case %22boolean%22:%0A      return boolean.class;%0A    case %22byte%22:%0A      return byte.class;%0A    case %22short%22:%0A      return short.class;%0A    case %22int%22:%0A      return int.class;%0A    case %22long%22:%0A      return long.class;%0A    case %22char%22:%0A      return char.class;%0A    case %22float%22:%0A      return float.class;%0A    case %22double%22:%0A      return double.class;%0A    default:%0A      throw new WrapgenRuntimeException(String.format(%22Unknown type in RunParameterPrimitive: %25s%22, typeName()));%0A    %7D%0A  %7D%0A%0A
   @Override%0A  pu

add typeClass method to RunParameterPrimitive