//////////////////////////////////////////////////////////////////////////////
// 
//               Copyright 2010, Starting Block Technologies
//                        www.startingblocktech.com
//
//////////////////////////////////////////////////////////////////////////////

package com.startingblocktech.tcases;

import com.startingblocktech.tcases.util.ToString;
import static com.startingblocktech.tcases.DefUtils.*;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Defines the binding of an input variable to a specific value.
 *
 * @version $Revision$, $Date$
 */
public class VarBinding
  {
  /**
   * Creates a new VarBinding object.
   */
  public VarBinding()
    {
    this( null, null, null);
    }
  
  /**
   * Creates a new VarBinding object.
   */
  public VarBinding( String varName, String valueName)
    {
    this( varName, IVarDef.ARG, valueName);
    }
  
  /**
   * Creates a new VarBinding object.
   */
  public VarBinding( String varName, String varType, String valueName)
    {
    setVar( varName);
    setType( varType);
    setValue( valueName);
    setValueValid( true);
    }
  
  /**
   * Creates a new VarBinding object.
   */
  public VarBinding( IVarDef varDef, VarValueDef valueDef)
    {
    this( varDef.getPathName(), varDef.getType(), valueDef.getName());
    setValueValid( valueDef.getType().isValid());
    }
  
  /**
   * Creates a new VarBinding object.
   */
  public VarBinding( VarBindingDef def)
    {
    this( def.getVarDef(), def.getValueDef());
    }

  /**
   * Changes the variable name for this binding.
   */
  public void setVar( String varName)
    {
    assertPath( varName);
    var_ = varName;
    }

  /**
   * Returns the variable name for this binding.
   */
  public String getVar()
    {
    return var_;
    }

  /**
   * Changes the value name for this binding.
   */
  public void setValue( String valueName)
    {
    assertIdentifier( valueName);
    value_ = valueName;
    }

  /**
   * Returns the value name for this binding.
   */
  public String getValue()
    {
    return value_;
    }

  /**
   * Changes the type identifier for this variable.
   */
  public void setType( String type)
    {
    assertIdentifier( type);
    varType_ = type;
    }

  /**
   * Returns the type identifier for this variable.
   */
  public String getType()
    {
    return varType_;
    }

  /**
   * Changes if this variable is bound to a valid value.
   */
  public void setValueValid( boolean valid)
    {
    valueValid_ = valid;
    }

  /**
   * Returns if this variable is bound to a valid value.
   */
  public boolean isValueValid()
    {
    return valueValid_;
    }

  public String toString()
    {
    ToStringBuilder builder = ToString.getBuilder( this);

    builder.getStringBuffer()
      .append( getVar())
      .append( '=')
      .append( getValue());

    if( !isValueValid())
      {
      builder.append( "valid", isValueValid());
      }

    return builder.toString();
    }

  private String var_;
  private String varType_;
  private String value_;
  private boolean valueValid_;
  }


@@ -418,16 +418,60 @@
 ils.*;%0A%0A
+import org.apache.commons.lang.ObjectUtils;%0A
 import o
@@ -649,16 +649,50 @@
 rBinding
+ implements Comparable%3CVarBinding%3E
 %0A  %7B%0A  /
@@ -3058,16 +3058,861 @@
 %0A    %7D%0A%0A
+  public int compareTo( VarBinding other)%0A    %7B%0A    return getVar().compareTo( other.getVar());%0A    %7D%0A%0A  public int hashCode()%0A    %7B%0A    return%0A      getClass().hashCode()%0A      %5E (getVar()==null? 0 : getVar().hashCode())%0A      %5E (getType()==null? 0 : getType().hashCode())%0A      %5E (getValue()==null? 0 : getValue().hashCode())%0A      %5E (isValueValid()? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode());%0A    %7D%0A%0A  public boolean equals( Object object)%0A    %7B%0A    VarBinding other =%0A      object != null && object.getClass().equals( getClass())%0A      ? (VarBinding) object%0A      : null;%0A%0A    return%0A      other != null%0A      && ObjectUtils.equals( getVar(), other.getVar())%0A      && ObjectUtils.equals( getType(), other.getType())%0A      && ObjectUtils.equals( getValue(), other.getValue())%0A      && isValueValid() == other.isValueValid();%0A    %7D%0A%0A
   privat

Add support for equals, compareTo