package W3C.PICS;
import java.util.Vector;
/**
 * Rating is the building block of SingleLabel
 *
 * @see W3C.PICS.SingleLabel
 * @see W3C.PICS.SingleLabelDialog
 * @author Ching Law
 */
public class Rating
{
/**
 *  Constructor for single value Rating
 *
 */

 public Rating(String categorytransmit,double value)
 {
    this.categorytransmit=categorytransmit;
    valuelist=new Vector();
    valuelist.addElement(new Double(value));
    multivalue=false;
 }
/**
 *  Constructor for multi-value Rating
 */
 public Rating(String categorytransmit)
 {
    this.categorytransmit=categorytransmit;
    valuelist=new Vector();
    multivalue=true;
 }

 public void addValue(double value)
 {
  if (multivalue)
     valuelist.addElement(new Double(value));
  else throw new RuntimeException();
 }
/**

 * @return The string representation of the Rating object
 */
 public String toString()
 {
  if (multivalue)
    {String s="(";
     for (int i=0; i<valuelist.size();i++)
     {
      if (i!=0) s+=" ";
      s+=(Double)valuelist.elementAt(i);
     }
     s+=")";

     return categorytransmit + " " + s;
    }
  else return categorytransmit + " " + valuelist.elementAt(0);
 }
/**

 * @return The output string used for list display in SingleLabelDialog
 */
 public String getListString()
 {
  StringBuffer sb=new StringBuffer(categorytransmit);
  for (int i=0;i<35-sb.length();i++)
    {
      sb.append(" ");
    }

  if (multivalue)
    {
        for (int i=0; i<valuelist.size();i++)
        {
            if (i!=0) sb.append(" ");
            sb.append((Double)valuelist.elementAt(i));
        }
        return sb.toString();
    }
  else
    return sb.toString() + " " + valuelist.elementAt(0);

 }

 public String getTransmit()
 {
  return categorytransmit;
 }

 private boolean multivalue;
 private String categorytransmit;
 private Vector valuelist;
}
