package W3C.PICS;
import java.util.*;
import java.io.IOException;

/**
 * Enum represents a single labeled value in a Category
 */
public class Enum
{
    /**
     * Constructs an Enum from a PICSTokenizer
     */
    public Enum(PICSTokenizer PT) throws PICSException, IOException
    {
            //Get Name
        int type=PT.nextPair("name",'"');
        if (type==PICSTokenizer.T_CLOSEPAREN)
            throw new PICSException("Unexpected ) ");
        name=PT.sval;

        type=PT.nextEnumOption();
        if (type==PICSTokenizer.T_CLOSEPAREN)
            throw new PICSException("Unexpected ) ");

        if (type==PICSTokenizer.T_OPTIONPAIR && PT.option.equals("description"))
           {
            description=PT.sval;
            type=PT.nextEnumOption();
            if (type==PICSTokenizer.T_CLOSEPAREN)
                throw new PICSException("Unexpected ) ");
           }

        if (!(type==PICSTokenizer.T_OPTIONPAIR && PT.option.equals("value")))
            throw new PICSException("enum value expected");


        value=PT.nval;

        type=PT.nextEnumOption();
        if (type==PICSTokenizer.T_CLOSEPAREN)
            return;
        if (type==PICSTokenizer.T_OPTIONPAIR && PT.option.equals("icon"))
            {icon=PT.sval;
            PT.endPair();
            return;}
          else
            throw new RuntimeException("Error at Enum initiation");

    }

    public String getDescription()
    {return description;}

    public String getIcon()
    {return icon;}
    public String getName()
    {return name;}

    public double getValue()
    {return value;}

    /**
     * @return a description of the Enum
     */
    public String toString()
    {
        return "Label ---\n" +
        "name: " + name + "\n" +
        "description: " + description + "\n" +
        "value: " + value + "\n" +
        "icon: " + icon + "\n";
    }

    private String description="";
    private String icon="";
    private String name="";
    private double value=0;
}