01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of 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,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.json;
17:
18: /**
19: * The Json version of a String
20: * @author Joe Walker [joe at getahead dot ltd dot uk]
21: */
22: public class JsonNumber extends JsonValue {
23: /**
24: * All JsonStrings wrap a Java string
25: */
26: public JsonNumber(int value) {
27: this .value = value;
28: }
29:
30: /**
31: * All JsonStrings wrap a Java string
32: */
33: public JsonNumber(long value) {
34: this .value = value;
35: }
36:
37: /**
38: * All JsonStrings wrap a Java string
39: */
40: public JsonNumber(double value) {
41: this .value = value;
42: }
43:
44: /* (non-Javadoc)
45: * @see org.directwebremoting.json.JsonValue#getDouble()
46: */
47: @Override
48: public double getDouble() {
49: return value;
50: }
51:
52: /* (non-Javadoc)
53: * @see org.directwebremoting.json.JsonValue#getLong()
54: */
55: @Override
56: public long getLong() {
57: return (long) value;
58: }
59:
60: /* (non-Javadoc)
61: * @see org.directwebremoting.json.JsonValue#getInteger()
62: */
63: @Override
64: public int getInteger() {
65: return (int) value;
66: }
67:
68: /* (non-Javadoc)
69: * @see org.directwebremoting.json.JsonValue#toExternalRepresentation()
70: */
71: @Override
72: public String toExternalRepresentation() {
73: return Double.toString(value);
74: }
75:
76: /* (non-Javadoc)
77: * @see java.lang.Object#toString()
78: */
79: @Override
80: public String toString() {
81: return toExternalRepresentation();
82: }
83:
84: /**
85: * The string value that we wrap
86: */
87: private final double value;
88: }
|