Skip to content

Commit 352b918

Browse files
committed
remove some KVP constructors
1 parent 5d27447 commit 352b918

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/main/java/com/esaulpaugh/headlong/rlp/KVP.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,11 @@ public KVP(String keyUtf8, String val, int valEncoding) {
5151
this(keyUtf8, Strings.decode(val, valEncoding));
5252
}
5353

54-
public KVP(String keyUtf8, byte[] rawVal) {
55-
this(Strings.decode(keyUtf8, UTF_8), rawVal);
56-
}
57-
58-
public KVP(byte[] key, byte[] value) {
59-
this.rlp = RLPEncoder.sequence(key, value);
54+
public KVP(String keyUtf8, byte[] val) {
55+
this.rlp = RLPEncoder.sequence(Strings.decode(keyUtf8, UTF_8), val);
6056
this.key = RLP_STRICT.wrapString(rlp);
6157
}
6258

63-
public KVP(String keyUtf8, RLPItem value) {
64-
this(RLP_STRICT.wrapString(RLPEncoder.string(Strings.decode(keyUtf8, UTF_8))), value);
65-
}
66-
6759
public KVP(RLPString key, RLPItem value) {
6860
final int keyLen = key.encodingLength();
6961
this.rlp = new byte[keyLen + value.encodingLength()];

src/test/java/com/esaulpaugh/headlong/rlp/EIP778Test.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Set;
3535

3636
import static com.esaulpaugh.headlong.TestUtils.assertThrown;
37+
import static com.esaulpaugh.headlong.rlp.KVP.CLIENT;
3738
import static com.esaulpaugh.headlong.rlp.KVP.EMPTY_ARRAY;
3839
import static com.esaulpaugh.headlong.rlp.KVP.ID;
3940
import static com.esaulpaugh.headlong.rlp.KVP.IP;
@@ -340,11 +341,10 @@ public byte[] sign(byte[] content) {
340341

341342
@Test
342343
public void testDuplicateKeys() throws Throwable {
343-
byte[] keyBytes = new byte[0];
344-
final List<KVP> pairs = Arrays.asList(new KVP(keyBytes, new byte[0]), new KVP(keyBytes, new byte[1]));
344+
final List<KVP> pairs = Arrays.asList(new KVP("", new byte[0]), new KVP("", new byte[1]));
345345
assertThrown(IllegalArgumentException.class, "duplicate key", () -> pairs.sort(Comparator.naturalOrder()));
346346

347-
final List<KVP> pairs2 = Arrays.asList(new KVP(new byte[] { 2 }, new byte[0]), new KVP(new byte[] { 2 }, new byte[1]));
347+
final List<KVP> pairs2 = Arrays.asList(new KVP("d", new byte[0]), new KVP("d", new byte[1]));
348348
assertThrown(IllegalArgumentException.class, "duplicate key", () -> pairs2.sort(Comparator.naturalOrder()));
349349
}
350350

@@ -476,6 +476,9 @@ public void testOutOfOrder() throws Throwable {
476476
@Test
477477
public void testToString() {
478478
assertEquals("ip --> 3235352e3130312e302e313238", new KVP(IP, "255.101.0.128", ASCII).toString());
479-
assertEquals("client --> [\"dd\", \"\"]", new KVP(KVP.CLIENT, RLPDecoder.RLP_STRICT.wrapBits(0xc482646480L)).toString());
479+
assertEquals(
480+
"client --> [\"dd\", \"\"]",
481+
new KVP(RLPDecoder.RLP_STRICT.wrapString(RLPEncoder.string(Strings.decode(CLIENT, UTF_8))), RLPDecoder.RLP_STRICT.wrapBits(0xc482646480L)).toString()
482+
);
480483
}
481484
}

0 commit comments

Comments
 (0)