Skip to content

Commit 5c51b39

Browse files
committed
toXXX -> castAsXXX
1 parent 321d64b commit 5c51b39

File tree

7 files changed

+67
-65
lines changed

7 files changed

+67
-65
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,47 @@
1818
import java.math.BigInteger;
1919

2020
/**
21-
* The interface {@code NumberValue} is the interface of {@code IntegerValue} and {@code FloatValue}.
21+
* The base interface {@code NumberValue} of {@code IntegerValue} and {@code FloatValue}.
2222
*
2323
* @see org.msgpack.value.IntegerValue
2424
* @see org.msgpack.value.FloatValue
2525
*/
2626
public interface NumberValue extends Value {
2727

2828
/**
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.
29+
* Represent this value as a byte value, which may involve rounding or truncation of the original value.
30+
* the value.
3031
*/
31-
byte toByte();
32+
byte castAsByte();
3233

3334
/**
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.
35+
* Represent this value as a short value, which may involve rounding or truncation of the original value.
3536
*/
36-
short toShort();
37+
short castAsShort();
3738

3839
/**
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.
40+
* Represent this value as an int value, which may involve rounding or truncation of the original value.
41+
* value.
4042
*/
41-
int toInt();
43+
int castAsInt();
4244

4345
/**
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.
46+
* Represent this value as a long value, which may involve rounding or truncation of the original value.
4547
*/
46-
long toLong();
48+
long castAsLong();
4749

4850
/**
49-
* Convert this value into a BigInteger. If value is Float type, it will round the value
51+
* Represent this value as a BigInteger, which may involve rounding or truncation of the original value.
5052
*/
51-
BigInteger toBigInteger();
53+
BigInteger castAsBigInteger();
5254

5355
/**
54-
* Converts this value into a 32-bit float
56+
* Represent this value as a 32-bit float value, which may involve rounding or truncation of the original value.
5557
*/
56-
float toFloat();
58+
float castAsFloat();
5759

5860
/**
59-
* Converts this value into a 64-bit double
61+
* Represent this value as a 64-bit double value, which may involve rounding or truncation of the original value.
6062
*/
61-
double toDouble();
63+
double castAsDouble();
6264
}

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

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

305305
@Override
306-
public byte toByte() {
306+
public byte castAsByte() {
307307
if (type == Type.BIG_INTEGER) {
308308
return ((BigInteger) objectValue).byteValue();
309309
}
310310
return (byte) longValue;
311311
}
312312

313313
@Override
314-
public short toShort() {
314+
public short castAsShort() {
315315
if (type == Type.BIG_INTEGER) {
316316
return ((BigInteger) objectValue).shortValue();
317317
}
318318
return (short) longValue;
319319
}
320320

321321
@Override
322-
public int toInt() {
322+
public int castAsInt() {
323323
if (type == Type.BIG_INTEGER) {
324324
return ((BigInteger) objectValue).intValue();
325325
}
326326
return (int) longValue;
327327
}
328328

329329
@Override
330-
public long toLong() {
330+
public long castAsLong() {
331331
if (type == Type.BIG_INTEGER) {
332332
return ((BigInteger) objectValue).longValue();
333333
}
334334
return (long) longValue;
335335
}
336336

337337
@Override
338-
public BigInteger toBigInteger() {
338+
public BigInteger castAsBigInteger() {
339339
if (type == Type.BIG_INTEGER) {
340340
return (BigInteger) objectValue;
341341
}
@@ -346,7 +346,7 @@ else if (type == Type.DOUBLE) {
346346
}
347347

348348
@Override
349-
public float toFloat() {
349+
public float castAsFloat() {
350350
if (type == Type.BIG_INTEGER) {
351351
return ((BigInteger) objectValue).floatValue();
352352
}
@@ -357,7 +357,7 @@ else if (type == Type.DOUBLE) {
357357
}
358358

359359
@Override
360-
public double toDouble() {
360+
public double castAsDouble() {
361361
if (type == Type.BIG_INTEGER) {
362362
return ((BigInteger) objectValue).doubleValue();
363363
}
@@ -504,14 +504,14 @@ public Variable setFloatValue(double v) {
504504
this.type = Type.DOUBLE;
505505
this.accessor = floatAccessor;
506506
this.doubleValue = v;
507-
this.longValue = (long) v; // AbstractNumberValueAccessor uses toLong
507+
this.longValue = (long) v; // AbstractNumberValueAccessor uses castAsLong
508508
return this;
509509
}
510510

511511
public Variable setFloatValue(float v) {
512512
this.type = Type.DOUBLE;
513513
this.accessor = floatAccessor;
514-
this.longValue = (long) v; // AbstractNumberValueAccessor uses toLong
514+
this.longValue = (long) v; // AbstractNumberValueAccessor uses castAsLong
515515
return this;
516516
}
517517

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 toByte() {
68+
public byte castAsByte() {
6969
return value.byteValue();
7070
}
7171

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

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

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

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

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

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

@@ -175,7 +175,7 @@ public boolean equals(Object o) {
175175
return false;
176176
}
177177
IntegerValue iv = v.asIntegerValue();
178-
return value.equals(iv.toBigInteger());
178+
return value.equals(iv.castAsBigInteger());
179179
}
180180

181181
@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
@@ -48,37 +48,37 @@ public ImmutableDoubleValueImpl immutableValue() {
4848
}
4949

5050
@Override
51-
public byte toByte() {
51+
public byte castAsByte() {
5252
return (byte) value;
5353
}
5454

5555
@Override
56-
public short toShort() {
56+
public short castAsShort() {
5757
return (short) value;
5858
}
5959

6060
@Override
61-
public int toInt() {
61+
public int castAsInt() {
6262
return (int) value;
6363
}
6464

6565
@Override
66-
public long toLong() {
66+
public long castAsLong() {
6767
return (long) value;
6868
}
6969

7070
@Override
71-
public BigInteger toBigInteger() {
71+
public BigInteger castAsBigInteger() {
7272
return new BigDecimal(value).toBigInteger();
7373
}
7474

7575
@Override
76-
public float toFloat() {
76+
public float castAsFloat() {
7777
return (float) value;
7878
}
7979

8080
@Override
81-
public double toDouble() {
81+
public double castAsDouble() {
8282
return value;
8383
}
8484

@@ -100,7 +100,7 @@ public boolean equals(Object o) {
100100
if(!v.isFloatValue()) {
101101
return false;
102102
}
103-
return value == v.asFloatValue().toDouble();
103+
return value == v.asFloatValue().castAsDouble();
104104
}
105105

106106
@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 toByte() {
66+
public byte castAsByte() {
6767
return (byte) value;
6868
}
6969

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

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

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

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

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

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

@@ -173,7 +173,7 @@ public boolean equals(Object o) {
173173
if (!iv.isInLongRange()) {
174174
return false;
175175
}
176-
return value == iv.toLong();
176+
return value == iv.castAsLong();
177177
}
178178

179179
@Override

msgpack-core/src/test/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.toInt();
187+
int i = iv.castAsInt();
188188
System.out.println("read int: " + i);
189189
}
190190
else if (iv.isInLongRange()) {
191-
long l = iv.toLong();
191+
long l = iv.castAsLong();
192192
System.out.println("read long: " + l);
193193
}
194194
else {
195-
BigInteger i = iv.toBigInteger();
195+
BigInteger i = iv.castAsBigInteger();
196196
System.out.println("read long: " + i);
197197
}
198198
break;
199199
case FLOAT:
200200
FloatValue fv = v.asFloatValue();
201-
float f = fv.toFloat(); // use as float
202-
double d = fv.toDouble(); // use as double
201+
float f = fv.castAsFloat(); // use as float
202+
double d = fv.castAsDouble(); // use as double
203203
System.out.println("read float: " + d);
204204
break;
205205
case STRING:

0 commit comments

Comments
 (0)