rename[protocol]: rename enhance method

This commit is contained in:
godotg committed 2022-09-25 14:14:48 +08:00
1 parent ba95368991
commit f754172649
5 files changed
+16 -19

No files matched your search

@@ -430,7 +430,7 @@ public abstract class ByteBufUtils {
public static Set<IPacket> readPacketSet(ByteBuf byteBuf, IProtocolRegistration protocolRegistration) {
var length = readInt(byteBuf);
var set = (Set<IPacket>) CollectionUtils.newFixedSet(length);
var set = (Set<IPacket>) CollectionUtils.newSet(length);
for (var i = 0; i < length; i++) {
set.add((IPacket) protocolRegistration.read(byteBuf));
}
@@ -619,7 +619,7 @@ public abstract class ByteBufUtils {
public static Map<String, Integer> readStringIntMap(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var map = (Map<String, Integer>) CollectionUtils.newFixedMap(length);
var map = (Map<String, Integer>) CollectionUtils.newMap(length);
for (var i = 0; i < length; i++) {
map.put(readString(byteBuf), readIntBox(byteBuf));
}
@@ -640,7 +640,7 @@ public abstract class ByteBufUtils {
public static Map<String, Long> readStringLongMap(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var map = (Map<String, Long>) CollectionUtils.newFixedMap(length);
var map = (Map<String, Long>) CollectionUtils.newMap(length);
for (var i = 0; i < length; i++) {
map.put(readString(byteBuf), readLongBox(byteBuf));
}
@@ -661,7 +661,7 @@ public abstract class ByteBufUtils {
public static Map<String, String> readStringStringMap(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var map = (Map<String, String>) CollectionUtils.newFixedMap(length);
var map = (Map<String, String>) CollectionUtils.newMap(length);
for (var i = 0; i < length; i++) {
map.put(readString(byteBuf), readString(byteBuf));
}
@@ -682,7 +682,7 @@ public abstract class ByteBufUtils {
public static Map<String, IPacket> readStringPacketMap(ByteBuf byteBuf, IProtocolRegistration protocolRegistration) {
var length = readInt(byteBuf);
var map = (Map<String, IPacket>) CollectionUtils.newFixedMap(length);
var map = (Map<String, IPacket>) CollectionUtils.newMap(length);
for (var i = 0; i < length; i++) {
map.put(readString(byteBuf), (IPacket) protocolRegistration.read(byteBuf));
}
@@ -760,7 +760,7 @@ public abstract class ByteBufUtils {
public static Set<Boolean> readBooleanSet(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var set = (Set<Boolean>) CollectionUtils.newFixedSet(length);
var set = (Set<Boolean>) CollectionUtils.newSet(length);
for (var i = 0; i < length; i++) {
set.add(readBooleanBox(byteBuf));
}
@@ -1143,7 +1143,7 @@ public abstract class ByteBufUtils {
public static Set<Float> readFloatSet(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var set = (Set<Float>) CollectionUtils.newFixedSet(length);
var set = (Set<Float>) CollectionUtils.newSet(length);
for (var i = 0; i < length; i++) {
set.add(readFloatBox(byteBuf));
}
@@ -1224,7 +1224,7 @@ public abstract class ByteBufUtils {
public static Set<Double> readDoubleSet(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var set = (Set<Double>) CollectionUtils.newFixedSet(length);
var set = (Set<Double>) CollectionUtils.newSet(length);
for (var i = 0; i < length; i++) {
set.add(readDoubleBox(byteBuf));
}
@@ -1282,7 +1282,7 @@ public abstract class ByteBufUtils {
public static Set<String> readStringSet(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var set = (Set<String>) CollectionUtils.newFixedSet(length);
var set = (Set<String>) CollectionUtils.newSet(length);
for (var i = 0; i < length; i++) {
set.add(readString(byteBuf));
}
@@ -75,18 +75,15 @@ public abstract class CollectionUtils {
}
/**
* 固定大小集合,如果初始化容量为0,则后续无法继续增加集合容量
*/
public static List<?> newFixedList(int size) {
return size <= 0 ? Collections.EMPTY_LIST : new ArrayList<>(size);
public static List<?> newList(int size) {
return size <= 0 ? Collections.EMPTY_LIST : new ArrayList<>(comfortableLength(size));
}
public static Set<?> newFixedSet(int size) {
public static Set<?> newSet(int size) {
return size <= 0 ? Collections.EMPTY_SET : new HashSet<>(comfortableCapacity(size));
}
public static Map<?, ?> newFixedMap(int size) {
public static Map<?, ?> newMap(int size) {
return size <= 0 ? Collections.EMPTY_MAP : new HashMap<>(comfortableCapacity(size));
}
@@ -67,7 +67,7 @@ public class EnhanceListSerializer implements IEnhanceSerializer {
var size = "size" + GenerateProtocolFile.index.getAndIncrement();
builder.append(StringUtils.format("int {}={}.readInt($1);", size, EnhanceUtils.byteBufUtils));
builder.append(StringUtils.format("List {} = CollectionUtils.newFixedList({});", list, size));
builder.append(StringUtils.format("List {} = CollectionUtils.newList({});", list, size));
var i = "i" + GenerateProtocolFile.index.getAndIncrement();
@@ -80,7 +80,7 @@ public class EnhanceMapSerializer implements IEnhanceSerializer {
var size = "size" + GenerateProtocolFile.index.getAndIncrement();
builder.append(StringUtils.format("int {}={}.readInt($1);", size, EnhanceUtils.byteBufUtils));
builder.append(StringUtils.format("Map {} = CollectionUtils.newFixedMap({});", map, size));
builder.append(StringUtils.format("Map {} = CollectionUtils.newMap({});", map, size));
var i = "i" + GenerateProtocolFile.index.getAndIncrement();
builder.append(StringUtils.format("for(int {}=0; {}<{}; {}++){", i, i, size, i));
@@ -65,7 +65,7 @@ public class EnhanceSetSerializer implements IEnhanceSerializer {
var size = "size" + GenerateProtocolFile.index.getAndIncrement();
builder.append(StringUtils.format("int {} = {}.readInt($1);", size, EnhanceUtils.byteBufUtils));
builder.append(StringUtils.format("Set {} = CollectionUtils.newFixedSet({});", set, size));
builder.append(StringUtils.format("Set {} = CollectionUtils.newSet({});", set, size));
var i = "i" + GenerateProtocolFile.index.getAndIncrement();
builder.append(StringUtils.format("for(int {}=0; {}<{}; {}++){", i, i, size, i));