completed PrimitiveList implementation
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package dev.asdf00.general.utils.list.internal;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ListReader {
|
||||
public static int getSize(AbstractBaseList list) {
|
||||
return list.size;
|
||||
}
|
||||
|
||||
public static int getModCnt(AbstractBaseList list) {
|
||||
return list.modCnt;
|
||||
}
|
||||
|
||||
public static int getLength(AbstractBaseList list) {
|
||||
try {
|
||||
Class<?> cls = list.getClass();
|
||||
Field data = cls.getDeclaredField("data");
|
||||
if (!data.canAccess(list)) {
|
||||
data.setAccessible(true);
|
||||
}
|
||||
Object array = data.get(list);
|
||||
if (array == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return AbstractBaseList.UNSAFE.getInt(array, AbstractBaseList.OFFSET_LEN);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user