From 438d4894ca24c099cf04f1cc630f64278f7efccd Mon Sep 17 00:00:00 2001 From: godotg Date: Sat, 24 Sep 2022 18:15:11 +0800 Subject: [PATCH] =?UTF-8?q?feat[buffer]:=20=E4=BD=BF=E7=94=A8primitive=20t?= =?UTF-8?q?ype=E7=9A=84=E9=AB=98=E6=80=A7=E8=83=BDset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zfoo/protocol/buffer/ByteBufUtils.java | 16 ++++++++-------- .../protocol/collection/FixedCollectionTest.java | 13 ++++++------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java index 44b23fe9..8548e64b 100644 --- a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java @@ -844,9 +844,9 @@ public abstract class ByteBufUtils { public static Set readByteSet(ByteBuf byteBuf) { var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); + var set = new HashByteSet(length); for (var i = 0; i < length; i++) { - set.add(readByteBox(byteBuf)); + set.add(readByte(byteBuf)); } return set; } @@ -930,9 +930,9 @@ public abstract class ByteBufUtils { public static Set readShortSet(ByteBuf byteBuf) { var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); + var set = new HashShortSet(length); for (var i = 0; i < length; i++) { - set.add(readShortBox(byteBuf)); + set.add(readShort(byteBuf)); } return set; } @@ -1009,9 +1009,9 @@ public abstract class ByteBufUtils { public static Set readIntSet(ByteBuf byteBuf) { var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); + var set = new HashIntSet(length); for (var i = 0; i < length; i++) { - set.add(readIntBox(byteBuf)); + set.add(readInt(byteBuf)); } return set; } @@ -1088,9 +1088,9 @@ public abstract class ByteBufUtils { public static Set readLongSet(ByteBuf byteBuf) { var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); + var set = new HashLongSet(length); for (var i = 0; i < length; i++) { - set.add(readLongBox(byteBuf)); + set.add(readLong(byteBuf)); } return set; } diff --git a/protocol/src/test/java/com/zfoo/protocol/collection/FixedCollectionTest.java b/protocol/src/test/java/com/zfoo/protocol/collection/FixedCollectionTest.java index 8e4d21c1..be10445f 100644 --- a/protocol/src/test/java/com/zfoo/protocol/collection/FixedCollectionTest.java +++ b/protocol/src/test/java/com/zfoo/protocol/collection/FixedCollectionTest.java @@ -49,19 +49,18 @@ public class FixedCollectionTest { @Test - public void testFixedHashInt() { - var list = new FixedSizeListInt(3); - list.set(0, 1); - list.set(1, 2); - list.set(2, 4); - var set = new FixedHashSetInt(list); + public void testHashIntSet() { + var set = new HashIntSet(3); + set.add(1); + set.add(2); + set.add(3); for (int i = 0; i < set.size(); i++) { for (var ele : set) { // test iterator } } - Assert.assertTrue(set.contains(4)); + Assert.assertTrue(set.contains(3)); } }