fix[zfoo]: maven compile warning

This commit is contained in:
godotg
2023-09-09 12:20:05 +08:00
parent 94e7e39e9b
commit 5bd66f4254
20 changed files with 94 additions and 115 deletions
@@ -368,7 +368,9 @@ public abstract class ArrayUtils {
var length = list.size();
var objectArray = Array.newInstance(clazz, length);
return (T[]) copy(list.toArray(), objectArray, length);
@SuppressWarnings("unchecked")
var copy = (T[]) copy(list.toArray(), objectArray, length);
return copy;
}
@@ -452,7 +454,9 @@ public abstract class ArrayUtils {
AssertionUtils.notNull(clazz);
var length = source.length;
var target = Array.newInstance(clazz, length);
return (T[]) copy(source, target, length);
@SuppressWarnings("unchecked")
var copy = (T[]) copy(source, target, length);
return copy;
}
private static Object copy(Object source, Object target, int length) {
@@ -234,52 +234,6 @@ public abstract class CollectionUtils {
}
/**
* list合并
*
* @param exclusive 元素是否是独占的,也就是说是否可以重复
* @param pairs 需要被合并的pairs集合,第一个参数是步数,第二个参数是集合
* @return 返回合并后的list
*/
public static <T> List<T> listJoinList(boolean exclusive, Pair<Integer, List<T>>... pairs) {
return listJoinList(exclusive, List.of(pairs));
}
public static <T> List<T> listJoinList(boolean exclusive, List<Pair<Integer, List<T>>> pairs) {
var iteratorList = new ArrayList<List<T>>();
var iteratorMap = new HashMap<List<T>, Iterator<T>>();
var stepMap = new HashMap<List<T>, Integer>();
for (var pair : pairs) {
var step = pair.getKey();
var list = pair.getValue();
AssertionUtils.ge1(step);
if (isNotEmpty(list)) {
var iterator = list.iterator();
iteratorList.add(list);
iteratorMap.put(list, iterator);
stepMap.put(list, step);
}
}
var result = new ArrayList<T>();
while (iteratorMap.values().stream().anyMatch(it -> it.hasNext())) {
for (var list : iteratorList) {
var iterator = iteratorMap.get(list);
var step = stepMap.get(list);
for (var i = 0; i < step && iterator.hasNext(); i++) {
var element = iterator.next();
if (exclusive && result.contains(element)) {
i--;
continue;
}
result.add(element);
}
}
}
return result;
}
/**
* 获取集合的最后几个元素
@@ -49,6 +49,7 @@ public class ConcurrentArrayList<E> implements List<E> {
public List<E> clearAndReturn() {
lock.lock();
try {
@SuppressWarnings("unchecked")
var newList = (ArrayList<E>) list.clone();
list.clear();
return newList;
@@ -71,6 +72,7 @@ public class ConcurrentArrayList<E> implements List<E> {
public Iterator<E> iterator() {
lock.lock();
try {
@SuppressWarnings("unchecked")
var newList = (ArrayList<E>) list.clone();
return newList.iterator();
} finally {
@@ -237,6 +239,7 @@ public class ConcurrentArrayList<E> implements List<E> {
public ListIterator<E> listIterator() {
lock.lock();
try {
@SuppressWarnings("unchecked")
var newList = (ArrayList<E>) list.clone();
return newList.listIterator();
} finally {
@@ -248,6 +251,7 @@ public class ConcurrentArrayList<E> implements List<E> {
public ListIterator<E> listIterator(int index) {
lock.lock();
try {
@SuppressWarnings("unchecked")
var newList = (ArrayList<E>) list.clone();
return newList.listIterator(index);
} finally {
@@ -123,7 +123,9 @@ public class FileChannelMap<V> implements LpMap<V>, Closeable {
dbBuffer.writeBytes(dbFileChannel, packetPosition, (int) packetSize);
var packet = protocolRegistration.read(dbBuffer);
return (V) packet;
@SuppressWarnings("unchecked")
var p = (V) packet;
return p;
} catch (Exception e) {
return null;
}
@@ -110,6 +110,7 @@ public class FileHeapMap<V> implements LpMap<V> {
var size = ByteBufUtils.readLong(buffer);
for (var i = 0; i < size; i++) {
var key = ByteBufUtils.readLong(buffer);
@SuppressWarnings("unchecked")
var value = (V) protocolRegistration.read(buffer);
put(key, value);
}
@@ -13,7 +13,6 @@
package com.zfoo.protocol.util;
import com.zfoo.protocol.collection.CollectionUtils;
import com.zfoo.protocol.model.Pair;
import org.junit.Assert;
import org.junit.Test;
@@ -49,19 +48,6 @@ public class CollectionUtilsTest {
Assert.assertArrayEquals(c.toArray(), a.toArray());
}
@Test
public void listJoinListTest() {
var a = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
var b = List.of(11, 22, 33, 44, 55);
var c = List.of(1, 2, 3, 4, 5, 6);
var d = CollectionUtils.listJoinList(true, new Pair<>(2, a), new Pair<>(2, b), new Pair<>(2, c));
Assert.assertArrayEquals(d.toArray(), List.of(1, 2, 11, 22, 3, 4, 5, 6, 33, 44, 7, 8, 55, 9).toArray());
var e = CollectionUtils.listJoinList(false, new Pair<>(2, a), new Pair<>(2, b), new Pair<>(2, c));
Assert.assertArrayEquals(e.toArray(), List.of(1, 2, 11, 22, 1, 2, 3, 4, 33, 44, 3, 4, 5, 6, 55, 5, 6, 7, 8, 9).toArray());
}
@Test
public void subListLastTest() {
var list = List.of(1, 2, 3, 4, 5);