comparison src/main/java/org/msgpack/type/DoubleValueImpl.java @ 0:cb825acd883a

first commit
author sugi
date Sat, 18 Oct 2014 15:06:15 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cb825acd883a
1 //
2 // MessagePack for Java
3 //
4 // Copyright (C) 2009 - 2013 FURUHASHI Sadayuki
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 package org.msgpack.type;
19
20 import java.math.BigInteger;
21 import java.math.BigDecimal;
22 import java.io.IOException;
23 import org.msgpack.packer.Packer;
24
25 @SuppressWarnings("serial")
26 class DoubleValueImpl extends FloatValue {
27 private double value;
28
29 DoubleValueImpl(double value) {
30 this.value = value;
31 }
32
33 @Override
34 public float getFloat() {
35 return (float) value;
36 }
37
38 @Override
39 public double getDouble() {
40 return value;
41 }
42
43 @Override
44 public byte byteValue() {
45 return (byte) value;
46 }
47
48 @Override
49 public short shortValue() {
50 return (short) value;
51 }
52
53 @Override
54 public int intValue() {
55 return (int) value;
56 }
57
58 @Override
59 public long longValue() {
60 return (long) value;
61 }
62
63 @Override
64 public BigInteger bigIntegerValue() {
65 return new BigDecimal(value).toBigInteger();
66 }
67
68 @Override
69 public float floatValue() {
70 return (float) value;
71 }
72
73 @Override
74 public double doubleValue() {
75 return value;
76 }
77
78 @Override
79 public void writeTo(Packer pk) throws IOException {
80 pk.write(value);
81 }
82
83 @Override
84 public boolean equals(Object o) {
85 if (o == this) {
86 return true;
87 }
88 if (!(o instanceof Value)) {
89 return false;
90 }
91 Value v = (Value) o;
92 if (!v.isFloatValue()) {
93 return false;
94 }
95
96 return value == v.asFloatValue().getDouble();
97 }
98
99 // TODO compareTo
100
101 @Override
102 public int hashCode() {
103 long v = Double.doubleToLongBits(value);
104 return (int) (v ^ (v >>> 32));
105 }
106
107 @Override
108 public String toString() {
109 return Double.toString(value);
110 }
111
112 @Override
113 public StringBuilder toString(StringBuilder sb) {
114 return sb.append(Double.toString(value));
115 }
116 }