// (c) MIT 2003.  All rights reserved.

// $Id: VectorSet.java,v 1.3 2003/03/06 00:40:38 moltmans Exp $
// Time-stamp: <2000-03-11 18:59:35 moltmans>
package rec.util;


import java.util.*;

public class VectorSet extends Vector implements Set
{
  public VectorSet()
  {
  }

  public VectorSet( Collection c )
  {
    super( c );
  }

  public boolean add( Object o )
  {
    if ( !contains( o ) ) {
      super.addElement( o );
      return true;
    }
    else {
      return false;
    }
  }

  public void addElement( Object obj )
  {
    if ( !contains( obj ) ) {
      super.addElement( obj );
    }
  } 

  public boolean addAll( Collection c ) 
  {
    Iterator it = c.iterator();
    while ( it.hasNext() ) {
      add( it.next() );
    }
    return true;
  }

  public Object getRandomElement()
  {
    if ( size() == 0 ) {
      return null;
    }
    Random r = new Random();
    return elementAt( (int)(r.nextFloat() * (float)size()) );
  }

}
