package vermilion;

/**
 * A parameter meant to represent a sample number. This is stored as
 * a value between 000 and 999.
 */
public class ParameterSample extends ParameterBase
{
    public int value;

    /**
     * The constructor creates a parameter.
     * @param name A name for this parameter.
     * @param isTrack Indicates whether the parameter is global.
     */
    public ParameterSample(String name, boolean isTrack)
    {
        super(name, PARAMETER_TYPE_SAMPLE, isTrack);
        value = 0;
    }

    /**
     * This constructor creates a command.
     */
    public ParameterSample(int val)
    {
        super(PARAMETER_TYPE_SAMPLE);
        value = val;
    }

    /**
     * The serialisation type for this object is 'SMP'.
     */
    @Override
    public String getType() { return "SMP"; }

    /**
     * The current serialisation version for this object is 1.
     */
    @Override
    public int getVersion() { return 1; }

    @Override
    public String saveImpl()
    {
        return String.valueOf(value);
    }

    @Override
    public UsefulFileObject loadImpl(String str, int version)
    {
        if (version == 1)
        {
            ParameterSample smp = new ParameterSample(Integer.parseInt(str));
            return smp;
        }

        return null;
    }

    @Override
    public void copyValue(ParameterBase source)
    {
        value = ((ParameterSample) source).value;
    }

    @Override
    public String printValue()
    {
        return String.valueOf(value);
    }
}
