2026-03-17 13:31:18 -07:00

153 lines
4.2 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package com.tridium.util;
import java.util.LinkedList;
import javax.baja.sys.BObject;
import javax.baja.sys.Type;
public abstract class ClassUtil {
public static Class[] classes(Object[] objectArray) {
Class[] classArray = new Class[objectArray.length];
int n = 0;
while (n < objectArray.length) {
classArray[n] = objectArray[n].getClass();
++n;
}
return classArray;
}
public static Class baseClass(Class[] classArray) {
LinkedList[] linkedListArray = new LinkedList[classArray.length];
int n = 0;
while (n < classArray.length) {
linkedListArray[n] = new LinkedList();
Class clazz = classArray[n];
while (clazz != null) {
linkedListArray[n].addFirst(clazz);
clazz = clazz.getSuperclass();
}
++n;
}
Class clazz = (Class)linkedListArray[0].get(0);
block2: for (int i = 0; i != linkedListArray[0].size(); ++i) {
Class clazz2 = (Class)linkedListArray[0].get(i);
int n2 = 1;
while (n2 < linkedListArray.length) {
if (i == linkedListArray[n2].size() || !clazz2.equals((Class)linkedListArray[n2].get(i))) break block2;
++n2;
}
clazz = clazz2;
}
return clazz;
}
public static boolean all(Object[] objectArray, Class clazz) {
int n = 0;
while (n < objectArray.length) {
if (objectArray[n] == null) {
return false;
}
if (!clazz.isAssignableFrom(objectArray[n].getClass())) {
return false;
}
++n;
}
return true;
}
public static boolean any(Object[] objectArray, Class clazz) {
int n = 0;
while (n < objectArray.length) {
if (objectArray[n] != null && clazz.isAssignableFrom(objectArray[n].getClass())) {
return true;
}
++n;
}
return false;
}
public static boolean allNull(Object[] objectArray) {
int n = 0;
while (n < objectArray.length) {
if (objectArray[n] != null) {
return false;
}
++n;
}
return true;
}
public static boolean anyNull(Object[] objectArray) {
int n = 0;
while (n < objectArray.length) {
if (objectArray[n] == null) {
return true;
}
++n;
}
return false;
}
public static boolean sameClass(Object[] objectArray) {
if (objectArray[0] == null) {
return false;
}
Class<?> clazz = objectArray[0].getClass();
int n = 1;
while (n < objectArray.length) {
if (objectArray[n] == null) {
return false;
}
if (!clazz.equals(objectArray[n].getClass())) {
return false;
}
++n;
}
return true;
}
public static Type getCommonSuperType(BObject[] bObjectArray) {
Type[] typeArray = new Type[bObjectArray.length];
int n = 0;
while (n < bObjectArray.length) {
typeArray[n] = bObjectArray[n].getType();
++n;
}
return ClassUtil.getCommonSuperType(typeArray);
}
public static Type getCommonSuperType(Type[] typeArray) {
if (typeArray.length == 1) {
return typeArray[0];
}
int n = 0;
while (n < typeArray.length) {
if (typeArray[n].isInterface()) {
return BObject.TYPE;
}
++n;
}
Type type = typeArray[0];
while (type != BObject.TYPE) {
boolean bl = true;
int n2 = 1;
while (n2 < typeArray.length) {
if (!typeArray[n2].is(type)) {
bl = false;
break;
}
++n2;
}
if (bl) {
return type;
}
if ((type = type.getSuperType()) != null) continue;
return BObject.TYPE;
}
return BObject.TYPE;
}
}