package com.jscape.inet.terminal;

/**
 * Simple sequence type. In general it has only two characters in sequence:
 * "\033C", where C - alpha or digit character.
 */
public class SimpleType
        implements SequenceType {

    private static final SimpleType INSTANCE = new SimpleType();

    //----------------------------------------------------------------------------

    /**
     * Returns one and only one instance of this type.
     *
     * @return one and only one instance of <code>SimpleType</code> object.
     */
    public static SimpleType getInstance() {
        return INSTANCE;
    }

    //----------------------------------------------------------------------------

    /**
     * Private constructor to prevent uncontrolled creation.
     */
    private SimpleType() {
    }

    //----------------------------------------------------------------------------

    /**
     * Checks if sequence is complete.
     *
     * @param value sequence value.
     *
     * @return true if sequence is complete.
     */
    public boolean isComplete(StringBuffer value) {
        return (value.length() == 2);
    }

    //----------------------------------------------------------------------------

    /**
     * Extracts and returns sequence parameters as array of <code>int</code>.
     *
     * @param value sequence value.
     *
     * @return array of <code>int</code>.
     */
    public int[] getParameters(StringBuffer value) {
        return new int[0];
    }

    //----------------------------------------------------------------------------

    /**
     * Returns "canonical" form of control sequence (i.e. without parameters).
     * For example: having "\033A" incoming sequence its "canonical" form
     * will be "\033A".
     *
     * @param value sequence value.
     *
     * @return string with "canonical" sequence form.
     */
    public String getCanonicalForm(StringBuffer value) {
        return value.toString();
    }

}