package com.jscape.inet.terminal;

/**
 * Represents "Special Graphic Character Set" in VT100 terminal.
 * For character map see VT100 User's Manual.
 * "Singleton" pattern [Gamma94].
 * "Strategy" pattern [Gamma94].
 */
public class SpecialGraphic
        implements CharacterSet {

    private static final SpecialGraphic INSTANCE = new SpecialGraphic();
    private static final int BASE = 95;
    private final char[] chars = {
            '\u0000', '\u2666', '\u2592', '\u0000', '\u0000', '\u0000', '\u0000',
            '\u00b0', '\u00b1', '\u0000', '\u0000', '\u2518', '\u2510', '\u250c',
            '\u2514', '\u253c', '\u2500', '\u2500', '\u2500', '\u2500', '\u2500',
            '\u251c', '\u2524', '\u2534', '\u252c', '\u2502', '\u2264', '\u2265',
            '\u03c0', '\u2260', '\u00a3', '\u00b7'
    };

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

    /**
     * Returns one and only one instance of this type.
     *
     * @return one and only one instance of this type.
     */
    public static SpecialGraphic getInstance() {
        return INSTANCE;
    }

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

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

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

    /**
     * Encodes giving character.
     *
     * @param ch character to be encoded.
     *
     * @return encoded character.
     */
    public char encode(char ch) {
        int ind = ch - this.BASE;
        return (0 <= ind && ind < this.chars.length) ? this.chars[ind] : ch;
    }

}
