01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.json.client;
17:
18: /**
19: * Represents a JSON boolean value.
20: */
21: public class JSONBoolean extends JSONValue {
22:
23: private static final JSONBoolean FALSE = new JSONBoolean(false);
24: private static final JSONBoolean TRUE = new JSONBoolean(true);
25:
26: /**
27: * Gets a reference to the singleton instance representing either
28: * <code>true</code> or <code>false</code>.
29: *
30: * @param b controls which value to get
31: * @return if <code>true</code>, the JSONBoolean instance representing
32: * <code>true</code> is returned; otherwise, the JSONBoolean
33: * instance representing <code>false</code> is returned
34: */
35: public static JSONBoolean getInstance(boolean b) {
36: if (b) {
37: return TRUE;
38: } else {
39: return FALSE;
40: }
41: }
42:
43: private final boolean value;
44:
45: /*
46: * This private constructor is used to build true and false.
47: */
48: private JSONBoolean(boolean value) {
49: this .value = value;
50: }
51:
52: /**
53: * Returns <code>true</code> if this is the instance representing "true",
54: * <code>false</code> otherwise.
55: */
56: public boolean booleanValue() {
57: return value;
58: }
59:
60: /**
61: * Returns <code>this</code>, as this is a JSONBoolean.
62: */
63: @Override
64: public JSONBoolean isBoolean() {
65: return this ;
66: }
67:
68: /**
69: * Returns "true" for the true value, and "false" for the false value.
70: */
71: @Override
72: public String toString() {
73: return Boolean.toString(value);
74: }
75: }
|