package mfl;

public class Enumerated_list
extends mfl.List
{
  java.util.Vector java_value;

  public Enumerated_list()
    {}

  public Enumerated_list(int size)
    {java_value = new java.util.Vector(size, 16);}

  public mfl.Value append(mfl.Value x)
    {java_value.addElement(x); return this;}

  Enumerated_list copy_of()
    {Enumerated_list result = new Enumerated_list();
     result.java_value = (java.util.Vector)java_value.clone();
     return result;}   

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

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

  public mfl.Value index_op(mfl.Value x)
    {int i;
    if (!(x instanceof mfl.Integer)) return super.index_op(x);
    i = (int)((mfl.Integer)x).java_value;
    if (i < 1) return super.index_op(x);
    if (i > java_value.size()) return super.index_op(x);
    return (mfl.Value)java_value.elementAt(i-1);}

  public mfl.Value ith_element(int i)
    {return (mfl.Value)java_value.elementAt(i-1);}

  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)
       {result += ((mfl.Value)java_value.elementAt(0)).toString();
       while (++i < n)
         {result += " ";
         result += ((mfl.Value)java_value.elementAt(i)).toString();}
     }
     result += "]"; return result;}

  public mfl.Value update_element(mfl.Value I, mfl.Value v)
    {if (!(I instanceof mfl.Integer)) return this;
     int i = (int)((mfl.Integer)I).java_value;
     if (i < 1 | i > size()+1) return this;
     Enumerated_list result = copy_of();
     result.java_value.setElementAt(v, i-1);
     return result;}
    
  public mfl.Value op_update_element(mfl.Value I, mfl.Value v, java.lang.String op)
    {if (!(I instanceof mfl.Integer)) return this;
     int i = (int)((mfl.Integer)I).java_value;
     if (i < 1 | i > size()+1) return this;
     Enumerated_list result = copy_of();
     mfl.Value ov = (mfl.Value)java_value.elementAt(i-1);
     if (op == "multiply_op") 
       result.java_value.setElementAt(ov.multiply_op(v), i-1);
     return result;}
}

