001package Torello.CSS;
002
003import java.util.Vector;
004
005// <colon-token>, <semicolon-token>, <comma-token>,
006// <[-token>, <]-token>, <(-token>, <)-token>, <{-token>, and <}-token>.
007
008/**
009 * A class for saving one of nine different Punctuation-Token classes.
010 * The nine-available singleton-instances include: 
011 * <B STYLE='color: red;'>{@code ':', ';', ',', '[', ']', '(', ')', '{', '}'}</B>
012 */
013@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="CSS_TOK")
014public final class Punct extends CSSToken
015    implements CharSequence, java.io.Serializable, Comparable<CharSequence>
016{
017    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
018    protected static final long serialVersionUID = 1;
019
020
021    // ********************************************************************************************
022    // ********************************************************************************************
023    // Public & Final Fields
024    // ********************************************************************************************
025    // ********************************************************************************************
026
027
028    /**
029     * The actual character that comprises this Punxtuation-Mark Token.  Because Class
030     * {@code Punct} only allows singleton instances, therefore there is a limited number of 
031     * characters to which this field may be assigned.
032     * 
033     * <BR /><BR />The nine singleton instances of Class {@code Punct} are built for the following
034     * nine punctuation characters: <B>{@code ':' ';' ',' '[' ']' '(' ')' '{' '}'}</B>
035     */
036    public final char c;
037
038
039    // ********************************************************************************************
040    // ********************************************************************************************
041    // Private Constructor, API "is" and "if" Methods
042    // ********************************************************************************************
043    // ********************************************************************************************
044
045
046    private Punct(char c)
047    {
048        super("" + c);
049        this.c = c;
050    }
051
052    @Override
053    public final boolean isPunct() { return true; }
054
055    @Override
056    public final Punct ifPunct() { return this; }
057
058
059    // ********************************************************************************************
060    // ********************************************************************************************
061    // Singleton Stuff
062    // ********************************************************************************************
063    // ********************************************************************************************
064
065
066    static final Punct COLON            = new Punct(':');
067    static final Punct SEMICOLON        = new Punct(';');
068    static final Punct COMMA            = new Punct(',');
069
070    static final Punct LEFT_BRACKET     = new Punct('[');
071    static final Punct RIGHT_BRACKET    = new Punct(']');
072
073    static final Punct LEFT_PAREN       = new Punct('(');
074    static final Punct RIGHT_PAREN      = new Punct(')');
075
076    static final Punct LEFT_SQUIGGLY    = new Punct('{');
077    static final Punct RIGHT_SQUIGGLY   = new Punct('}');
078
079
080    /**
081     * Retrieve the singleton instance of a particular CSS Character.
082     * 
083     * @param c Any Java {@code 'char'} primitive, but only the following characters will generate
084     * a non-null result from this method: {@code ':', ';', ',', '[', ']', '(', ')', '{', '}' }.
085     * 
086     * @return The singleton instance of {@code Punct} corresponding to {@code 'c'}.  If 
087     * {@code 'c'} doesn't have any corresponding {@code Punct} Singleton-Instance, then null is
088     * returned.
089     */
090    public static final Punct get(char c)
091    {
092        switch (c)
093        {
094            case ':': return COLON;
095            case ';': return SEMICOLON;
096            case ',': return COMMA;
097
098            case '{': return LEFT_SQUIGGLY;
099            case '}': return RIGHT_SQUIGGLY;
100
101            case '(': return LEFT_PAREN;
102            case ')': return RIGHT_PAREN;
103
104            case '[': return LEFT_BRACKET;
105            case ']': return RIGHT_BRACKET;
106
107            default: return null;
108        }
109    }
110}