perf[list]: 统一命名规则

This commit is contained in:
godotg committed 2022-09-23 21:13:03 +08:00
1 parent 9c5c23c7af
commit 5f7b942d1f
8 files changed
+43 -41

No files matched your search

@@ -418,9 +418,9 @@ public abstract class ByteBufUtils {
public static List<IPacket> readPacketList(ByteBuf byteBuf, IProtocolRegistration protocolRegistration) {
var length = readInt(byteBuf);
var list = (List<IPacket>) CollectionUtils.newFixedList(length);
var list = new FixedSizeList(length);
for (var i = 0; i < length; i++) {
list.add((IPacket) protocolRegistration.read(byteBuf));
list.set(i, protocolRegistration.read(byteBuf));
}
return list;
}
@@ -753,7 +753,7 @@ public abstract class ByteBufUtils {
public static List<Boolean> readBooleanList(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var list = new FixedSizeBooleanList(length);
var list = new FixedSizeListBoolean(length);
for (var i = 0; i < length; i++) {
list.set(i, readBoolean(byteBuf));
}
@@ -917,7 +917,7 @@ public abstract class ByteBufUtils {
public static List<Short> readShortList(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var list = new FixedSizeShortList(length);
var list = new FixedSizeListShort(length);
for (var i = 0; i < length; i++) {
list.set(i, readShort(byteBuf));
}
@@ -1075,7 +1075,7 @@ public abstract class ByteBufUtils {
public static List<Long> readLongList(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var list = new FixedSizeLongList(length);
var list = new FixedSizeListLong(length);
for (var i = 0; i < length; i++) {
list.set(i, readLong(byteBuf));
}
@@ -1161,7 +1161,7 @@ public abstract class ByteBufUtils {
public static List<Float> readFloatList(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var list = new FixedSizeFloatList(length);
var list = new FixedSizeListFloat(length);
for (var i = 0; i < length; i++) {
list.set(i, readFloat(byteBuf));
}
@@ -1247,7 +1247,7 @@ public abstract class ByteBufUtils {
public static List<Double> readDoubleList(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var list = new FixedSizeDoubleList(length);
var list = new FixedSizeListDouble(length);
for (var i = 0; i < length; i++) {
list.set(i, readDouble(byteBuf));
}
@@ -1305,7 +1305,7 @@ public abstract class ByteBufUtils {
public static List<String> readStringList(ByteBuf byteBuf) {
var length = readInt(byteBuf);
var list = new FixedSizeStringList(length);
var list = new FixedSizeList(length);
for (var i = 0; i < length; i++) {
list.set(i, readString(byteBuf));
}
@@ -18,15 +18,17 @@ import java.util.List;
import java.util.ListIterator;
/**
* 初始化就确定了大小的List,不可添加和删除,但是可以set,就像一个数组一样
*
* @author godotg
* @version 3.0
*/
public class FixedSizeStringList implements List<String> {
public class FixedSizeList<E> implements List<E> {
private final String[] array;
private final Object[] array;
public FixedSizeStringList(int initialCapacity) {
this.array = new String[initialCapacity];
public FixedSizeList(int initialCapacity) {
this.array = new Object[initialCapacity];
}
@Override
@@ -40,15 +42,15 @@ public class FixedSizeStringList implements List<String> {
}
@Override
public String get(int index) {
return array[index];
public E get(int index) {
return (E) array[index];
}
@Override
public String set(int index, String ele) {
public E set(int index, E ele) {
var old = array[index];
array[index] = ele;
return old;
return (E) old;
}
@Override
@@ -83,42 +85,42 @@ public class FixedSizeStringList implements List<String> {
}
@Override
public Iterator<String> iterator() {
return ArrayUtils.toList(array).iterator();
public Iterator<E> iterator() {
return (Iterator<E>) ArrayUtils.toList(array).iterator();
}
@Override
public ListIterator<String> listIterator() {
return ArrayUtils.toList(array).listIterator();
public ListIterator<E> listIterator() {
return (ListIterator<E>) ArrayUtils.toList(array).listIterator();
}
@Override
public ListIterator<String> listIterator(int index) {
return ArrayUtils.toList(array).listIterator(index);
public ListIterator<E> listIterator(int index) {
return (ListIterator<E>) ArrayUtils.toList(array).listIterator(index);
}
@Override
public List<String> subList(int fromIndex, int toIndex) {
return ArrayUtils.toList(array).subList(fromIndex, toIndex);
public List<E> subList(int fromIndex, int toIndex) {
return (List<E>) ArrayUtils.toList(array).subList(fromIndex, toIndex);
}
@Override
public boolean add(String e) {
public boolean add(E e) {
throw new UnsupportedOperationException();
}
@Override
public void add(int index, String element) {
public void add(int index, E element) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends String> collection) {
public boolean addAll(Collection<? extends E> collection) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(int index, Collection<? extends String> collection) {
public boolean addAll(int index, Collection<? extends E> collection) {
throw new UnsupportedOperationException();
}
@@ -128,7 +130,7 @@ public class FixedSizeStringList implements List<String> {
}
@Override
public String remove(int index) {
public E remove(int index) {
throw new UnsupportedOperationException();
}
@@ -21,11 +21,11 @@ import java.util.ListIterator;
* @author godotg
* @version 3.0
*/
public class FixedSizeBooleanList implements List<Boolean> {
public class FixedSizeListBoolean implements List<Boolean> {
private final boolean[] array;
public FixedSizeBooleanList(int initialCapacity) {
public FixedSizeListBoolean(int initialCapacity) {
this.array = new boolean[initialCapacity];
}
@@ -21,11 +21,11 @@ import java.util.ListIterator;
* @author godotg
* @version 3.0
*/
public class FixedSizeDoubleList implements List<Double> {
public class FixedSizeListDouble implements List<Double> {
private final double[] array;
public FixedSizeDoubleList(int initialCapacity) {
public FixedSizeListDouble(int initialCapacity) {
this.array = new double[initialCapacity];
}
@@ -21,11 +21,11 @@ import java.util.ListIterator;
* @author godotg
* @version 3.0
*/
public class FixedSizeFloatList implements List<Float> {
public class FixedSizeListFloat implements List<Float> {
private final float[] array;
public FixedSizeFloatList(int initialCapacity) {
public FixedSizeListFloat(int initialCapacity) {
this.array = new float[initialCapacity];
}
@@ -21,11 +21,11 @@ import java.util.ListIterator;
* @author godotg
* @version 3.0
*/
public class FixedSizeLongList implements List<Long> {
public class FixedSizeListLong implements List<Long> {
private final long[] array;
public FixedSizeLongList(int initialCapacity) {
public FixedSizeListLong(int initialCapacity) {
this.array = new long[initialCapacity];
}
@@ -21,11 +21,11 @@ import java.util.ListIterator;
* @author godotg
* @version 3.0
*/
public class FixedSizeShortList implements List<Short> {
public class FixedSizeListShort implements List<Short> {
private final short[] array;
public FixedSizeShortList(int initialCapacity) {
public FixedSizeListShort(int initialCapacity) {
this.array = new short[initialCapacity];
}
@@ -34,8 +34,8 @@ public class ListTest {
}
@Test
public void testFixedSizeStringList() {
var list = new FixedSizeStringList(3);
public void testFixedSizeList() {
var list = new FixedSizeList(3);
list.set(0, "1");
list.set(1, "2");
list.set(2, "3");