⚡ Sangsakala Proxy 🏠 Home
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2242fe4
implemented Value API
frsyuki Jun 10, 2015
7685276
added org.msgpack.value.Variable
frsyuki Jun 10, 2015
3393110
implemented Variable.hashCode, equals, toString, and writeTo methods
frsyuki Jun 10, 2015
a40cbcb
fixed Value API
frsyuki Jun 10, 2015
2ff4f59
ImmutableMapValueImpl.equals should not assume order of elements is same
frsyuki Jun 10, 2015
e2fc4e6
Renmae ExtendedType -> ExtensionType
xerial Jun 13, 2015
bc7e503
ValueFactory.newXXXValue -> newXXX for brevity
xerial Jun 13, 2015
b123089
immutableValue() -> toImmutable()
xerial Jun 13, 2015
4bcfab5
Add visitor interface
xerial Jun 13, 2015
de6d1f5
Add augumented constructor for ExtensionTypeHeader
xerial Jun 13, 2015
04819a3
Fix test case
xerial Jun 13, 2015
d1807a5
Add ValueType bit mask to improve type check performance
xerial Jun 13, 2015
770f013
Preserve float and double differences
xerial Jun 13, 2015
775379d
Renamed xxxValue that returns primitive type value as toXXX
xerial Jun 13, 2015
301ae10
Remove public scope from interface
xerial Jun 13, 2015
9db3537
Fix compilation error of msgpack-jackson
xerial Jun 13, 2015
c782451
toImmutable -> immutableValue
xerial Jun 15, 2015
ed45331
Remove visitor, ExtensionTypeHeader constructor. Fix exception type o…
xerial Jun 15, 2015
787533c
Remove ValueFactory.newArrayOf
xerial Jun 15, 2015
53557e9
Removed ValueType.bitMask
xerial Jun 15, 2015
9e8c806
Fix test compile error
xerial Jun 15, 2015
33f9ccf
Changed the extension type interface to use byte
xerial Jun 15, 2015
3df8f36
FloatHolder test is no longer necesary
xerial Jun 15, 2015
5289289
Remove RawValue
xerial Jun 15, 2015
4cba605
Fix test case that checks nil value
xerial Jun 15, 2015
c14c87c
Fix test cases and range check of extension types
xerial Jun 15, 2015
f6f9e8f
Fixes test case to use getString to extract raw string value
xerial Jun 15, 2015
e1b8105
Removed obsolete classes
xerial Jun 15, 2015
1d1da11
Moved example codes to test folder
xerial Jun 15, 2015
005edf4
Map.Entry based builder. Add putAll methods
xerial Jun 16, 2015
bef3c55
nil() -> newNil() for method name consisitency
xerial Jun 16, 2015
ca2fb1e
Add comment to ExtensionTypeHeader
xerial Jun 16, 2015
5ba7366
Fix unit test errors
komamitsu Jun 18, 2015
080deb3
Merge pull request #1 from komamitsu/v07-value-impl-rev2-fix-jackson-…
xerial Jun 18, 2015
5ac35d1
Merge pull request #249 from xerial/v07-value-impl-rev2
xerial Jun 19, 2015
b7787d4
removed unnecessary empty lines
frsyuki Jun 23, 2015
27be4d9
removed unused ValueType.toTypeName()
frsyuki Jun 23, 2015
321d64b
added example javadoc on ExtensionTypeHeader constructor
frsyuki Jun 23, 2015
5c51b39
toXXX -> castAsXXX
xerial Jun 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
toXXX -> castAsXXX
  • Loading branch information
xerial committed Jun 23, 2015
commit 5c51b39d00ae234aca3eeb9bc348add49efa8969
32 changes: 17 additions & 15 deletions msgpack-core/src/main/java/org/msgpack/value/NumberValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,47 @@
import java.math.BigInteger;

/**
* The interface {@code NumberValue} is the interface of {@code IntegerValue} and {@code FloatValue}.
* The base interface {@code NumberValue} of {@code IntegerValue} and {@code FloatValue}.
*
* @see org.msgpack.value.IntegerValue
* @see org.msgpack.value.FloatValue
*/
public interface NumberValue extends Value {

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

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

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

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

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

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

/**
* Converts this value into a 64-bit double
* Represent this value as a 64-bit double value, which may involve rounding or truncation of the original value.
*/
double toDouble();
double castAsDouble();
}
18 changes: 9 additions & 9 deletions msgpack-core/src/main/java/org/msgpack/value/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,39 +303,39 @@ public NumberValue asNumberValue() {
}

@Override
public byte toByte() {
public byte castAsByte() {
if (type == Type.BIG_INTEGER) {
return ((BigInteger) objectValue).byteValue();
}
return (byte) longValue;
}

@Override
public short toShort() {
public short castAsShort() {
if (type == Type.BIG_INTEGER) {
return ((BigInteger) objectValue).shortValue();
}
return (short) longValue;
}

@Override
public int toInt() {
public int castAsInt() {
if (type == Type.BIG_INTEGER) {
return ((BigInteger) objectValue).intValue();
}
return (int) longValue;
}

@Override
public long toLong() {
public long castAsLong() {
if (type == Type.BIG_INTEGER) {
return ((BigInteger) objectValue).longValue();
}
return (long) longValue;
}

@Override
public BigInteger toBigInteger() {
public BigInteger castAsBigInteger() {
if (type == Type.BIG_INTEGER) {
return (BigInteger) objectValue;
}
Expand All @@ -346,7 +346,7 @@ else if (type == Type.DOUBLE) {
}

@Override
public float toFloat() {
public float castAsFloat() {
if (type == Type.BIG_INTEGER) {
return ((BigInteger) objectValue).floatValue();
}
Expand All @@ -357,7 +357,7 @@ else if (type == Type.DOUBLE) {
}

@Override
public double toDouble() {
public double castAsDouble() {
if (type == Type.BIG_INTEGER) {
return ((BigInteger) objectValue).doubleValue();
}
Expand Down Expand Up @@ -504,14 +504,14 @@ public Variable setFloatValue(double v) {
this.type = Type.DOUBLE;
this.accessor = floatAccessor;
this.doubleValue = v;
this.longValue = (long) v; // AbstractNumberValueAccessor uses toLong
this.longValue = (long) v; // AbstractNumberValueAccessor uses castAsLong
return this;
}

public Variable setFloatValue(float v) {
this.type = Type.DOUBLE;
this.accessor = floatAccessor;
this.longValue = (long) v; // AbstractNumberValueAccessor uses toLong
this.longValue = (long) v; // AbstractNumberValueAccessor uses castAsLong
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,37 @@ public ImmutableIntegerValue asIntegerValue() {
}

@Override
public byte toByte() {
public byte castAsByte() {
return value.byteValue();
}

@Override
public short toShort() {
public short castAsShort() {
return value.shortValue();
}

@Override
public int toInt() {
public int castAsInt() {
return value.intValue();
}

@Override
public long toLong() {
public long castAsLong() {
return value.longValue();
}

@Override
public BigInteger toBigInteger() {
public BigInteger castAsBigInteger() {
return value;
}

@Override
public float toFloat() {
public float castAsFloat() {
return value.floatValue();
}

@Override
public double toDouble() {
public double castAsDouble() {
return value.doubleValue();
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public boolean equals(Object o) {
return false;
}
IntegerValue iv = v.asIntegerValue();
return value.equals(iv.toBigInteger());
return value.equals(iv.castAsBigInteger());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,37 @@ public ImmutableDoubleValueImpl immutableValue() {
}

@Override
public byte toByte() {
public byte castAsByte() {
return (byte) value;
}

@Override
public short toShort() {
public short castAsShort() {
return (short) value;
}

@Override
public int toInt() {
public int castAsInt() {
return (int) value;
}

@Override
public long toLong() {
public long castAsLong() {
return (long) value;
}

@Override
public BigInteger toBigInteger() {
public BigInteger castAsBigInteger() {
return new BigDecimal(value).toBigInteger();
}

@Override
public float toFloat() {
public float castAsFloat() {
return (float) value;
}

@Override
public double toDouble() {
public double castAsDouble() {
return value;
}

Expand All @@ -100,7 +100,7 @@ public boolean equals(Object o) {
if(!v.isFloatValue()) {
return false;
}
return value == v.asFloatValue().toDouble();
return value == v.asFloatValue().castAsDouble();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,37 @@ public ImmutableIntegerValue asIntegerValue() {
}

@Override
public byte toByte() {
public byte castAsByte() {
return (byte) value;
}

@Override
public short toShort() {
public short castAsShort() {
return (short) value;
}

@Override
public int toInt() {
public int castAsInt() {
return (int) value;
}

@Override
public long toLong() {
public long castAsLong() {
return value;
}

@Override
public BigInteger toBigInteger() {
public BigInteger castAsBigInteger() {
return BigInteger.valueOf(value);
}

@Override
public float toFloat() {
public float castAsFloat() {
return (float) value;
}

@Override
public double toDouble() {
public double castAsDouble() {
return (double) value;
}

Expand Down Expand Up @@ -173,7 +173,7 @@ public boolean equals(Object o) {
if (!iv.isInLongRange()) {
return false;
}
return value == iv.toLong();
return value == iv.castAsLong();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,22 @@ public static void readAndWriteFile() throws IOException {
case INTEGER:
IntegerValue iv = v.asIntegerValue();
if(iv.isInIntRange()) {
int i = iv.toInt();
int i = iv.castAsInt();
System.out.println("read int: " + i);
}
else if (iv.isInLongRange()) {
long l = iv.toLong();
long l = iv.castAsLong();
System.out.println("read long: " + l);
}
else {
BigInteger i = iv.toBigInteger();
BigInteger i = iv.castAsBigInteger();
System.out.println("read long: " + i);
}
break;
case FLOAT:
FloatValue fv = v.asFloatValue();
float f = fv.toFloat(); // use as float
double d = fv.toDouble(); // use as double
float f = fv.castAsFloat(); // use as float
double d = fv.castAsDouble(); // use as double
System.out.println("read float: " + d);
break;
case STRING:
Expand Down
Loading