Skip to content

Commit ed45331

Browse files
committed
Remove visitor, ExtensionTypeHeader constructor. Fix exception type of integer overflow
1 parent c782451 commit ed45331

16 files changed

+39
-180
lines changed

msgpack-core/src/main/java/org/msgpack/core/ExtensionTypeHeader.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ public class ExtensionTypeHeader {
1010
private final int length;
1111

1212
public ExtensionTypeHeader(byte type, int length) {
13-
checkArgument(length >= 0, String.format("length must be >= 0: %,d", length));
13+
checkArgument(length >= 0, "length must be >= 0");
1414
this.type = type;
1515
this.length = length;
1616
}
1717

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

2423
public byte getType() {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.msgpack.value;
1717

1818
import java.math.BigInteger;
19-
import org.msgpack.core.MessageOverflowException;
19+
import org.msgpack.core.MessageIntegerOverflowException;
2020

2121
/**
2222
* The interface {@code IntegerValue} represents MessagePack's Integer type.
@@ -47,31 +47,31 @@ public interface IntegerValue extends NumberValue {
4747
/**
4848
* Returns the value as a {@code byte}, otherwise throws an exception.
4949
*
50-
* @throws MessageOverflowException
50+
* @throws MessageIntegerOverflowException
5151
* If the value does not fit in the range of {@code byte} type.
5252
*/
5353
byte getByte();
5454

5555
/**
5656
* Returns the value as a {@code short}, otherwise throws an exception.
5757
*
58-
* @throws MessageOverflowException
58+
* @throws MessageIntegerOverflowException
5959
* If the value does not fit in the range of {@code short} type.
6060
*/
6161
short getShort();
6262

6363
/**
6464
* Returns the value as an {@code int}, otherwise throws an exception.
6565
*
66-
* @throws MessageOverflowException
66+
* @throws MessageIntegerOverflowException
6767
* If the value does not fit in the range of {@code int} type.
6868
*/
6969
int getInt();
7070

7171
/**
7272
* Returns the value as a {@code long}, otherwise throws an exception.
7373
*
74-
* @throws MessageOverflowException
74+
* @throws MessageIntegerOverflowException
7575
* If the value does not fit in the range of {@code long} type.
7676
*/
7777
long getLong();

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,6 @@ public interface Value {
235235
*/
236236
void writeTo(MessagePacker pk) throws IOException;
237237

238-
239-
/**
240-
* Accept a visitor to traverse this value
241-
* @param visitor
242-
*/
243-
void accept(ValueVisitor visitor);
244-
245238
/**
246239
* Compares this value to the specified object.
247240
* <p/>

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

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

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,6 @@ public ImmutableNilValue immutableValue() {
239239
public void writeTo(MessagePacker pk) throws IOException {
240240
pk.packNil();
241241
}
242-
243-
@Override
244-
public void accept(ValueVisitor visitor) {
245-
visitor.visitNil();
246-
}
247242
}
248243

249244

@@ -283,11 +278,6 @@ public boolean getBoolean() {
283278
public void writeTo(MessagePacker pk) throws IOException {
284279
pk.packBoolean(longValue == 1L);
285280
}
286-
287-
@Override
288-
public void accept(ValueVisitor visitor) {
289-
visitor.visitBoolean(this);
290-
}
291281
}
292282

293283

@@ -501,11 +491,6 @@ public void writeTo(MessagePacker pk) throws IOException {
501491
pk.packLong(longValue);
502492
}
503493
}
504-
505-
@Override
506-
public void accept(ValueVisitor visitor) {
507-
visitor.visitInteger(this);
508-
}
509494
}
510495

511496

@@ -549,10 +534,6 @@ public void writeTo(MessagePacker pk) throws IOException {
549534
pk.packDouble(doubleValue);
550535
}
551536

552-
@Override
553-
public void accept(ValueVisitor visitor) {
554-
visitor.visitFloat(this);
555-
}
556537
}
557538

558539

@@ -639,10 +620,6 @@ public void writeTo(MessagePacker pk) throws IOException {
639620
pk.writePayload(data);
640621
}
641622

642-
@Override
643-
public void accept(ValueVisitor visitor) {
644-
visitor.visitBinary(this);
645-
}
646623
}
647624

648625

@@ -683,11 +660,6 @@ public void writeTo(MessagePacker pk) throws IOException {
683660
pk.packRawStringHeader(data.length);
684661
pk.writePayload(data);
685662
}
686-
687-
@Override
688-
public void accept(ValueVisitor visitor) {
689-
visitor.visitString(this);
690-
}
691663
}
692664

693665

@@ -756,11 +728,6 @@ public void writeTo(MessagePacker pk) throws IOException {
756728
e.writeTo(pk);
757729
}
758730
}
759-
760-
@Override
761-
public void accept(ValueVisitor visitor) {
762-
visitor.visitArray(this);
763-
}
764731
}
765732

766733
////
@@ -840,11 +807,6 @@ public void writeTo(MessagePacker pk) throws IOException {
840807
pair.getValue().writeTo(pk);
841808
}
842809
}
843-
844-
@Override
845-
public void accept(ValueVisitor visitor) {
846-
visitor.visitMap(this);
847-
}
848810
}
849811

850812

@@ -888,11 +850,6 @@ public byte[] getData() {
888850
public void writeTo(MessagePacker pk) throws IOException {
889851
((ImmutableExtensionValue) objectValue).writeTo(pk);
890852
}
891-
892-
@Override
893-
public void accept(ValueVisitor visitor) {
894-
visitor.visitExtension(((ImmutableExtensionValue) objectValue));
895-
}
896853
}
897854

898855

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

913-
@Override
914-
public void accept(ValueVisitor visitor) {
915-
accessor.accept(visitor);
916-
}
917-
918870
@Override
919871
public int hashCode() {
920872
return immutableValue().hashCode(); // TODO optimize

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ public void writeTo(MessagePacker pk) throws IOException {
9595
}
9696
}
9797

98-
@Override
99-
public void accept(ValueVisitor visitor) {
100-
visitor.visitArray(this);
101-
}
102-
10398
@Override
10499
public boolean equals(Object o) {
105100
if(o == this) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,6 @@ public void writeTo(MessagePacker pk) throws IOException {
161161
pk.packBigInteger(value);
162162
}
163163

164-
@Override
165-
public void accept(ValueVisitor visitor) {
166-
visitor.visitInteger(this);
167-
}
168-
169164
@Override
170165
public boolean equals(Object o) {
171166
if (o == this) {

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@
1616
package org.msgpack.value.impl;
1717

1818
import org.msgpack.core.MessagePacker;
19+
import org.msgpack.value.ImmutableBinaryValue;
1920
import org.msgpack.value.Value;
2021
import org.msgpack.value.ValueType;
21-
import org.msgpack.value.ImmutableBinaryValue;
22-
import org.msgpack.value.ValueVisitor;
2322

24-
import java.util.Arrays;
2523
import java.io.IOException;
24+
import java.util.Arrays;
2625

2726

2827
/**
2928
* {@code ImmutableBinaryValueImpl} Implements {@code ImmutableBinaryValue} using a {@code byte[]} field.
3029
* This implementation caches result of {@code stringValue()} and {@code getString()} using a private {@code String} field.
3130
*
32-
* @see org.msgpack.value.StringValue
31+
* @see org.msgpack.value.StringValue
3332
*/
3433
public class ImmutableBinaryValueImpl extends AbstractImmutableRawValue implements ImmutableBinaryValue {
3534
public ImmutableBinaryValueImpl(byte[] data) {
@@ -57,28 +56,24 @@ public void writeTo(MessagePacker pk) throws IOException {
5756
pk.writePayload(data);
5857
}
5958

60-
@Override
61-
public void accept(ValueVisitor visitor) {
62-
visitor.visitBinary(this);
63-
}
64-
6559
@Override
6660
public boolean equals(Object o) {
67-
if (this == o) {
61+
if(this == o) {
6862
return true;
6963
}
70-
if (!(o instanceof Value)) {
64+
if(!(o instanceof Value)) {
7165
return false;
7266
}
7367
Value v = (Value) o;
74-
if (!v.isBinaryValue()) {
68+
if(!v.isBinaryValue()) {
7569
return false;
7670
}
7771

78-
if (v instanceof ImmutableBinaryValueImpl) {
72+
if(v instanceof ImmutableBinaryValueImpl) {
7973
ImmutableBinaryValueImpl bv = (ImmutableBinaryValueImpl) v;
8074
return Arrays.equals(data, bv.data);
81-
} else {
75+
}
76+
else {
8277
return Arrays.equals(data, v.asBinaryValue().getByteArray());
8378
}
8479
}

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
package org.msgpack.value.impl;
1717

1818
import org.msgpack.core.MessagePacker;
19-
import org.msgpack.value.*;
19+
import org.msgpack.value.ImmutableBooleanValue;
20+
import org.msgpack.value.Value;
21+
import org.msgpack.value.ValueType;
2022

2123
import java.io.IOException;
2224

2325

2426
/**
2527
* {@code ImmutableBooleanValueImpl} Implements {@code ImmutableBooleanValue} using a {@code boolean} field.
26-
*
28+
* <p/>
2729
* This class is a singleton. {@code ImmutableBooleanValueImpl.trueInstance()} and {@code ImmutableBooleanValueImpl.falseInstance()} are the only instances of this class.
2830
*
29-
* @see org.msgpack.value.BooleanValue
31+
* @see org.msgpack.value.BooleanValue
3032
*/
3133
public class ImmutableBooleanValueImpl extends AbstractImmutableValue implements ImmutableBooleanValue {
3234
public static ImmutableBooleanValue TRUE = new ImmutableBooleanValueImpl(true);
@@ -58,32 +60,28 @@ public void writeTo(MessagePacker packer) throws IOException {
5860
packer.packBoolean(value);
5961
}
6062

61-
@Override
62-
public void accept(ValueVisitor visitor) {
63-
visitor.visitBoolean(this);
64-
}
65-
6663
@Override
6764
public boolean equals(Object o) {
68-
if (o == this) {
65+
if(o == this) {
6966
return true;
7067
}
71-
if (!(o instanceof Value)) {
68+
if(!(o instanceof Value)) {
7269
return false;
7370
}
7471
Value v = (Value) o;
7572

76-
if (!v.isBooleanValue()) {
73+
if(!v.isBooleanValue()) {
7774
return false;
7875
}
7976
return value == v.asBooleanValue().getBoolean();
8077
}
8178

8279
@Override
8380
public int hashCode() {
84-
if (value) {
81+
if(value) {
8582
return 1231;
86-
} else {
83+
}
84+
else {
8785
return 1237;
8886
}
8987
}

0 commit comments

Comments
 (0)