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

package com.startingblocktech.tcases;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Defines an individual input variable.
 *
 * @version $Revision$, $Date$
 */
public class VarDef extends AbstractVarDef
  {
  /**
   * Creates a new VarDef object.
   */
  public VarDef()
    {
    this( null);
    }
  
  /**
   * Creates a new VarDef object.
   */
  public VarDef( String name)
    {
    super( name);
    }

  /**
   * If this variable has member variables, returns an iterator for the member variable list.
   * Otherwise, returns null.
   */
  public Iterator<IVarDef> getMembers()
    {
    return null;
    }

  /**
   * If this variable defines a value set, returns an iterator for the value set.
   * Otherwise, returns null.
   */
  public Iterator<VarValueDef> getValues()
    {
    return values_.iterator();
    }

  /**
   * Adds a value definition for this variable.
   */
  public VarDef addValue( VarValueDef value)
    {
    assert value != null;
    assert value.getName() != null;

    if( findValue( value.getName()) >= 0)
      {
      throw new IllegalStateException( "Value=" + value.getName() + " already defined for variable=" + getPathName());
      }

    values_.add( value);
    return this;
    }

  /**
   * Removes a value definition from this variable.
   */
  public VarDef removeValue( String name)
    {
    int i = findValue( name);
    if( i >= 0)
      {
      values_.remove(i);
      }

    return this;
    }

  /**
   * Returns the value definition with the given name.
   */
  public VarValueDef getValue( String name)    {
    int i = findValue( name);
    return i >= 0? values_.get(i) : null;
    }

  /**
   * Returns the index of the value definition with the given name.
   */
  protected int findValue( String name)
    {
    int valueCount = name==null? 0 : values_.size();
    int i;
    for( i = 0; i < valueCount && !name.equals( values_.get(i).getName()); i++);
    return i < valueCount? i : -1;
    }
  
  private List<VarValueDef> values_ = new ArrayList<VarValueDef>();
  }


@@ -311,16 +311,123 @@
 cases;%0A%0A
+import org.apache.commons.collections15.IteratorUtils;%0Aimport org.apache.commons.collections15.Predicate;%0A%0A
 import j
@@ -1239,32 +1239,803 @@
 rator();%0A    %7D%0A%0A
+  /**%0A   * Returns an iterator for the set of valid values.%0A   */%0A  public Iterator%3CVarValueDef%3E getValidValues()%0A    %7B%0A    return%0A      IteratorUtils.filteredIterator%0A      ( getValues(),%0A        new Predicate%3CVarValueDef%3E()%0A          %7B%0A          public boolean evaluate( VarValueDef valueDef)%0A            %7B%0A            return valueDef.isValid();%0A            %7D%0A          %7D);%0A    %7D%0A%0A  /**%0A   * Returns an iterator for the set of failure values.%0A   */%0A  public Iterator%3CVarValueDef%3E getFailureValues()%0A    %7B%0A    return%0A      IteratorUtils.filteredIterator%0A      ( getValues(),%0A        new Predicate%3CVarValueDef%3E()%0A          %7B%0A          public boolean evaluate( VarValueDef valueDef)%0A            %7B%0A            return !valueDef.isValid();%0A            %7D%0A          %7D);%0A    %7D%0A%0A
   /**%0A   * Adds 

Add get{Valid,Failure}Values()