@Override public boolean apply(Object input) { return truth(input); } };
public static <T> Closure<T> closureFromRunnable(final Runnable job) { return new FromRunnableClosure<T>(GroovyJavaMethods.class, job); }
public static <T> Closure<T> closureFromCallable(final Callable<T> job) { return new FromCallableClosure<T>(GroovyJavaMethods.class, job); }
@SuppressWarnings("unchecked") public static <T> Predicate<T> castToPredicate(Object o) { try { if (safeGroovyIsCase(o, Closure.class)) { return predicateFromClosure((Closure<Boolean>)o); } else { return (Predicate<T>) o; } } catch (Throwable e) { throw Exceptions.propagate(e); } }
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated public Builder<T,V> readiness(Closure<Boolean> val) { this.readiness = GroovyJavaMethods.predicateFromClosure(checkNotNull(val, "val")); return this; } public Builder<T,V> readiness(Predicate<? super T> val) {
@SuppressWarnings("unchecked") @Deprecated /** @deprecated since 0.7.0 use Function */ public NamedActionWithUrl(String actionName, Closure<String> postProcessing) { this.actionName = actionName; this.postProcessing = (Function<T, String>) ((postProcessing == null) ? null : GroovyJavaMethods.functionFromClosure(postProcessing)); }
@SuppressWarnings("unchecked") public static <T> T fix(Object o) { try { if (safeGroovyIsCase(o, GString.class)) { return (T)ScriptBytecodeAdapter.asType(o, String.class); } else { return (T)o; } } catch (Throwable e) { throw Exceptions.propagate(e); } }
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated public BasicTask(Closure<T> job) { this(GroovyJavaMethods.callableFromClosure(job)); }
public static <T> Closure<T> closureFromFunction(final Function<?,T> job) { return new FromFunctionClosure<T>(GroovyJavaMethods.class, job); }
@SuppressWarnings("unchecked") public static <T> T invokeMethodOnMetaClass(Object target, String methodName, Object args) { try { CallSite[] callSiteArray = getCallSiteArray(); Object metaClass = callSiteArray[0].callGetProperty(target); return (T) callSiteArray[1].call(metaClass, target, methodName, args); } catch (Throwable e) { throw Exceptions.propagate(e); } }
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated public static List<Class<?>> getAllAssignableTypes(Class<?> base, Closure<Boolean> filter) { return getAllAssignableTypes(base, GroovyJavaMethods.<Class<?>>predicateFromClosure(filter)); } public static List<Class<?>> getAllAssignableTypes(Class<?> base, Predicate<Class<?>> filter) {
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted; also use {@link EnricherSpec} */ @Deprecated public TimeWeightedDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double> target, int unitMillis, Closure<Double> postProcessor) { this(producer, source, target, unitMillis, GroovyJavaMethods.<Double,Double>functionFromClosure(postProcessor)); }
private boolean groovyIsCaseInvocation(Object switchValue, Class<?> caseExpression) throws Throwable { // We expect this to be equivalent to: // org.codehaus.groovy.runtime.ScriptBytecodeAdapter.isCase(switchValue, caseExpression); boolean result = org.apache.brooklyn.util.groovy.GroovyJavaMethods.safeGroovyIsCase(switchValue, caseExpression); boolean equiv = org.codehaus.groovy.runtime.ScriptBytecodeAdapter.isCase(switchValue, caseExpression); assertEquals(result, equiv, "switchValue="+switchValue+"; caseExpression="+caseExpression); return result; }
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated public BasicTask(Map<?,?> flags, Closure<T> job) { this(flags, GroovyJavaMethods.callableFromClosure(job)); }
/** * Takes a closure which accepts this ScriptHelper and returns true or false * as to whether the script needs to run (or can throw error if desired) * * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated @SuppressWarnings({ "rawtypes", "unchecked" }) public ScriptHelper executeIf(Closure c) { Predicate<ScriptHelper> predicate = GroovyJavaMethods.predicateFromClosure(c); return executeIf(predicate); }
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated @SuppressWarnings({ "unchecked", "rawtypes" }) public <V2> Builder<T,V2> postProcess(Closure<V2> val) { this.postProcess = (Function) GroovyJavaMethods.<T,V2>functionFromClosure(checkNotNull(val, "postProcess")); return (Builder<T,V2>) this; } @SuppressWarnings({ "unchecked", "rawtypes" })
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated public FunctionPollConfig<S, T> closure(Closure<?> val) { this.callable = GroovyJavaMethods.callableFromClosure(checkNotNull(val, "closure")); return this; }
/** * @see #transformMultiple(Function, TaskAdaptable...) * * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated @SuppressWarnings({ "unchecked", "rawtypes" }) public static <U,T> Task<T> transformMultiple(Map flags, Closure transformer, TaskAdaptable<U> ...tasks) { return transformMultiple(flags, GroovyJavaMethods.functionFromClosure(transformer), tasks); }
/** * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted. */ @Deprecated public static <T,V> Task<V> attributePostProcessedWhenReady(final Entity source, final AttributeSensor<T> sensor, final Predicate<? super T> ready, final Closure<V> postProcess) { return attributePostProcessedWhenReady(source, sensor, ready, GroovyJavaMethods.<T,V>functionFromClosure(postProcess)); }