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
Add ValueType bit mask to improve type check performance
  • Loading branch information
xerial committed Jun 13, 2015
commit d1807a5dc68bb315c887cca5492009e659991c3d
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static MessageFormat valueOf(final byte b) {
* @return
*/
@VisibleForTesting
static MessageFormat toMessageFormat(final byte b) {
public static MessageFormat toMessageFormat(final byte b) {
if (Code.isPosFixInt(b)) {
return POSFIXINT;
}
Expand Down
10 changes: 10 additions & 0 deletions msgpack-core/src/main/java/org/msgpack/value/ValueFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public static ImmutableArrayValue newArray(Value[] array) {
return new ImmutableArrayValueImpl(Arrays.copyOf(array, array.length));
}

public static ImmutableArrayValue newArrayOf(Value... elem) {
return newArray(elem);
}


public static ImmutableArrayValue emptyArray() {
return ImmutableArrayValueImpl.empty();
}
Expand Down Expand Up @@ -130,6 +135,11 @@ public static ImmutableMapValue newMap(Value[] kvs) {
return new ImmutableMapValueImpl(Arrays.copyOf(kvs, kvs.length));
}

public static ImmutableMapValue emptyMap() {
return ImmutableMapValueImpl.empty();
}


public static class MapEntry {
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.

We don't need MapEntry class because we can use Map.Entry<Value, Value>.

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.

Right. Fixed to use Map.Entry

public final Value key;
public final Value value;
Expand Down
30 changes: 30 additions & 0 deletions msgpack-core/src/main/java/org/msgpack/value/ValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//
package org.msgpack.value;

import org.msgpack.core.MessageFormat;

/**
* MessageTypeFamily is a group of {@link org.msgpack.core.MessageFormat}s
*/
Expand All @@ -32,10 +34,30 @@ public enum ValueType {

private final boolean numberType;
private final boolean rawType;
private final int bitMask;

private ValueType(boolean numberType, boolean rawType) {
this.numberType = numberType;
this.rawType = rawType;
this.bitMask = 1 << this.ordinal();
}

/**
* Returns a bit mask representing this value type for quickly cheking
* this value type
* @return bit mask representing this value type
*/
public int getBitMask() {
return bitMask;
}

/**
* Check whether the given bit mask represents this value type
* @param bitMask
* @return
*/
public boolean isTypeOf(int bitMask) {
return (this.bitMask & bitMask) != 0;
}

public boolean isNilType() {
Expand Down Expand Up @@ -81,4 +103,12 @@ public boolean isMapType() {
public boolean isExtensionType() {
return this == EXTENSION;
}

public static ValueType valueOf(byte b) {
return MessageFormat.valueOf(b).getValueType();
}

public String toTypeName() {
return this.name().substring(0, 1) + this.name().substring(1).toLowerCase();
}
}
199 changes: 0 additions & 199 deletions msgpack-core/src/test/scala/org/msgpack/value/CursorTest.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ class ValueFactoryTest extends MessagePackSpec {
isRaw : Boolean = false,
isNumber : Boolean = false
) {
v.isNil shouldBe isNil
v.isBoolean shouldBe isBoolean
v.isInteger shouldBe isInteger
v.isFloat shouldBe isFloat
v.isString shouldBe isString
v.isBinary shouldBe isBinary
v.isArray shouldBe isArray
v.isMap shouldBe isMap
v.isExtension shouldBe isExtension
v.isRaw shouldBe isRaw
v.isNumber shouldBe isNumber
v.isNilValue shouldBe isNil
v.isBooleanValue shouldBe isBoolean
v.isIntegerValue shouldBe isInteger
v.isFloatValue shouldBe isFloat
v.isStringValue shouldBe isString
v.isBinaryValue shouldBe isBinary
v.isArrayValue shouldBe isArray
v.isMapValue shouldBe isMap
v.isExtensionValue shouldBe isExtension
v.isRawValue shouldBe isRaw
v.isNumberValue shouldBe isNumber
}

"ValueFactory" should {

"create valid type values" in {
isValid(ValueFactory.nilValue(), expected=ValueType.NIL, isNil = true)
isValid(ValueFactory.nil(), expected=ValueType.NIL, isNil = true)
forAll{(v:Boolean) => isValid(ValueFactory.newBoolean(v), expected=ValueType.BOOLEAN, isBoolean = true)}
forAll{(v:Int) => isValid(ValueFactory.newInt(v), expected=ValueType.INTEGER, isInteger = true, isNumber = true)}
forAll{(v:Int) => isValid(ValueFactory.newInteger(v), expected=ValueType.INTEGER, isInteger = true, isNumber = true)}
forAll{(v:Float) => isValid(ValueFactory.newFloat(v), expected=ValueType.FLOAT, isFloat = true, isNumber = true)}
forAll{(v:String) => isValid(ValueFactory.newString(v), expected=ValueType.STRING, isString = true, isRaw = true)}
forAll{(v:Array[Byte]) => isValid(ValueFactory.newBinary(v), expected=ValueType.BINARY, isBinary = true, isRaw = true)}
Expand Down