本文整理汇总了Java中org.apache.commons.collections.Closure类的典型用法代码示例。如果您正苦于以下问题:Java Closure类的具体用法?Java Closure怎么用?Java Closure使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Closure类属于org.apache.commons.collections包,在下文中一共展示了Closure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVolumeProductsFromVhds
import org.apache.commons.collections.Closure; //导入依赖的package包/类
private ArrayList<VolumeProduct> getVolumeProductsFromVhds() throws CloudException {
WAPVhdsModel wapVhdsModel =
new AzurePackRequester(this.getProvider(), new AzurePackVolumeRequests(this.getProvider()).listVirtualDisks().build()).withJsonProcessor(WAPVhdsModel.class).execute();
final ArrayList<VolumeProduct> volumes = new ArrayList<>();
CollectionUtils.forAllDo(wapVhdsModel.getVhds(), new Closure() {
@Override
public void execute(Object input) {
WAPVhdModel wapVhdModel = (WAPVhdModel)input;
if(wapVhdModel.getOperatingSystem().equalsIgnoreCase("none")) {
volumes.add(VolumeProduct.getInstance(wapVhdModel.getId(), wapVhdModel.getName(),
wapVhdModel.getName(),
VolumeType.HDD,
new Storage<Megabyte>(Integer.parseInt(wapVhdModel.getSize()), Storage.MEGABYTE)));
}
}
});
return volumes;
}
示例2: getVolumesFromVMs
import org.apache.commons.collections.Closure; //导入依赖的package包/类
private ArrayList<Volume> getVolumesFromVMs() throws CloudException {
WAPVirtualMachinesModel virtualMachinesModel =
new AzurePackRequester(this.getProvider(), new AzurePackVolumeRequests(this.getProvider()).listVMsWithVDD().build())
.withJsonProcessor(WAPVirtualMachinesModel.class).execute();
final ArrayList<Volume> volumes = new ArrayList<>();
CollectionUtils.forAllDo(virtualMachinesModel.getVirtualMachines(), new Closure() {
@Override
public void execute(Object input) {
WAPVirtualMachineModel virtualMachineModel = (WAPVirtualMachineModel)input;
for (WAPDiskDriveModel wapDiskDriveModel : virtualMachineModel.getVirtualDiskDrives()) {
volumes.add(volumeFrom(wapDiskDriveModel, virtualMachineModel.getId()));
}
}
});
return volumes;
}
示例3: listVlans
import org.apache.commons.collections.Closure; //导入依赖的package包/类
@Override
public @Nonnull Iterable<VLAN> listVlans() throws CloudException, InternalException {
HttpUriRequest listNetworksRequest = new AzurePackNetworkRequests(provider).listVMNetworks().build();
return new AzurePackRequester(provider, listNetworksRequest).withJsonProcessor(new DriverToCoreMapper<WAPVMNetworksModel, List<VLAN>>() {
@Override
public List<VLAN> mapFrom(WAPVMNetworksModel entity) {
final ArrayList<VLAN> vlans = new ArrayList<VLAN>();
CollectionUtils.forAllDo(entity.getVirtualMachineNetworks(), new Closure() {
@Override
public void execute(Object input) {
vlans.add(vlanFrom((WAPVMNetworkModel) input));
}
});
return vlans;
}
}, WAPVMNetworksModel.class).execute();
}
示例4: listRegions
import org.apache.commons.collections.Closure; //导入依赖的package包/类
@Override
public Collection<Region> listRegions() throws InternalException, CloudException {
HttpUriRequest httpUriRequest = new AzurePackDataCenterRequests(provider).listClouds().build();
WAPCloudsModel result = new AzurePackRequester(provider, httpUriRequest).withJsonProcessor(WAPCloudsModel.class).execute();
final List<Region> regions = new ArrayList<Region>();
CollectionUtils.forAllDo(result.getClouds(), new Closure() {
@Override
public void execute(Object input) {
WAPCloudModel cloudModel = (WAPCloudModel) input;
Region region = new Region();
region.setName(cloudModel.getName());
region.setProviderRegionId(cloudModel.getId());
region.setActive(true);
region.setAvailable(true);
region.setJurisdiction("US");
regions.add(region);
}
});
return regions;
}
示例5: assertHttpMethod
import org.apache.commons.collections.Closure; //导入依赖的package包/类
private static void assertHttpMethod(final HttpUriRequest actualHttpRequest, String expectedHttpMethod, String expectedUrl, Header[] expectedHeaders)
{
assertHttpMethod(actualHttpRequest, expectedHttpMethod, expectedUrl);
assertNotNull(actualHttpRequest.getAllHeaders());
CollectionUtils.forAllDo(Arrays.asList(expectedHeaders), new Closure() {
@Override
public void execute(Object input) {
final Header expectedHeader = (Header) input;
boolean headerExists = CollectionUtils.exists(Arrays.asList(actualHttpRequest.getAllHeaders()), new Predicate() {
@Override
public boolean evaluate(Object object) {
Header actualHeader = (Header) object;
return expectedHeader.getName().equals(actualHeader.getName()) && expectedHeader.getValue().equals(actualHeader.getValue());
}
});
assertTrue(String.format("Expected %s header not found in the request or found with the wrong value in the request", expectedHeader.getName()), headerExists);
}
});
}
示例6: findProvider_shouldReturnTheListOfProvidersMatchingTheSearchName
import org.apache.commons.collections.Closure; //导入依赖的package包/类
/**
* @see DWRProviderService#findProvider(String,boolean,Integer,Integer)
* @verifies return the list of providers matching the search name
*/
@Test
public void findProvider_shouldReturnTheListOfProvidersMatchingTheSearchName() throws Exception {
Vector<Object> providers = service.findProvider("provider", false, 0, 10);
Assert.assertEquals(2, providers.size());
final ArrayList<String> providerNames = new ArrayList<String>();
CollectionUtils.forAllDo(providers, new Closure() {
@Override
public void execute(Object input) {
providerNames.add(((ProviderListItem) input).getDisplayName());
}
});
Assert.assertTrue(providerNames.containsAll(Arrays.asList("Bruno Otterbourg", "Hippocrates of Cos")));
}
示例7: testGetNames
import org.apache.commons.collections.Closure; //导入依赖的package包/类
@Test
public void testGetNames() throws Exception {
final InputStream is = getClass().getResourceAsStream(personalXsd);
assertNotNull(is);
final StreamSource source = new StreamSource(is);
final XmlSchema schema = new XmlSchemaCollection().read(source);
assertNotNull(schema);
final Collection<QName> elements = SchemaUtil.getElements(schema);
assertNotNull(elements);
assertFalse(elements.isEmpty());
System.out.println("Got the following elements from schema:");
CollectionUtils.forAllDo(elements, new Closure() {
@Override
public void execute(Object input) {
System.out.println(input);
}
});
}
示例8: onConfigChange
import org.apache.commons.collections.Closure; //导入依赖的package包/类
public void onConfigChange(CruiseConfig newCruiseConfig) {
LOGGER.info("[Configuration Changed] Removing jobs for pipelines that no longer exist in configuration.");
synchronized (this) {
List<JobPlan> jobsToRemove = new ArrayList<>();
for (JobPlan jobPlan : jobPlans) {
if (!newCruiseConfig.hasBuildPlan(new CaseInsensitiveString(jobPlan.getPipelineName()), new CaseInsensitiveString(jobPlan.getStageName()), jobPlan.getName(), true)) {
jobsToRemove.add(jobPlan);
}
}
forAllDo(jobsToRemove, new Closure() {
@Override
public void execute(Object o) {
removeJob((JobPlan) o);
}
});
}
}
示例9: indexCollection
import org.apache.commons.collections.Closure; //导入依赖的package包/类
/**
* Indexes a collection by creating a map that allows each element of the
* specified collection to be looked up by its key. The key of each element is
* determined by calling the <code>makeKey</code> Transformer on that
* element. I sure miss Lisp.
*
* @return a Map
*/
public static <K, E> Map<K,E> indexCollection(Collection c,
final Transformer getKey,
Class<K> keyClass,
Class<E> elementClass)
{
final Map<K,E> map = new HashMap<K,E>(c.size());
org.apache.commons.collections.CollectionUtils.forAllDo(c, new Closure() {
@SuppressWarnings("unchecked")
public void execute(Object e)
{
map.put((K) getKey.transform(e), (E) e);
}
});
return map;
}
示例10: applyForSelectedChanges
import org.apache.commons.collections.Closure; //导入依赖的package包/类
/**
* Calls the given closure for all changes that are of one of the given types, and
* then removes them from the changes collection.
*
* @param changes The changes
* @param changeTypes The types to search for
* @param closure The closure to invoke
*/
protected void applyForSelectedChanges(Collection changes, Class[] changeTypes, final Closure closure)
{
final Predicate predicate = new MultiInstanceofPredicate(changeTypes);
// basically we filter the changes for all objects where the above predicate
// returns true, and for these filtered objects we invoke the given closure
CollectionUtils.filter(changes,
new Predicate()
{
public boolean evaluate(Object obj)
{
if (predicate.evaluate(obj))
{
closure.execute(obj);
return false;
}
else
{
return true;
}
}
});
}
示例11: setSelectAll
import org.apache.commons.collections.Closure; //导入依赖的package包/类
public void setSelectAll(boolean selectAll) {
this.selectAll = selectAll;
if (this.triggerProcessList != null) {
final boolean isSelectAll = this.isSelectAll();
CollectionUtils.forAllDo(this.triggerProcessList, new Closure() {
@Override
public void execute(Object tp) {
((TriggerProcess) tp).setSelected(isSelectAll);
}
});
}
}
示例12: RepositoryScannerInstance
import org.apache.commons.collections.Closure; //导入依赖的package包/类
public RepositoryScannerInstance( ManagedRepository repository,
List<KnownRepositoryContentConsumer> knownConsumerList,
List<InvalidRepositoryContentConsumer> invalidConsumerList )
{
this.repository = repository;
this.knownConsumers = knownConsumerList;
this.invalidConsumers = invalidConsumerList;
consumerTimings = new HashMap<>();
consumerCounts = new HashMap<>();
this.consumerProcessFile = new ConsumerProcessFileClosure();
consumerProcessFile.setExecuteOnEntireRepo( true );
consumerProcessFile.setConsumerTimings( consumerTimings );
consumerProcessFile.setConsumerCounts( consumerCounts );
this.consumerWantsFile = new ConsumerWantsFilePredicate( repository );
stats = new RepositoryScanStatistics();
stats.setRepositoryId( repository.getId() );
Closure triggerBeginScan =
new TriggerBeginScanClosure( repository, new Date( System.currentTimeMillis() ), true );
CollectionUtils.forAllDo( knownConsumerList, triggerBeginScan );
CollectionUtils.forAllDo( invalidConsumerList, triggerBeginScan );
if ( SystemUtils.IS_OS_WINDOWS )
{
consumerWantsFile.setCaseSensitive( false );
}
}
示例13: directoryWalkStep
import org.apache.commons.collections.Closure; //导入依赖的package包/类
@Override
public void directoryWalkStep( int percentage, File file )
{
log.debug( "Walk Step: {}, {}", percentage, file );
stats.increaseFileCount();
// consume files regardless - the predicate will check the timestamp
BaseFile basefile = new BaseFile( repository.getLocation(), file );
// Timestamp finished points to the last successful scan, not this current one.
if ( file.lastModified() >= changesSince )
{
stats.increaseNewFileCount();
}
consumerProcessFile.setBasefile( basefile );
consumerWantsFile.setBasefile( basefile );
Closure processIfWanted = IfClosure.getInstance( consumerWantsFile, consumerProcessFile );
CollectionUtils.forAllDo( this.knownConsumers, processIfWanted );
if ( consumerWantsFile.getWantedFileCount() <= 0 )
{
// Nothing known processed this file. It is invalid!
CollectionUtils.forAllDo( this.invalidConsumers, consumerProcessFile );
}
}
示例14: up
import org.apache.commons.collections.Closure; //导入依赖的package包/类
private IntakeNode up(IntakeNode node, Closure closure) {
//if(node == null)
IntakeNode root = node;
while (root.getParent() != null) {
closure.execute(root);
root = root.getParent();
}
return root;
}
示例15: down
import org.apache.commons.collections.Closure; //导入依赖的package包/类
private void down(List<IntakeNode> children, Closure closure) {
for (IntakeNode child : children) {
if (child != null) {
closure.execute(child);
down(child.getChildren(), closure);
}
}
}