KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > conditional > Token


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.conditional;
16
17 import org.apache.hivemind.util.Defense;
18
19 /**
20  * A token recognized from a conditional expression.
21  *
22  * @author Howard M. Lewis Ship
23  * @since 1.1
24  */

25 class Token
26 {
27     private TokenType _type;
28
29     private String JavaDoc _value;
30
31     Token(TokenType type)
32     {
33         this(type, null);
34     }
35
36     /**
37      * @param type
38      * a specific token type (may not be null)
39      * @param value
40      * the value for this token
41      */

42
43     Token(TokenType type, String JavaDoc value)
44     {
45         Defense.notNull(type, "type");
46
47         _type = type;
48         _value = value;
49     }
50
51     public TokenType getType()
52     {
53         return _type;
54     }
55
56     /**
57      * Returns the specific value for this token, generally only meaningful for the
58      * {@link org.apache.hivemind.conditional.TokenType#SYMBOL} type.
59      */

60
61     public String JavaDoc getValue()
62     {
63         return _value;
64     }
65
66     /**
67      * Returns either <TYPE> or <TYPE(VALUE)>, where TYPE is the TokenType and VALUE is
68      * the value (if non null).
69      */

70
71     public String JavaDoc toString()
72     {
73         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("<");
74
75         buffer.append(_type);
76
77         if (_value != null)
78         {
79             buffer.append("(");
80             buffer.append(_value);
81             buffer.append(")");
82         }
83
84         buffer.append(">");
85
86         return buffer.toString();
87     }
88 }
Popular Tags