Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
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
Next Next commit
Remove visitor, ExtensionTypeHeader constructor. Fix exception type o…
…f integer overflow
  • Loading branch information
xerial committed Jun 15, 2015
commit ed45331e90eaf85947b60e19f3abb2c98dbe0cbb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ public class ExtensionTypeHeader {
private final int length;

public ExtensionTypeHeader(byte type, int length) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you add java doc here to suggest that users can use checkedCastToByte?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment

checkArgument(length >= 0, String.format("length must be >= 0: %,d", length));
checkArgument(length >= 0, "length must be >= 0");
this.type = type;
this.length = length;
}

public ExtensionTypeHeader(int type, int length) {
checkArgument(Byte.MIN_VALUE <= type && type <= Byte.MAX_VALUE, "Extension type must be within -128 to 127");
this.type = (byte) type;
this.length = length;
public static byte checkedCastToByte(int code) {
checkArgument(code < Byte.MIN_VALUE && code > Byte.MAX_VALUE, "Extension type code must be within the range of byte");
return (byte) code;
}

public byte getType() {
Expand Down
10 changes: 5 additions & 5 deletions msgpack-core/src/main/java/org/msgpack/value/IntegerValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.msgpack.value;

import java.math.BigInteger;
import org.msgpack.core.MessageOverflowException;
import org.msgpack.core.MessageIntegerOverflowException;

/**
* The interface {@code IntegerValue} represents MessagePack's Integer type.
Expand Down Expand Up @@ -47,31 +47,31 @@ public interface IntegerValue extends NumberValue {
/**
* Returns the value as a {@code byte}, otherwise throws an exception.
*
* @throws MessageOverflowException
* @throws MessageIntegerOverflowException
* If the value does not fit in the range of {@code byte} type.
*/
byte getByte();

/**
* Returns the value as a {@code short}, otherwise throws an exception.
*
* @throws MessageOverflowException
* @throws MessageIntegerOverflowException
* If the value does not fit in the range of {@code short} type.
*/
short getShort();

/**
* Returns the value as an {@code int}, otherwise throws an exception.
*
* @throws MessageOverflowException
* @throws MessageIntegerOverflowException
* If the value does not fit in the range of {@code int} type.
*/
int getInt();

/**
* Returns the value as a {@code long}, otherwise throws an exception.
*
* @throws MessageOverflowException
* @throws MessageIntegerOverflowException
* If the value does not fit in the range of {@code long} type.
*/
long getLong();
Expand Down
7 changes: 0 additions & 7 deletions msgpack-core/src/main/java/org/msgpack/value/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,6 @@ public interface Value {
*/
void writeTo(MessagePacker pk) throws IOException;


/**
* Accept a visitor to traverse this value
* @param visitor
*/
void accept(ValueVisitor visitor);

/**
* Compares this value to the specified object.
* <p/>
Expand Down
38 changes: 0 additions & 38 deletions msgpack-core/src/main/java/org/msgpack/value/ValueVisitor.java

This file was deleted.

48 changes: 0 additions & 48 deletions msgpack-core/src/main/java/org/msgpack/value/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ public ImmutableNilValue immutableValue() {
public void writeTo(MessagePacker pk) throws IOException {
pk.packNil();
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitNil();
}
}


Expand Down Expand Up @@ -283,11 +278,6 @@ public boolean getBoolean() {
public void writeTo(MessagePacker pk) throws IOException {
pk.packBoolean(longValue == 1L);
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitBoolean(this);
}
}


Expand Down Expand Up @@ -501,11 +491,6 @@ public void writeTo(MessagePacker pk) throws IOException {
pk.packLong(longValue);
}
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitInteger(this);
}
}


Expand Down Expand Up @@ -549,10 +534,6 @@ public void writeTo(MessagePacker pk) throws IOException {
pk.packDouble(doubleValue);
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitFloat(this);
}
}


Expand Down Expand Up @@ -639,10 +620,6 @@ public void writeTo(MessagePacker pk) throws IOException {
pk.writePayload(data);
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitBinary(this);
}
}


Expand Down Expand Up @@ -683,11 +660,6 @@ public void writeTo(MessagePacker pk) throws IOException {
pk.packRawStringHeader(data.length);
pk.writePayload(data);
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitString(this);
}
}


Expand Down Expand Up @@ -756,11 +728,6 @@ public void writeTo(MessagePacker pk) throws IOException {
e.writeTo(pk);
}
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitArray(this);
}
}

////
Expand Down Expand Up @@ -840,11 +807,6 @@ public void writeTo(MessagePacker pk) throws IOException {
pair.getValue().writeTo(pk);
}
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitMap(this);
}
}


Expand Down Expand Up @@ -888,11 +850,6 @@ public byte[] getData() {
public void writeTo(MessagePacker pk) throws IOException {
((ImmutableExtensionValue) objectValue).writeTo(pk);
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitExtension(((ImmutableExtensionValue) objectValue));
}
}


Expand All @@ -910,11 +867,6 @@ public void writeTo(MessagePacker pk) throws IOException {
accessor.writeTo(pk);
}

@Override
public void accept(ValueVisitor visitor) {
accessor.accept(visitor);
}

@Override
public int hashCode() {
return immutableValue().hashCode(); // TODO optimize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ public void writeTo(MessagePacker pk) throws IOException {
}
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitArray(this);
}

@Override
public boolean equals(Object o) {
if(o == this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ public void writeTo(MessagePacker pk) throws IOException {
pk.packBigInteger(value);
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitInteger(this);
}

@Override
public boolean equals(Object o) {
if (o == this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
package org.msgpack.value.impl;

import org.msgpack.core.MessagePacker;
import org.msgpack.value.ImmutableBinaryValue;
import org.msgpack.value.Value;
import org.msgpack.value.ValueType;
import org.msgpack.value.ImmutableBinaryValue;
import org.msgpack.value.ValueVisitor;

import java.util.Arrays;
import java.io.IOException;
import java.util.Arrays;


/**
* {@code ImmutableBinaryValueImpl} Implements {@code ImmutableBinaryValue} using a {@code byte[]} field.
* This implementation caches result of {@code stringValue()} and {@code getString()} using a private {@code String} field.
*
* @see org.msgpack.value.StringValue
* @see org.msgpack.value.StringValue
*/
public class ImmutableBinaryValueImpl extends AbstractImmutableRawValue implements ImmutableBinaryValue {
public ImmutableBinaryValueImpl(byte[] data) {
Expand Down Expand Up @@ -57,28 +56,24 @@ public void writeTo(MessagePacker pk) throws IOException {
pk.writePayload(data);
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitBinary(this);
}

@Override
public boolean equals(Object o) {
if (this == o) {
if(this == o) {
return true;
}
if (!(o instanceof Value)) {
if(!(o instanceof Value)) {
return false;
}
Value v = (Value) o;
if (!v.isBinaryValue()) {
if(!v.isBinaryValue()) {
return false;
}

if (v instanceof ImmutableBinaryValueImpl) {
if(v instanceof ImmutableBinaryValueImpl) {
ImmutableBinaryValueImpl bv = (ImmutableBinaryValueImpl) v;
return Arrays.equals(data, bv.data);
} else {
}
else {
return Arrays.equals(data, v.asBinaryValue().getByteArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
package org.msgpack.value.impl;

import org.msgpack.core.MessagePacker;
import org.msgpack.value.*;
import org.msgpack.value.ImmutableBooleanValue;
import org.msgpack.value.Value;
import org.msgpack.value.ValueType;

import java.io.IOException;


/**
* {@code ImmutableBooleanValueImpl} Implements {@code ImmutableBooleanValue} using a {@code boolean} field.
*
* <p/>
* This class is a singleton. {@code ImmutableBooleanValueImpl.trueInstance()} and {@code ImmutableBooleanValueImpl.falseInstance()} are the only instances of this class.
*
* @see org.msgpack.value.BooleanValue
* @see org.msgpack.value.BooleanValue
*/
public class ImmutableBooleanValueImpl extends AbstractImmutableValue implements ImmutableBooleanValue {
public static ImmutableBooleanValue TRUE = new ImmutableBooleanValueImpl(true);
Expand Down Expand Up @@ -58,32 +60,28 @@ public void writeTo(MessagePacker packer) throws IOException {
packer.packBoolean(value);
}

@Override
public void accept(ValueVisitor visitor) {
visitor.visitBoolean(this);
}

@Override
public boolean equals(Object o) {
if (o == this) {
if(o == this) {
return true;
}
if (!(o instanceof Value)) {
if(!(o instanceof Value)) {
return false;
}
Value v = (Value) o;

if (!v.isBooleanValue()) {
if(!v.isBooleanValue()) {
return false;
}
return value == v.asBooleanValue().getBoolean();
}

@Override
public int hashCode() {
if (value) {
if(value) {
return 1231;
} else {
}
else {
return 1237;
}
}
Expand Down
Loading