groovy.lang.Closure Java Examples
The following examples show how to use
groovy.lang.Closure.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Node.java From groovy with Apache License 2.0 | 6 votes |
private void breadthFirstRest(boolean preorder, int level, Closure c) { Stack<Tuple2<Object, Integer>> stack = new Stack<Tuple2<Object, Integer>>(); List nextLevelChildren = preorder ? getDirectChildren() : DefaultGroovyMethods.reverse(getDirectChildren()); while (!nextLevelChildren.isEmpty()) { List working = new NodeList(nextLevelChildren); nextLevelChildren = new NodeList(); for (Object child : working) { if (preorder) { callClosureForNode(c, child, level); } else { stack.push(new Tuple2<Object, Integer>(child, level)); } if (child instanceof Node) { Node childNode = (Node) child; List children = childNode.getDirectChildren(); if (children.size() > 1 || (children.size() == 1 && !(children.get(0) instanceof String))) nextLevelChildren.addAll(preorder ? children : DefaultGroovyMethods.reverse(children)); } } level++; } while (!stack.isEmpty()) { Tuple2<Object, Integer> next = stack.pop(); callClosureForNode(c, next.getV1(), next.getV2()); } }
Example #2
Source File: DefaultRepositoryHandler.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public DependencyResolver mavenRepo(Map<String, ?> args, Closure configClosure) { DeprecationLogger.nagUserOfReplacedMethod("RepositoryHandler.mavenRepo()", "maven()"); Map<String, Object> modifiedArgs = new HashMap<String, Object>(args); if (modifiedArgs.containsKey("urls")) { List<?> urls = flattenCollections(modifiedArgs.remove("urls")); if (!urls.isEmpty()) { modifiedArgs.put("url", urls.get(0)); List<?> extraUrls = urls.subList(1, urls.size()); modifiedArgs.put("artifactUrls", extraUrls); } } MavenArtifactRepository repository = repositoryFactory.createMavenRepository(); ConfigureUtil.configureByMap(modifiedArgs, repository); DependencyResolver resolver = repositoryFactory.toResolver(repository); ConfigureUtil.configure(configClosure, resolver); addRepository(repositoryFactory.createResolverBackedRepository(resolver), "mavenRepo"); return resolver; }
Example #3
Source File: Continuable.java From groovy-cps with Apache License 2.0 | 6 votes |
/** * Resumes this program by either returning the value from {@link Continuable#suspend(Object)} or * throwing an exception */ public Outcome run0(final Outcome cn, List<Class> categories) { return GroovyCategorySupport.use(categories, new Closure<Outcome>(null) { @Override public Outcome call() { Next n = cn.resumeFrom(e,k); while(n.yield==null) { if (interrupt!=null) { // TODO: correctly reporting a source location requires every block to have the line number n = new Next(new ThrowBlock(UNKNOWN, new ConstantBlock(interrupt), true),n.e,n.k); interrupt = null; } n = n.step(); } e = n.e; k = n.k; return n.yield; } }); }
Example #4
Source File: DefaultPolymorphicDomainObjectContainer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public <U extends T> void registerFactory(Class<U> type, final Closure<? extends U> factory) { registerFactory(type, new NamedDomainObjectFactory<U>() { public U create(String name) { return factory.call(name); } }); }
Example #5
Source File: Contract.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
/** * Groovy point of entry to build a contract. Left for backward compatibility reasons. * @param closure function to manipulate the contract * @return manipulated contract */ public static Contract make(@DelegatesTo(Contract.class) Closure closure) { Contract dsl = new Contract(); closure.setDelegate(dsl); closure.call(); Contract.assertContract(dsl); return dsl; }
Example #6
Source File: BaseDispatchClosure.java From arcusplatform with Apache License 2.0 | 5 votes |
protected void addHandler(MessageType messageType, String event, String parameter, Closure<?> closure) { IpcdDispatchMatcher matcher = new IpcdDispatchMatcher(); matcher.setType(messageType); matcher.setEvent(event); matcher.setParameter(parameter); matcher.setHandler(DriverBinding.wrapAsHandler(closure)); binding.getBuilder().addEventMatcher(matcher); }
Example #7
Source File: DefaultManifest.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public DefaultManifest from(Object mergePaths, Closure closure) { DefaultManifestMergeSpec mergeSpec = new DefaultManifestMergeSpec(); mergeSpec.from(mergePaths); manifestMergeSpecs.add(mergeSpec); ConfigureUtil.configure(closure, mergeSpec); return this; }
Example #8
Source File: TaskFactory.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public TaskInternal createTask(Map<String, ?> args) { Map<String, Object> actualArgs = new HashMap<String, Object>(args); checkTaskArgsAndCreateDefaultValues(actualArgs); String name = actualArgs.get(Task.TASK_NAME).toString(); if (!GUtil.isTrue(name)) { throw new InvalidUserDataException("The task name must be provided."); } Class<? extends TaskInternal> type = (Class) actualArgs.get(Task.TASK_TYPE); Boolean generateSubclass = Boolean.valueOf(actualArgs.get(GENERATE_SUBCLASS).toString()); TaskInternal task = createTaskObject(project, type, name, generateSubclass); Object dependsOnTasks = actualArgs.get(Task.TASK_DEPENDS_ON); if (dependsOnTasks != null) { task.dependsOn(dependsOnTasks); } Object description = actualArgs.get(Task.TASK_DESCRIPTION); if (description != null) { task.setDescription(description.toString()); } Object group = actualArgs.get(Task.TASK_GROUP); if (group != null) { task.setGroup(group.toString()); } Object action = actualArgs.get(Task.TASK_ACTION); if (action instanceof Action) { Action<? super Task> taskAction = (Action<? super Task>) action; task.doFirst(taskAction); } else if (action != null) { Closure closure = (Closure) action; task.doFirst(closure); } return task; }
Example #9
Source File: Test.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public TestFramework testFramework(Closure testFrameworkConfigure) { if (testFramework == null) { useJUnit(testFrameworkConfigure); } return testFramework; }
Example #10
Source File: DependentConfiguration.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** * @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); }
Example #11
Source File: DefaultDependencyFactory.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public ClientModule createModule(Object dependencyNotation, Closure configureClosure) { ClientModule clientModule = clientModuleNotationParser.parseNotation(dependencyNotation); ModuleFactoryDelegate moduleFactoryDelegate = new ModuleFactoryDelegate(clientModule, this); moduleFactoryDelegate.prepareDelegation(configureClosure); if (configureClosure != null) { configureClosure.call(); } return clientModule; }
Example #12
Source File: StringGroovyMethodsTest.java From groovy with Apache License 2.0 | 5 votes |
private Closure<String> createClosureForFindOrFindAll() { return new Closure<String>(this) { @Override public String call(Object arguments) { assertTrue(arguments instanceof List); return ((List) arguments).get(2).toString(); } @Override public String call(Object... args) { return call((Object) args); } }; }
Example #13
Source File: IOGroovyMethods.java From groovy with Apache License 2.0 | 5 votes |
/** * Filter the lines from this Reader, and return a Writable which can be * used to stream the filtered lines to a destination. The closure should * return <code>true</code> if the line should be passed to the writer. * * @param reader this reader * @param closure a closure used for filtering * @return a Writable which will use the closure to filter each line * from the reader when the Writable#writeTo(Writer) is called. * @since 1.0 */ public static Writable filterLine(Reader reader, @ClosureParams(value=SimpleType.class, options="java.lang.String") final Closure closure) { final BufferedReader br = new BufferedReader(reader); return new Writable() { public Writer writeTo(Writer out) throws IOException { BufferedWriter bw = new BufferedWriter(out); String line; BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure); while ((line = br.readLine()) != null) { if (bcw.call(line)) { bw.write(line); bw.newLine(); } } bw.flush(); return out; } public String toString() { Writer buffer = new StringBuilderWriter(); try { writeTo(buffer); } catch (IOException e) { throw new StringWriterIOException(e); } return buffer.toString(); } }; }
Example #14
Source File: DefaultCopySpec.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public CopySpec filter(final Closure closure) { actions.add(new Action<FileCopyDetails>() { public void execute(FileCopyDetails fileCopyDetails) { fileCopyDetails.filter(closure); } }); return this; }
Example #15
Source File: ProGuardTask.java From bazel with Apache License 2.0 | 5 votes |
public void keepclassmembers(Map keepClassSpecificationArgs, Closure classMembersClosure) throws ParseException { configuration.keep = extendClassSpecifications(configuration.keep, createKeepClassSpecification(false, false, false, keepClassSpecificationArgs, classMembersClosure)); }
Example #16
Source File: OSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
protected void setDefaultLocale(Locale locale) throws Exception { assertThat(locale, is(notNullValue())); ConfigurationAdmin configAdmin = (ConfigurationAdmin) getService( Class.forName("org.osgi.service.cm.ConfigurationAdmin")); assertThat(configAdmin, is(notNullValue())); LocaleProvider localeProvider = (LocaleProvider) getService( Class.forName("org.eclipse.smarthome.core.i18n.LocaleProvider")); assertThat(localeProvider, is(notNullValue())); Configuration config = configAdmin.getConfiguration("org.eclipse.smarthome.core.i18nprovider", null); assertThat(config, is(notNullValue())); Dictionary<String, Object> properties = config.getProperties(); if (properties == null) { properties = new Hashtable<>(); } properties.put("language", locale.getLanguage()); properties.put("script", locale.getScript()); properties.put("region", locale.getCountry()); properties.put("variant", locale.getVariant()); config.update(properties); waitForAssert(new Closure<Object>(null) { private static final long serialVersionUID = -5083904877474902686L; public Object doCall() { assertThat(localeProvider.getLocale(), is(locale)); return null; } }); }
Example #17
Source File: AbstractGradleExecuter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public void afterExecute(Closure action) { afterExecute.add(new ClosureBackedAction<GradleExecuter>(action)); }
Example #18
Source File: DefaultSourceSet.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public SourceSet java(Closure configureClosure) { ConfigureUtil.configure(configureClosure, getJava()); return this; }
Example #19
Source File: DefaultDomainObjectCollection.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
protected <S extends Collection<? super T>> S findAll(Closure cl, S matches) { for (T t : filteredStore(createFilter(Specs.<Object>convertClosureToSpec(cl)))) { matches.add(t); } return matches; }
Example #20
Source File: TestCaseScript.java From mdw with Apache License 2.0 | 4 votes |
public TestCaseActivityStub activity(Closure<Boolean> matcher, Closure<String> completer) throws TestException { return new TestCaseActivityStub(matcher, completer); }
Example #21
Source File: ClosureStaticMetaMethod.java From groovy with Apache License 2.0 | 4 votes |
public ClosureStaticMetaMethod(String name, Class declaringClass, Closure c, Class[] paramTypes) { super(paramTypes); this.callable = c; this.declaringClass = ReflectionCache.getCachedClass(declaringClass); this.name = name; }
Example #22
Source File: DelegatingDomainObjectSet.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public DomainObjectSet<T> matching(Closure spec) { return backingSet.matching(spec); }
Example #23
Source File: AbstractPolymorphicDomainObjectContainer.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
private boolean isConfigureMethod(String name, Object... arguments) { return (arguments.length == 1 && arguments[0] instanceof Closure || arguments.length == 1 && arguments[0] instanceof Class || arguments.length == 2 && arguments[0] instanceof Class && arguments[1] instanceof Closure) && hasProperty(name); }
Example #24
Source File: VisitAssertHook.java From kan-java with Eclipse Public License 1.0 | 4 votes |
void afterVisitDetail(AssertTree node, List<ErrMsg> errMsgs, GlobalContext ctx, Closure<List<Map<String, Long>>> resolveRowAndCol, Closure<Void> setError);
Example #25
Source File: Tt1cgo.java From groovy with Apache License 2.0 | 4 votes |
public Closure getX() { return this.p1; }
Example #26
Source File: ComposedClosure.java From groovy with Apache License 2.0 | 4 votes |
public void setResolveStrategy(int resolveStrategy) { ((Closure) getOwner()).setResolveStrategy(resolveStrategy); second.setResolveStrategy(resolveStrategy); }
Example #27
Source File: DefaultComponentSelectionRules.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public ComponentSelectionRules all(Closure<?> closure) { return addRule(createAllSpecRulesAction(ruleActionAdapter.createFromClosure(ComponentSelection.class, closure))); }
Example #28
Source File: FactoryBuilderSupport.java From groovy with Apache License 2.0 | 4 votes |
/** * @return the explicit methods map (Unmodifiable Map). */ public Map<String, Closure> getLocalExplicitMethods() { return Collections.unmodifiableMap(explicitMethods); }
Example #29
Source File: DefaultResolutionResult.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public void allDependencies(final Closure closure) { allDependencies(new ClosureBackedAction<DependencyResult>(closure)); }
Example #30
Source File: WarOverlay.java From gradle-plugins with MIT License | 4 votes |
public CopySpec include(Closure includeSpec) { return getWarCopySpec().include(includeSpec); }