1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.johnzon.core; |
20 | |
|
21 | |
import javax.json.JsonString; |
22 | |
|
23 | |
final class JsonStringImpl implements JsonString { |
24 | |
private final String value; |
25 | |
private String escape; |
26 | 22608 | private Integer hashCode = null; |
27 | |
|
28 | |
|
29 | 22608 | JsonStringImpl(final String value) { |
30 | 22608 | if(value == null) { |
31 | 1 | throw new NullPointerException("value must not be null"); |
32 | |
} |
33 | |
|
34 | 22607 | this.value = value; |
35 | 22607 | } |
36 | |
|
37 | |
@Override |
38 | |
public String getString() { |
39 | 81 | return value; |
40 | |
} |
41 | |
|
42 | |
@Override |
43 | |
public CharSequence getChars() { |
44 | 0 | return value; |
45 | |
} |
46 | |
|
47 | |
@Override |
48 | |
public ValueType getValueType() { |
49 | 7 | return ValueType.STRING; |
50 | |
} |
51 | |
|
52 | |
@Override |
53 | |
public String toString() { |
54 | 12 | String s = escape; |
55 | 12 | if (s == null) { |
56 | 12 | s = JsonChars.QUOTE_CHAR+Strings.escape(value)+JsonChars.QUOTE_CHAR; |
57 | 12 | escape=s; |
58 | |
} |
59 | 12 | return s; |
60 | |
} |
61 | |
|
62 | |
@Override |
63 | |
public int hashCode() { |
64 | 0 | Integer h = hashCode; |
65 | 0 | if (h == null) { |
66 | 0 | h = value.hashCode(); |
67 | 0 | hashCode=h; |
68 | |
} |
69 | 0 | return h; |
70 | |
} |
71 | |
|
72 | |
@Override |
73 | |
public boolean equals(final Object obj) { |
74 | 0 | return JsonString.class.isInstance(obj) && JsonString.class.cast(obj).getString().equals(value); |
75 | |
} |
76 | |
} |