congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
GroovyJavaMethods
Code IndexAdd Tabnine to your IDE (free)

How to use
GroovyJavaMethods
in
org.apache.brooklyn.util.groovy

Best Java code snippets using org.apache.brooklyn.util.groovy.GroovyJavaMethods (Showing top 20 results out of 315)

origin: org.apache.brooklyn/brooklyn-core

/**
 * @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) {
origin: org.apache.brooklyn/brooklyn-core

@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));
}
origin: org.apache.brooklyn/brooklyn-utils-groovy

@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);
  }
}
origin: org.apache.brooklyn/brooklyn-utils-groovy

public static <T> T elvis(Object... preferences) {
  try {
    if (preferences.length == 0) throw new IllegalArgumentException("preferences must not be empty for elvis");
    for (Object contender : preferences) {
      if (truth(contender)) return fix(contender);
    }
    return fix(preferences[preferences.length-1]);
  } catch (Throwable e) {
    throw Exceptions.propagate(e);
  }
}

origin: org.apache.brooklyn/brooklyn-core

/**
 * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
 */
@Deprecated
public static <T,V> Task<V> attributePostProcessedWhenReady(Entity source, AttributeSensor<T> sensor, Closure<Boolean> ready, Closure<V> postProcess) {
  Predicate<? super T> readyPredicate = (ready != null) ? GroovyJavaMethods.predicateFromClosure(ready) : JavaGroovyEquivalents.groovyTruthPredicate();
  Function<? super T, V> postProcessFunction = GroovyJavaMethods.<T,V>functionFromClosure(postProcess);
  return attributePostProcessedWhenReady(source, sensor, readyPredicate, postProcessFunction);
}
origin: org.apache.brooklyn/brooklyn-utils-groovy

@SuppressWarnings("unchecked")
public static <T> Closure<T> castToClosure(Object o) {
  try {
    if (ScriptBytecodeAdapter.compareEqual(o, null)) {
      return (Closure<T>)ScriptBytecodeAdapter.castToType(o, Closure.class);
    } else if (safeGroovyIsCase(o, Closure.class)) {
      return (Closure<T>)ScriptBytecodeAdapter.castToType(o, Closure.class);
    } else if (o instanceof Runnable) {
      return closureFromRunnable((Runnable)ScriptBytecodeAdapter.createPojoWrapper(ScriptBytecodeAdapter.castToType(o, Runnable.class), Runnable.class));
    } else if (o instanceof Callable) {
      return closureFromCallable((Callable<T>)ScriptBytecodeAdapter.createPojoWrapper(ScriptBytecodeAdapter.castToType(o, Callable.class), Callable.class));
    } else if (o instanceof Function) {
      return closureFromFunction((Function<Object, T>)ScriptBytecodeAdapter.createPojoWrapper(ScriptBytecodeAdapter.castToType(o, Function.class), Function.class));
    } else {
      throw new IllegalArgumentException("Cannot convert to closure: o="+o+"; type="+(o != null ? o.getClass() : null));
    }
  } catch (Throwable e) {
    throw Exceptions.propagate(e);
  }
}
origin: org.apache.brooklyn/brooklyn-utils-groovy

@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);
  }
}

origin: org.apache.brooklyn/brooklyn-utils-groovy

  @Override public boolean apply(Object input) {
    return truth(input);
  }
};
origin: org.apache.brooklyn/brooklyn-core

/**
 * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
 */
@Deprecated
public BasicTask(Closure<T> job) { this(GroovyJavaMethods.callableFromClosure(job)); }

origin: org.apache.brooklyn/brooklyn-utils-groovy

@Test
public void testElvis() {
  final List<?> emptyList = ImmutableList.of();
  final List<?> singletonList = ImmutableList.of("myVal");
  final List<?> differentList = ImmutableList.of("differentVal");
  
  assertEquals(elvis("", "string2"), "string2");
  assertEquals(elvis("string1", "string2"), "string1");
  assertEquals(elvis(null, "string2"), "string2");
  assertEquals(elvis("", "string2"), "string2");
  assertEquals((int)elvis(1, 2), 1);
  assertEquals((int)elvis(0, 2), 2);
  assertEquals(elvis(singletonList, differentList), singletonList);
  assertEquals(elvis(emptyList, differentList), differentList);
  assertEquals(elvis(gstring, "other"), gstringVal);
  assertEquals(elvis(emptyGstring, "other"), "other");
  assertEquals(elvis(emptyGstring, gstring), gstringVal);
}
origin: org.apache.brooklyn/brooklyn-utils-groovy

public static <T> T elvis(Object preferred, Object fallback) {
  try {
    return fix(truth(preferred) ? preferred : fallback);
  } catch (Throwable e) {
    throw Exceptions.propagate(e);
  }
}

origin: org.apache.brooklyn/brooklyn-utils-groovy

@SuppressWarnings("unchecked")
public static <T> Callable<T> callableFromRunnable(final Runnable job) {
  try {
    if (safeGroovyIsCase(job, Callable.class)) {
      return (Callable<T>)ScriptBytecodeAdapter.asType(job, Callable.class);
    } else {
      return CallableFromRunnable.newInstance(job, null);
    }
  } catch (Throwable e) {
    throw Exceptions.propagate(e);
  }
}
origin: org.apache.brooklyn/brooklyn-utils-groovy

  private <T> boolean groovyTruthInvocation(T value) throws Throwable {
    // We expect this to be equivalent to Groovy-Truth
    boolean result = org.apache.brooklyn.util.JavaGroovyEquivalents.groovyTruth(value);
    boolean groovyTruth = org.apache.brooklyn.util.groovy.GroovyJavaMethods.truth(value);
    assertEquals(result, groovyTruth, "value="+value);
    return result;
  }
}
origin: org.apache.brooklyn/brooklyn-core

/**
 * @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)); }
origin: org.apache.brooklyn/brooklyn-core

/**
 * @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) {
origin: org.apache.brooklyn/brooklyn-policy

/**
 * @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));
}

origin: org.apache.brooklyn/brooklyn-utils-groovy

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;
}
origin: org.apache.brooklyn/brooklyn-core

/**
 * @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;
}
origin: org.apache.brooklyn/brooklyn-software-base

/**
 * 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);
}
origin: org.apache.brooklyn/brooklyn-core

/**
 * @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" })
org.apache.brooklyn.util.groovyGroovyJavaMethods

Javadoc

Handy methods available in groovy packaged so they can be consumed from java, and other conversion/conveniences; but see JavaGroovyEquivalents for faster alternatives.

Most used methods

  • predicateFromClosure
  • functionFromClosure
  • safeGroovyIsCase
    Alternative implementation of ScriptBytecodeAdapter#isCase(Object,Object) Stripped down to work only
  • truth
  • callableFromClosure
  • closureFromCallable
  • closureFromFunction
  • closureFromRunnable
  • elvis
  • fix
  • getCallSiteArray
  • getCallSiteArray

Popular in Java

  • Reactive rest calls using spring rest template
  • getSystemService (Context)
  • getResourceAsStream (ClassLoader)
  • getSupportFragmentManager (FragmentActivity)
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now