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

package com.startingblocktech.tcases.generator;

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

/**
 * Defines a set of input variable combinations used for test cases.
 *
 * @version $Revision$, $Date$
 */
public class VarTupleSet
  {
  /**
   * Creates a new VarTupleSet object.
   */
  public VarTupleSet( List<Tuple> tuples)
    {
    unused_ = new ArrayList<Tuple>();
    if( tuples != null)
      {
      unused_.addAll( tuples);
      }
    
    used_ = new ArrayList<Tuple>();
    }

  /**
   * Returns input tuples not yet used in a test case.
   */
  public Iterator<Tuple> getUnused()
    {
    return unused_.iterator();
    }

  /**
   * Returns input tuples already used in a test case.
   */
  public Iterator<Tuple> getUsed()
    {
    return used_.iterator();
    }

  /**
   * Asserts that the given tuple has been used in a test case.
   */
  public void used( Tuple tuple)
    {
    int i = unused_.indexOf( tuple);
    if( i >= 0)
      {
      used_.add( unused_.remove( i));
      }
    }

  /**
   * Returns true if all members of this set have been used in test cases.
   */
  public boolean isConsumed()
    {
    return unused_.isEmpty();
    }

  /**
   * Returns the next unused tuple from this set. Returns null if all
   * tuples have been used.
   */
  public Tuple getNextUnused()
    {
    Iterator<Tuple> unused = getUnused();
    return
      unused.hasNext()
      ? unused.next()
      : null;
    }

  private List<Tuple> unused_;
  private List<Tuple> used_;
  }

@@ -330,16 +330,173 @@
 tor;%0D%0A%0D%0A
+import com.startingblocktech.tcases.VarDef;%0D%0A%0D%0Aimport org.apache.commons.collections15.IteratorUtils;%0D%0Aimport org.apache.commons.collections15.Predicate;%0D%0A%0D%0A
 import j
@@ -1180,114 +1180,966 @@
 les 
-already used in a test case.%0D%0A   */%0D%0A  public Iterator%3CTuple%3E getUsed()%0D%0A    %7B%0D%0A    return used_.iterator(
+not yet used in a test case that bind the given variable.%0D%0A   */%0D%0A  public Iterator%3CTuple%3E getUnused( final VarDef var)%0D%0A    %7B%0D%0A    return%0D%0A      IteratorUtils.filteredIterator%0D%0A      ( unused_.iterator(),%0D%0A        new Predicate%3CTuple%3E()%0D%0A        %7B%0D%0A        public boolean evaluate( Tuple tuple)%0D%0A          %7B%0D%0A          return tuple.getBinding( var) != null;%0D%0A          %7D%0D%0A        %7D);%0D%0A    %7D%0D%0A%0D%0A  /**%0D%0A   * Returns input tuples already used in a test case.%0D%0A   */%0D%0A  public Iterator%3CTuple%3E getUsed()%0D%0A    %7B%0D%0A    return used_.iterator();%0D%0A    %7D%0D%0A%0D%0A  /**%0D%0A   * Returns input tuples already used in a test case that bind the given variable.%0D%0A   */%0D%0A  public Iterator%3CTuple%3E getUsed( final VarDef var)%0D%0A    %7B%0D%0A    return%0D%0A      IteratorUtils.filteredIterator%0D%0A      ( used_.iterator(),%0D%0A        new Predicate%3CTuple%3E()%0D%0A        %7B%0D%0A        public boolean evaluate( Tuple tuple)%0D%0A          %7B%0D%0A          return tuple.getBinding( var) != null;%0D%0A          %7D%0D%0A        %7D
 );%0D%0A
@@ -2263,24 +2263,50 @@
 le)%0D%0A    %7B%0D%0A
+    // Currently unused?%0D%0A
     int i = 
@@ -2353,24 +2353,318 @@
 )%0D%0A      %7B%0D%0A
+      // Yes, relocated to used list.%0D%0A      used_.add( unused_.remove( i));%0D%0A      %7D%0D%0A%0D%0A    // No, already used?%0D%0A    else if( (i = used_.indexOf( tuple)) %3E= 0)%0D%0A      %7B%0D%0A      // Yes, move to the end of the list. This acts to keep the used list%0D%0A      // in least-recently-used-first order.%0D%0A
       used_.
@@ -2660,34 +2660,32 @@
      used_.add( 
-un
 used_.remove( i)

Add iterators to get tuples that bind a specific variable.