Skip to content

Commit 775379d

Browse files
committed
Renamed xxxValue that returns primitive type value as toXXX
1 parent 770f013 commit 775379d

File tree

8 files changed

+67
-71
lines changed

8 files changed

+67
-71
lines changed

msgpack-core/src/main/java/org/msgpack/core/example/MessagePackExample.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,22 @@ public static void readAndWriteFile() throws IOException {
184184
case INTEGER:
185185
IntegerValue iv = v.asIntegerValue();
186186
if(iv.isInIntRange()) {
187-
int i = iv.intValue();
187+
int i = iv.toInt();
188188
System.out.println("read int: " + i);
189189
}
190190
else if (iv.isInLongRange()) {
191-
long l = iv.longValue();
191+
long l = iv.toLong();
192192
System.out.println("read long: " + l);
193193
}
194194
else {
195-
BigInteger i = iv.bigIntegerValue();
195+
BigInteger i = iv.toBigInteger();
196196
System.out.println("read long: " + i);
197197
}
198198
break;
199199
case FLOAT:
200200
FloatValue fv = v.asFloatValue();
201-
float f = fv.floatValue(); // use as float
202-
double d = fv.doubleValue(); // use as double
201+
float f = fv.toFloat(); // use as float
202+
double d = fv.toDouble(); // use as double
203203
System.out.println("read float: " + d);
204204
break;
205205
case STRING:

msgpack-core/src/main/java/org/msgpack/value/NumberValue.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,43 @@
2020
/**
2121
* The interface {@code NumberValue} is the interface of {@code IntegerValue} and {@code FloatValue}.
2222
*
23-
* @see org.msgpack.value.IntegerValue
24-
* @see org.msgpack.value.FloatValue
23+
* @see org.msgpack.value.IntegerValue
24+
* @see org.msgpack.value.FloatValue
2525
*/
2626
public interface NumberValue extends Value {
27-
@Override
28-
public ImmutableNumberValue toImmutable();
2927

3028
/**
31-
* Returns the value as a {@code byte}, which may involve rounding or truncation.
29+
* Convert this value into a byte value. If this value is not within the range of Byte value, it will truncate or round the value.
3230
*/
33-
public byte byteValue();
31+
byte toByte();
3432

3533
/**
36-
* Returns the value as a {@code short}, which may involve rounding or truncation.
34+
* Convert this value into a short value. If this value is not within the range of Short value, it will truncate or round the value.
3735
*/
38-
public short shortValue();
36+
short toShort();
3937

4038
/**
41-
* Returns the value as an {@code int}, which may involve rounding or truncation.
39+
* Convert this value into an int value. If this value is not within the range of Int value, it will truncate or round the value.
4240
*/
43-
public int intValue();
41+
int toInt();
4442

4543
/**
46-
* Returns the value as a {@code long}, which may involve rounding or truncation.
44+
* Convert this value into a long value. If this value is not within the range of Long value, it will truncate or round the value.
4745
*/
48-
public long longValue();
46+
long toLong();
4947

5048
/**
51-
* Returns the value as a {@code BigInteger}, which may involve rounding or truncation.
52-
*
53-
* Rounding could happen if type of this value is float or double.
49+
* Convert this value into a BigInteger. If value is Float type, it will round the value
5450
*/
55-
public BigInteger bigIntegerValue();
51+
BigInteger toBigInteger();
5652

5753
/**
58-
* Returns the value as a {@code float}, which may involve rounding or truncation.
54+
* Converts this value into a 32-bit float
5955
*/
60-
public float floatValue();
56+
float toFloat();
6157

6258
/**
63-
* Returns the value as a {@code double}, which may involve rounding or truncation.
59+
* Converts this value into a 64-bit double
6460
*/
65-
public double doubleValue();
61+
double toDouble();
6662
}

msgpack-core/src/main/java/org/msgpack/value/Value.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface Value {
3030
* <p/>
3131
* Note that you can't use <code>instanceof</code> to check type of a value because type of a mutable value is variable.
3232
*/
33-
public ValueType getValueType();
33+
ValueType getValueType();
3434

3535
/**
3636
* Returns immutable copy of this value.

msgpack-core/src/main/java/org/msgpack/value/Variable.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,39 +313,39 @@ public NumberValue asNumberValue() {
313313
}
314314

315315
@Override
316-
public byte byteValue() {
316+
public byte toByte() {
317317
if (type == Type.BIG_INTEGER) {
318318
return ((BigInteger) objectValue).byteValue();
319319
}
320320
return (byte) longValue;
321321
}
322322

323323
@Override
324-
public short shortValue() {
324+
public short toShort() {
325325
if (type == Type.BIG_INTEGER) {
326326
return ((BigInteger) objectValue).shortValue();
327327
}
328328
return (short) longValue;
329329
}
330330

331331
@Override
332-
public int intValue() {
332+
public int toInt() {
333333
if (type == Type.BIG_INTEGER) {
334334
return ((BigInteger) objectValue).intValue();
335335
}
336336
return (int) longValue;
337337
}
338338

339339
@Override
340-
public long longValue() {
340+
public long toLong() {
341341
if (type == Type.BIG_INTEGER) {
342342
return ((BigInteger) objectValue).longValue();
343343
}
344344
return (long) longValue;
345345
}
346346

347347
@Override
348-
public BigInteger bigIntegerValue() {
348+
public BigInteger toBigInteger() {
349349
if (type == Type.BIG_INTEGER) {
350350
return (BigInteger) objectValue;
351351
}
@@ -356,7 +356,7 @@ else if (type == Type.DOUBLE) {
356356
}
357357

358358
@Override
359-
public float floatValue() {
359+
public float toFloat() {
360360
if (type == Type.BIG_INTEGER) {
361361
return ((BigInteger) objectValue).floatValue();
362362
}
@@ -367,7 +367,7 @@ else if (type == Type.DOUBLE) {
367367
}
368368

369369
@Override
370-
public double doubleValue() {
370+
public double toDouble() {
371371
if (type == Type.BIG_INTEGER) {
372372
return ((BigInteger) objectValue).doubleValue();
373373
}
@@ -517,14 +517,14 @@ public Variable setFloatValue(double v) {
517517
this.type = Type.DOUBLE;
518518
this.accessor = floatAccessor;
519519
this.doubleValue = v;
520-
this.longValue = (long) v; // AbstractNumberValueAccessor uses longValue
520+
this.longValue = (long) v; // AbstractNumberValueAccessor uses toLong
521521
return this;
522522
}
523523

524524
public Variable setFloatValue(float v) {
525525
this.type = Type.DOUBLE;
526526
this.accessor = floatAccessor;
527-
this.longValue = (long) v; // AbstractNumberValueAccessor uses longValue
527+
this.longValue = (long) v; // AbstractNumberValueAccessor uses toLong
528528
return this;
529529
}
530530

msgpack-core/src/main/java/org/msgpack/value/impl/ImmutableBigIntegerValueImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,37 @@ public ImmutableIntegerValue asIntegerValue() {
6565
}
6666

6767
@Override
68-
public byte byteValue() {
68+
public byte toByte() {
6969
return value.byteValue();
7070
}
7171

7272
@Override
73-
public short shortValue() {
73+
public short toShort() {
7474
return value.shortValue();
7575
}
7676

7777
@Override
78-
public int intValue() {
78+
public int toInt() {
7979
return value.intValue();
8080
}
8181

8282
@Override
83-
public long longValue() {
83+
public long toLong() {
8484
return value.longValue();
8585
}
8686

8787
@Override
88-
public BigInteger bigIntegerValue() {
88+
public BigInteger toBigInteger() {
8989
return value;
9090
}
9191

9292
@Override
93-
public float floatValue() {
93+
public float toFloat() {
9494
return value.floatValue();
9595
}
9696

9797
@Override
98-
public double doubleValue() {
98+
public double toDouble() {
9999
return value.doubleValue();
100100
}
101101

@@ -180,7 +180,7 @@ public boolean equals(Object o) {
180180
return false;
181181
}
182182
IntegerValue iv = v.asIntegerValue();
183-
return value.equals(iv.bigIntegerValue());
183+
return value.equals(iv.toBigInteger());
184184
}
185185

186186
@Override

msgpack-core/src/main/java/org/msgpack/value/impl/ImmutableDoubleValueImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,37 @@ public ImmutableDoubleValueImpl toImmutable() {
4646
}
4747

4848
@Override
49-
public byte byteValue() {
49+
public byte toByte() {
5050
return (byte) value;
5151
}
5252

5353
@Override
54-
public short shortValue() {
54+
public short toShort() {
5555
return (short) value;
5656
}
5757

5858
@Override
59-
public int intValue() {
59+
public int toInt() {
6060
return (int) value;
6161
}
6262

6363
@Override
64-
public long longValue() {
64+
public long toLong() {
6565
return (long) value;
6666
}
6767

6868
@Override
69-
public BigInteger bigIntegerValue() {
69+
public BigInteger toBigInteger() {
7070
return new BigDecimal(value).toBigInteger();
7171
}
7272

7373
@Override
74-
public float floatValue() {
74+
public float toFloat() {
7575
return (float) value;
7676
}
7777

7878
@Override
79-
public double doubleValue() {
79+
public double toDouble() {
8080
return value;
8181
}
8282

@@ -103,7 +103,7 @@ public boolean equals(Object o) {
103103
if (!v.isFloatValue()) {
104104
return false;
105105
}
106-
return value == v.asFloatValue().doubleValue();
106+
return value == v.asFloatValue().toDouble();
107107
}
108108

109109
@Override

msgpack-core/src/main/java/org/msgpack/value/impl/ImmutableLongValueImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,37 @@ public ImmutableIntegerValue asIntegerValue() {
6363
}
6464

6565
@Override
66-
public byte byteValue() {
66+
public byte toByte() {
6767
return (byte) value;
6868
}
6969

7070
@Override
71-
public short shortValue() {
71+
public short toShort() {
7272
return (short) value;
7373
}
7474

7575
@Override
76-
public int intValue() {
76+
public int toInt() {
7777
return (int) value;
7878
}
7979

8080
@Override
81-
public long longValue() {
81+
public long toLong() {
8282
return value;
8383
}
8484

8585
@Override
86-
public BigInteger bigIntegerValue() {
86+
public BigInteger toBigInteger() {
8787
return BigInteger.valueOf(value);
8888
}
8989

9090
@Override
91-
public float floatValue() {
91+
public float toFloat() {
9292
return (float) value;
9393
}
9494

9595
@Override
96-
public double doubleValue() {
96+
public double toDouble() {
9797
return (double) value;
9898
}
9999

@@ -178,7 +178,7 @@ public boolean equals(Object o) {
178178
if (!iv.isInLongRange()) {
179179
return false;
180180
}
181-
return value == iv.longValue();
181+
return value == iv.toLong();
182182
}
183183

184184
@Override

0 commit comments

Comments
 (0)