// get purpose 1: access a list/array/map (safer version of x.get(y))
static A get(L l, int idx) {
ret l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
// seems to conflict with other signatures
/*static B get(Map map, A key) {
ret map != null ? map.get(key) : null;
}*/
static A get(A[] l, int idx) {
ret idx >= 0 && idx < l(l) ? l[idx] : null;
}
// default to false
static bool get(bool[] l, int idx) {
ret idx >= 0 && idx < l(l) ? l[idx] : false;
}
// get purpose 2: access a field by reflection or a map
static Object get(Object o, String field) {
try {
if (o == null) null;
if (o instanceof Class) return get((Class) o, field);
if (o instanceof Map)
ret ((Map) o).get(field);
Field f = getOpt_findField(o.getClass(), field);
if (f != null) {
makeAccessible(f);
ret f.get(o);
}
ifclass DynamicObject
if (o cast DynamicObject)
ret getOptDynOnly(o, field);
endif
} catch (Exception e) {
throw asRuntimeException(e);
}
throw new RuntimeException("Field '" + field + "' not found in " + o.getClass().getName());
}
sO mapMethodLike get_raw(S field, O o) {
ret get_raw(o, field);
}
static Object get_raw(Object o, String field) ctex {
if (o == null) null;
Field f = get_findField(o.getClass(), field);
makeAccessible(f);
ret f.get(o);
}
static Object get(Class c, String field) {
try {
Field f = get_findStaticField(c, field);
makeAccessible(f);
return f.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static Field get_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields())
if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
static Field get_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields())
if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
static O mapMethodLike get(S field, O o) {
ret get(o, field);
}
sbool get(BitSet bs, int idx) {
ret bs != null && bs.get(idx);
}