KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > json > client > JSONBoolean


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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   public JSONBoolean isBoolean() {
64     return this;
65   }
66
67   /**
68    * Returns "true" for the true value, and "false" for the false value.
69    */

70   public String JavaDoc toString() {
71     return Boolean.toString(value);
72   }
73 }
74
Popular Tags