/** as {@link #valueOfIgnoreCase(String, Enum[], String)} for all values of the given enum and using the enum type as the message */ public static <T extends Enum<?>> Maybe<T> valueOfIgnoreCase(Class<T> type, String givenValue) { return valueOfIgnoreCase(JavaClassNames.simpleClassName(type), values(type), givenValue); }
/** as {@link #checkAllEnumeratedIgnoreCase(String, Enum[], String...)} using the same default strategy * that {@link #valueOfIgnoreCase(Class, String)} applies */ public static void checkAllEnumeratedIgnoreCase(Class<? extends Enum<?>> type, String ...explicitValues) { checkAllEnumeratedIgnoreCase(JavaClassNames.simpleClassName(type), values(type), explicitValues); } /** checks that all accepted enum values are represented by the given set of explicit values */
/** adds the given URL as something this classloader will load * (however no scanning is done). * <p> * the DTO will _not_ be updated. */ public void addToClasspath(ClassLoader loader) { classloader.addFirst(loader); }
/** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */ public static <T> Maybe<T> invokeConstructorFromArgsUntyped(ClassLoader classLoader, String className, Object...argsArray) { Reflections reflections = new Reflections(classLoader); @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>)reflections.loadClass(className); return invokeConstructorFromArgs(reflections, clazz, argsArray, false); }
/** returns nice class name and method for the caller, going up the stack (filtered to remove invocation etc), * with 0 typically being the context where this method is called, 1 being its caller, etc */ public static String callerNiceClassAndMethod(int depth) { return niceClassAndMethod(callerStackElement(depth)); }
/** As {@link #invokeConstructorFromArgs(Class, Object...)} but allowing more configurable input; * in particular setAccessible allows private constructors to be used (not the default) */ public static <T> Maybe<T> invokeConstructorFromArgs(ClassLoader classLoader, Class<T> clazz, Object[] argsArray, boolean setAccessible) { Reflections reflections = new Reflections(classLoader); return invokeConstructorFromArgs(reflections, clazz, argsArray, setAccessible); }
/** can be overridden to supply a simpler base name than the class name */ protected String toStringBaseName() { return JavaClassNames.simpleClassName(this); } /** can be overridden to supply add'l info for the {@link #toString()}; subclasses can add to the returned value */
@Override public String toString() { return JavaClassNames.cleanSimpleClassName(this); } }
/** forces all soft references to be cleared by trying to allocate an enormous chunk of memory, * returns a description of what was done * (tune with {@link #forceClearSoftReferences(long, int)} * for greater than 200M precision in the output message, if you really care about that) */ public static String forceClearSoftReferences() { return forceClearSoftReferences(1000*1000, Integer.MAX_VALUE); } /** as {@link #forceClearSoftReferences()} but gives control over headroom and max chunk size.
/** convenience for {@link #callerNiceClassAndMethod(int)} with depth 0 * <p> * useful for tests and other debug-facing log messages! */ public static String niceClassAndMethod() { return callerNiceClassAndMethod(0); }
/** creates default instance, with no classloaders (assuming this instance will itself be nested, * or defaults will be added by caller) */ public static AggregateClassLoader newInstanceWithNoLoaders() { return new AggregateClassLoader(); }
@Override public int compare(Class<?> c1, Class<?> c2) { Class<?> cS = Reflections.inferSubbest(c1, c2); return (cS==c1 ? -1 : cS==c2 ? 1 : 0); } }
/** Lists all public fields declared on the class or any ancestor, with those HIGHEST in the hierarchy first */ public static List<Field> findPublicFieldsOrderedBySuper(Class<?> clazz) { return findFields(clazz, new Predicate<Field>() { @Override public boolean apply(Field input) { return Modifier.isPublic(input.getModifiers()); }}, FieldOrderings.SUB_BEST_FIELD_LAST_THEN_DEFAULT); }
/** true iff all args match the corresponding types */ public static boolean typesMatch(Object[] argsArray, Class<?>[] parameterTypes, Optional<? extends TypeCoercer> coercer) { if (argsArray.length != parameterTypes.length) return false; return typesMatchUpTo(argsArray, parameterTypes, argsArray.length, coercer); }
@Override public void run() { runShutdownHooks(); } });
/** static convenience for {@link #clean(Iterable)} */ public static List<StackTraceElement> cleanStackTrace(Iterable<StackTraceElement> st) { return DEFAULT_INSTACE.clean(st); }
@Override public int compare(Method m1, Method m2) { Method msubbest = inferSubbestMethod(m1, m2); return (msubbest == null) ? 0 : (msubbest == m1 ? 1 : -1); }});
private int m2(int x) { if (x<=0) return -1; return m1(x-1); } @Test
@Override public String toString() { return JavaClassNames.cleanSimpleClassName(this)+"["+JavaClassNames.cleanSimpleClassName(type)+" "+value+"]"; } }
@Override public String toString() { return JavaClassNames.cleanSimpleClassName(this)+"["+kind+","+expectedSuperType+","+encounteredTypes+"]"; } }