1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package Torello.CSS;

import java.util.Vector;

// <colon-token>, <semicolon-token>, <comma-token>,
// <[-token>, <]-token>, <(-token>, <)-token>, <{-token>, and <}-token>.

/**
 * A class for saving one of nine different Punctuation-Token classes.
 * The nine-available singleton-instances include: 
 * <B STYLE='color: red;'>{@code ':', ';', ',', '[', ']', '(', ')', '{', '}'}</B>
 */
@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="CSS_TOK")
public final class Punct extends CSSToken
    implements CharSequence, java.io.Serializable, Comparable<CharSequence>
{
    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
    protected static final long serialVersionUID = 1;


    // ********************************************************************************************
    // ********************************************************************************************
    // Public & Final Fields
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * The actual character that comprises this Punxtuation-Mark Token.  Because Class
     * {@code Punct} only allows singleton instances, therefore there is a limited number of 
     * characters to which this field may be assigned.
     * 
     * <BR /><BR />The nine singleton instances of Class {@code Punct} are built for the following
     * nine punctuation characters: <B>{@code ':' ';' ',' '[' ']' '(' ')' '{' '}'}</B>
     */
    public final char c;


    // ********************************************************************************************
    // ********************************************************************************************
    // Private Constructor, API "is" and "if" Methods
    // ********************************************************************************************
    // ********************************************************************************************


    private Punct(char c)
    {
        super("" + c);
        this.c = c;
    }

    @Override
    public final boolean isPunct() { return true; }

    @Override
    public final Punct ifPunct() { return this; }


    // ********************************************************************************************
    // ********************************************************************************************
    // Singleton Stuff
    // ********************************************************************************************
    // ********************************************************************************************


    static final Punct COLON            = new Punct(':');
    static final Punct SEMICOLON        = new Punct(';');
    static final Punct COMMA            = new Punct(',');

    static final Punct LEFT_BRACKET     = new Punct('[');
    static final Punct RIGHT_BRACKET    = new Punct(']');

    static final Punct LEFT_PAREN       = new Punct('(');
    static final Punct RIGHT_PAREN      = new Punct(')');

    static final Punct LEFT_SQUIGGLY    = new Punct('{');
    static final Punct RIGHT_SQUIGGLY   = new Punct('}');


    /**
     * Retrieve the singleton instance of a particular CSS Character.
     * 
     * @param c Any Java {@code 'char'} primitive, but only the following characters will generate
     * a non-null result from this method: {@code ':', ';', ',', '[', ']', '(', ')', '{', '}' }.
     * 
     * @return The singleton instance of {@code Punct} corresponding to {@code 'c'}.  If 
     * {@code 'c'} doesn't have any corresponding {@code Punct} Singleton-Instance, then null is
     * returned.
     */
    public static final Punct get(char c)
    {
        switch (c)
        {
            case ':': return COLON;
            case ';': return SEMICOLON;
            case ',': return COMMA;

            case '{': return LEFT_SQUIGGLY;
            case '}': return RIGHT_SQUIGGLY;

            case '(': return LEFT_PAREN;
            case ')': return RIGHT_PAREN;

            case '[': return LEFT_BRACKET;
            case ']': return RIGHT_BRACKET;

            default: return null;
        }
    }
}