fix[zfoo]: maven compile warning

This commit is contained in:
godotg committed 2023-09-09 12:20:05 +08:00
1 parent 94e7e39e9b
commit 5bd66f4254
20 files changed
+94 -115

No files matched your search

@@ -29,7 +29,9 @@ public class StorageInt<K, V> extends StorageObject<K, V> {
public StorageInt(StorageObject<K, V> storage) {
this.dataMap = new IntObjectHashMap<V>(storage.size());
this.dataMap.putAll((Map<? extends Integer, ? extends V>) storage.getData());
@SuppressWarnings("unchecked")
var map = (Map<? extends Integer, ? extends V>) storage.getData();
this.dataMap.putAll(map);
super.indexMap = storage.indexMap;
super.uniqueIndexMap = storage.uniqueIndexMap;
super.clazz = storage.clazz;
@@ -89,7 +91,9 @@ public class StorageInt<K, V> extends StorageObject<K, V> {
@Override
public Map<K, V> getData() {
return (Map<K, V>) Collections.unmodifiableMap(dataMap);
@SuppressWarnings("unchecked")
var map = (Map<K, V>) Collections.unmodifiableMap(dataMap);
return map;
}
}
@@ -29,7 +29,9 @@ public class StorageLong<K, V> extends StorageObject<K, V> {
public StorageLong(StorageObject<K, V> storage) {
this.dataMap = new LongObjectHashMap<V>(storage.size());
this.dataMap.putAll((Map<? extends Long, ? extends V>) storage.getData());
@SuppressWarnings("unchecked")
var map = (Map<? extends Long, ? extends V>) storage.getData();
this.dataMap.putAll(map);
super.indexMap = storage.indexMap;
super.uniqueIndexMap = storage.uniqueIndexMap;
super.clazz = storage.clazz;
@@ -89,7 +91,9 @@ public class StorageLong<K, V> extends StorageObject<K, V> {
@Override
public Map<K, V> getData() {
return (Map<K, V>) Collections.unmodifiableMap(dataMap);
@SuppressWarnings("unchecked")
var map = (Map<K, V>) Collections.unmodifiableMap(dataMap);
return map;
}
}
@@ -78,12 +78,16 @@ public class StorageObject<K, V> implements IStorage<K, V> {
@Override
public boolean contain(int key) {
return contain((K) Integer.valueOf(key));
@SuppressWarnings("unchecked")
var k = (K) Integer.valueOf(key);
return contain(k);
}
@Override
public boolean contain(long key) {
return contain((K) Long.valueOf(key));
@SuppressWarnings("unchecked")
var k = (K) Long.valueOf(key);
return contain(k);
}
@Override
@@ -95,12 +99,16 @@ public class StorageObject<K, V> implements IStorage<K, V> {
@Override
public V get(int id) {
return get((K) Integer.valueOf(id));
@SuppressWarnings("unchecked")
var key = (K) Integer.valueOf(id);
return get(key);
}
@Override
public V get(long id) {
return get((K) Long.valueOf(id));
@SuppressWarnings("unchecked")
var key = (K) Long.valueOf(id);
return get(key);
}
@Override
@@ -164,6 +172,7 @@ public class StorageObject<K, V> implements IStorage<K, V> {
}
public V put(Object value) {
@SuppressWarnings("unchecked")
var key = (K) ReflectionUtils.getField(idDef.getField(), value);
if (key == null) {
@@ -175,22 +184,24 @@ public class StorageObject<K, V> implements IStorage<K, V> {
}
// 添加资源
var result = dataMap.put(key, (V) value);
@SuppressWarnings("unchecked")
var v = (V) value;
var result = dataMap.put(key, v);
// 添加索引
for (var def : indexDefMap.values()) {
// 使用field的名称作为索引的名称
var indexKey = def.getField().getName();
var indexValue = ReflectionUtils.getField(def.getField(), value);
var indexValue = ReflectionUtils.getField(def.getField(), v);
if (def.isUnique()) {// 唯一索引
var index = uniqueIndexMap.computeIfAbsent(indexKey, k -> new HashMap<>());
if (index.put(indexValue, (V) value) != null) {
if (index.put(indexValue, v) != null) {
throw new RuntimeException(StringUtils.format("Duplicate unique index [index:{}][value:{}] of static resource [class:{}]", indexKey, indexValue, clazz.getName()));
}
} else {// 不是唯一索引
var index = indexMap.computeIfAbsent(indexKey, k -> new HashMap<>());
var list = index.computeIfAbsent(indexValue, k -> new ArrayList<V>());
list.add((V) value);
list.add(v);
}
}
return result;
@@ -63,11 +63,9 @@ public class ConversionTest {
ConversionService conversionService = csfb.getObject();
//Json to Map
String str = "{\"1\":1,\"2\":2,\"3\":3}";
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
// 注意:第3个参数不能写成TypeDescriptor.valueOf(map.getClass()) 而是要明确指定Map的key和value的类型
map = (Map<Integer, Integer>) conversionService.convert(str, TypeDescriptor.valueOf(String.class), TypeDescriptor.map(map.getClass(), TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
@SuppressWarnings("unchecked")
var map = (Map<Integer, Integer>) conversionService.convert(str, TypeDescriptor.valueOf(String.class), TypeDescriptor.map(HashMap.class, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
Assert.assertEquals(3, map.size());
}
@@ -103,7 +103,7 @@ public class ExportBinaryTesting {
ProtocolManager.write(buffer, resourceData);
var bytes = ByteBufUtils.readAllBytes(buffer);
FileUtils.writeInputStreamToFile(new File("D:/github/godot-bird/binary_data.cfg"), new ByteArrayInputStream(bytes));
@SuppressWarnings("unchecked")
var storage = (StorageObject<Integer, StudentResource>) storageManager.getStorage(StudentResource.class);
for (StudentResource resource : storage.getAll()) {
System.out.println(JsonUtils.object2String(resource));