package mfl;

public class Enumerated_set
extends mfl.Set
{
  java.util.Hashtable java_value;
  java.util.Enumeration enum;
  int curr_elem = -1;

  public Enumerated_set()
    {}

  public Enumerated_set(int size)
    {java_value = new java.util.Hashtable(size>0?size*2:16, 0.5f);}

  public mfl.Value append(mfl.Value x)
    {java_value.put(x, "true"); return this;}

  Enumerated_set copy_of()
    {Enumerated_set result = new Enumerated_set();
     result.java_value = (java.util.Hashtable)java_value.clone();
     return result;}   

  public boolean contains(mfl.Value x)
    {return java_value.containsKey(x);}

  public boolean equals(Object x)
    {if (!(x instanceof mfl.Set)) return false;
     if (!(x instanceof Enumerated_set)) return super.equals(x);
     return java_value.equals(((Enumerated_set)x).java_value);}

  public mfl.Value ith_element(int i)
    {mfl.Value result = mfl.Value.Undefined;
     if (curr_elem == -1 || curr_elem >= i){enum = java_value.keys(); curr_elem = 0;};
     while (curr_elem < i) result = (mfl.Value)enum.nextElement();
     return result;}

  public int size()
    {return java_value.size();}

  public java.lang.String toString()
    {java.lang.String result = "{";
     int n = java_value.size(), i = 0;
     if (n > 0)
       {java.util.Enumeration enum = java_value.keys();
       result += ((mfl.Value)enum.nextElement()).toString();
       while (++i < n)
         {result += " ";
         result += ((mfl.Value)enum.nextElement()).toString();}
     }
     result += "}"; return result;}

}

