//////////////////////////////////////////////////////////////////////////////
// 
//               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 java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Defines test cases for a specific function.
 *
 * @version $Revision$, $Date$
 */
public class FunctionTestDef
  {
  /**
   * Creates a new FunctionTestDef object.
   */
  public FunctionTestDef()
    {
    this( null);
    }
  
  /**
   * Creates a new FunctionTestDef object.
   */
  public FunctionTestDef( String name)
    {
    setName( name);
    }

  /**
   * Changes the function name.
   */
  public void setName( String name)
    {
    assertIdentifier( name);
    name_ = name;
    }

  /**
   * Returns the function name.
   */
  public String getName()
    {
    return name_;
    }

  /**
   * Adds a new test case.
   */
  public FunctionTestDef addTestCase( TestCase testCase)
    {
    assert testCase != null;

    if( findTestCase( testCase.getId()) >= 0)
      {
      throw new IllegalStateException( "Test=" + testCase.getId() + " already defined for function=" + getName());
      }
    
    testCases_.add( testCase);
    return this;
    }

  /**
   * Removes a test case.
   */
  public FunctionTestDef removeTestCase( int id)
    {
    int i = findTestCase( id);
    if( i >= 0)
      {
      testCases_.remove(i);
      }

    return this;
    }

  /**
   * Returns the test case with the given id.
   */
  public TestCase getTestCase( int id)
    {
    int i = findTestCase( id);
    return i >= 0? testCases_.get(i) : null;
    }

  /**
   * Returns the test cases for this function.
   */
  public Iterator<TestCase> getTestCases()
    {
    return testCases_.iterator();
    }

  /**
   * Returns the index of the test case with the given id.
   */
  protected int findTestCase( int id)
    {
    int testCount = testCases_.size();
    int i;
    for( i = 0; i < testCount && testCases_.get(i).getId() != id; i++);
    return i < testCount? i : -1;
    }

  public String toString()
    {
    return
      ToString.getBuilder( this)
      .append( getName())
      .toString();
    }

  private String name_;
  private List<TestCase> testCases_ = new ArrayList<TestCase>();
  }


@@ -418,16 +418,61 @@
 ils.*;%0A%0A
+import org.apache.commons.lang.ObjectUtils;%0A%0A
 import j
@@ -2337,16 +2337,503 @@
 %0A    %7D%0A%0A
+  public int hashCode()%0A    %7B%0A    return%0A      getClass().hashCode()%0A      %5E (getName() == null? 0 : getName().hashCode())%0A      %5E testCases_.hashCode();%0A    %7D%0A%0A  public boolean equals( Object object)%0A    %7B%0A    FunctionTestDef other =%0A      object != null && object.getClass().equals( getClass())%0A      ? (FunctionTestDef) object%0A      : null;%0A%0A    return%0A      other != null%0A      && ObjectUtils.equals( getName(), other.getName())%0A      && testCases_.equals( other.testCases_);%0A    %7D%0A%0A
   public

Define equals()