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

package com.startingblocktech.tcases;

import com.startingblocktech.tcases.util.ToString;

import org.apache.commons.collections15.bag.HashBag;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

/**
 * Defines a set of test case properties.
 *
 * @version $Revision$, $Date$
 */
public class PropertySet
  {
  /**
   * Creates a new PropertySet object.
   */
  public PropertySet()
    {
    this( (Collection<String>) null);
    }
  
  /**
   * Creates a new PropertySet object.
   */
  public PropertySet( String ...properties)
    {
    this( Arrays.asList( properties));
    }
  
  /**
   * Creates a new PropertySet object.
   */
  public PropertySet( Collection<String> properties)
    {
    properties_ = new HashBag<String>();
    addAll( properties);
    }

  /**
   * Adds a property to this set.
   */
  public PropertySet add( String property)
    {
    String candidate = StringUtils.trimToNull( property);
    if( candidate != null)
      {
      properties_.add( candidate);
      }

    return this;
    }

  /**
   * Adds a set of properties to this set.
   */
  public PropertySet addAll( PropertySet propertySet)
    {
    if( propertySet != null)
      {
      addAll( propertySet.properties_.uniqueSet());
      }

    return this;
    }

  /**
   * Adds a set of properties to this set.
   */
  public PropertySet addAll( Collection<String> properties)
    {
    if( properties != null)
      {
      for( String property : properties)
        {
        add( property);
        }
      }

    return this;
    }

  /**
   * Removes a property from this set.
   */
  public PropertySet remove( String property)
    {
    String candidate = StringUtils.trimToNull( property);
    if( candidate != null)
      {
      properties_.remove( candidate, 1);
      }

    return this;
    }

  /**
   * Removes a set of properties from this set.
   */
  public PropertySet removeAll( Collection<String> properties)
    {
    if( properties != null)
      {
      for( String property : properties)
        {
        remove( property);
        }
      }
    
    return this;
    }

  /**
   * Removes all properties this set.
   */
  public void clear()
    {
    properties_.clear();
    }

  /**
   * Returns true if the given property is a member of this set.
   */
  public boolean contains( String property)
    {
    return properties_.contains( property);
    }

  /**
   * Returns the members of this set.
   */
  public Iterator<String> getProperties()
    {
    return properties_.iterator();
    }

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

  private HashBag<String> properties_;
  }


@@ -1549,17 +1549,20 @@
 ertySet.
-p
+getP
 ropertie
@@ -1566,19 +1566,8 @@
 ties
-_.uniqueSet
 ());
@@ -1800,32 +1800,32 @@
 ties)%0A        %7B%0A
-
         add( pro
@@ -1867,32 +1867,308 @@
 rn this;%0A    %7D%0A%0A
+  /**%0A   * Adds a set of properties to this set.%0A   */%0A  public PropertySet addAll( Iterator%3CString%3E properties)%0A    %7B%0A    if( properties != null)%0A      %7B%0A      while( properties.hasNext())%0A        %7B%0A        add( properties.next());%0A        %7D%0A      %7D%0A%0A    return this;%0A    %7D%0A%0A
   /**%0A   * Remov
@@ -3120,16 +3120,28 @@
 erties_.
+uniqueSet().
 iterator

Return distinct members only, ignoring cardinality