forked from NASAWorldWind/WorldWindJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonToken.java
More file actions
160 lines (139 loc) · 4.67 KB
/
JsonToken.java
File metadata and controls
160 lines (139 loc) · 4.67 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package org.codehaus.jackson;
/**
* Enumeration for basic token types used for returning results
* of parsing JSON content.
*/
public enum JsonToken
{
/* Some notes on implementation:
*
* - Entries are to be ordered such that start/end array/object
* markers come first, then field name marker (if any), and
* finally scalar value tokens. This is assumed by some
* typing checks.
*/
/**
* NOT_AVAILABLE can be returned if {@link JsonParser}
* implementation can not currently return the requested
* token (usually next one), or even if any will be
* available, but that may be able to determine this in
* future. This is the case with non-blocking parsers --
* they can not block to wait for more data to parse and
* must return something.
*
* @since 0.9.7
*/
NOT_AVAILABLE(null),
/**
* START_OBJECT is returned when encountering '{'
* which signals starting of an Object value.
*/
START_OBJECT("{"),
/**
* START_OBJECT is returned when encountering '}'
* which signals ending of an Object value
*/
END_OBJECT("}"),
/**
* START_OBJECT is returned when encountering '['
* which signals starting of an Array value
*/
START_ARRAY("["),
/**
* START_OBJECT is returned when encountering ']'
* which signals ending of an Array value
*/
END_ARRAY("]"),
/**
* FIELD_NAME is returned when a String token is encountered
* as a field name (same lexical value, different function)
*/
FIELD_NAME(null),
/**
* Placeholder token returned when the input source has a concept
* of embedded Object that are not accessible as usual structure
* (of starting with {@link #START_OBJECT}, having values, ending with
* {@link #END_OBJECT}), but as "raw" objects.
*<p>
* Note: this token is never returned by regular JSON readers, but
* only by readers that expose other kinds of source (like
* {@link JsonNode}-based JSON trees, Maps, Lists and such).
*
* @since 1.1
*/
VALUE_EMBEDDED_OBJECT(null),
/**
* VALUE_STRING is returned when a String token is encountered
* in value context (array element, field value, or root-level
* stand-alone value)
*/
VALUE_STRING(null),
/**
* VALUE_NUMBER_INT is returned when an integer numeric token is
* encountered in value context: that is, a number that does
* not have floating point or exponent marker in it (consists
* only of an optional sign, followed by one or more digits)
*/
VALUE_NUMBER_INT(null),
/**
* VALUE_NUMBER_INT is returned when a numeric token other
* that is not an integer is encountered: that is, a number that does
* have floating point or exponent marker in it, in addition
* to one or more digits.
*/
VALUE_NUMBER_FLOAT(null),
/**
* VALUE_TRUE is returned when encountering literal "true" in
* value context
*/
VALUE_TRUE("true"),
/**
* VALUE_FALSE is returned when encountering literal "false" in
* value context
*/
VALUE_FALSE("false"),
/**
* VALUE_NULL is returned when encountering literal "null" in
* value context
*/
VALUE_NULL("null")
;
final String _serialized;
final char[] _serializedChars;
final byte[] _serializedBytes;
/**
* @param Textual representation for this token, if there is a
* single static representation; null otherwise
*/
JsonToken(String token)
{
if (token == null) {
_serialized = null;
_serializedChars = null;
_serializedBytes = null;
} else {
_serialized = token;
_serializedChars = token.toCharArray();
// It's all in ascii, can just case...
int len = _serializedChars.length;
_serializedBytes = new byte[len];
for (int i = 0; i < len; ++i) {
_serializedBytes[i] = (byte) _serializedChars[i];
}
}
}
public String asString() { return _serialized; }
public char[] asCharArray() { return _serializedChars; }
public byte[] asByteArray() { return _serializedBytes; }
public boolean isNumeric() {
return (this == VALUE_NUMBER_INT) || (this == VALUE_NUMBER_FLOAT);
}
/**
* Method that can be used to check whether this token represents
* a valid non-structured value. This means all tokens other than
* Object/Array start/end markers all field names.
*/
public boolean isScalarValue() {
return ordinal() >= VALUE_STRING.ordinal();
}
}