Java 类org.apache.commons.collections.Closure 实例源码

项目:dasein-cloud-azurepack    文件:AzurePackVolumeSupport.java   
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;
}
项目:dasein-cloud-azurepack    文件:AzurePackVolumeSupport.java   
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;
}
项目:dasein-cloud-azurepack    文件:AzurePackNetworkSupport.java   
@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();
}
项目:dasein-cloud-azurepack    文件:AzurePackDataCenterService.java   
@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;
}
项目:dasein-cloud-azurepack    文件:HttpMethodAsserts.java   
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);
        }
    });
}
项目:openmrs-module-legacyui    文件:DWRProviderServiceTest.java   
/**
 * @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")));
}
项目:xsd2xml    文件:SchemaUtilTest.java   
@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);
        }
    });

}
项目:gocd    文件:BuildAssignmentService.java   
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);
            }
        });
    }
}
项目:screensaver    文件:CollectionUtils.java   
/**
 * 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;
}
项目:apache-ddlutils    文件:SqlBuilder.java   
/**
 * 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;
                                   }
                               }
                           });
}
项目:oscm    文件:TriggerProcessBean.java   
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);
            }
        });
    }
}
项目:apache-archiva    文件:RepositoryScannerInstance.java   
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 );
    }
}
项目:apache-archiva    文件:RepositoryScannerInstance.java   
@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 );
    }
}
项目:OSCAR-ConCert    文件:IntakeNodeWalker.java   
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;
}
项目:OSCAR-ConCert    文件:IntakeNodeWalker.java   
private void down(List<IntakeNode> children, Closure closure) {
    for (IntakeNode child : children) {
        if (child != null) {
            closure.execute(child);
            down(child.getChildren(), closure);
        }
    }
}
项目:development    文件:TriggerProcessBean.java   
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);
            }
        });
    }
}
项目:dasein-cloud-azurepack    文件:AzurePackImageSupport.java   
private List<MachineImage> getAllTemplates() throws CloudException {
    HttpUriRequest listTemplatesRequest = new AzurePackImageRequests(this.provider).listTemplates().build();
    WAPTemplatesModel templatesModel = new AzurePackRequester(this.provider, listTemplatesRequest).withJsonProcessor(WAPTemplatesModel.class).execute();

    final List<MachineImage> images = new ArrayList<MachineImage>();
    final String regionId = this.provider.getContext().getRegionId();

    CollectionUtils.forAllDo(templatesModel.getTemplates(), new Closure() {
        @Override
        public void execute(Object input) {
            WAPTemplateModel templateModel = (WAPTemplateModel)input;
            if(templateModel.getEnabled().equalsIgnoreCase("true")) {
                MachineImage image = MachineImage.getInstance(templateModel.getOwner().getRoleID() != null ? templateModel.getOwner().getRoleID() : "wap",
                        regionId,
                        templateModel.getId(),
                        ImageClass.MACHINE,
                        MachineImageState.ACTIVE,
                        templateModel.getName(),
                        templateModel.getDescription() != null ? templateModel.getDescription() : templateModel.getName(),
                        Architecture.I64,
                        templateModel.getOperatingSystemInstance().getOsType().toLowerCase().contains("windows") ? Platform.WINDOWS : Platform.UNIX);
                image.setTag("type", "template");
                image.setTag("ProductKeyHasValue", templateModel.getProductKeyHasValue());
                images.add(image);
            }
        }
    });

    return images;
}
项目:dasein-cloud-azurepack    文件:AzurePackImageSupport.java   
private List<MachineImage> getAllVhds() throws CloudException {
    HttpUriRequest listVhdsRequest = new AzurePackImageRequests(this.provider).listVirtualDisks().build();
    WAPVhdsModel vhds = new AzurePackRequester(this.provider, listVhdsRequest).withJsonProcessor(WAPVhdsModel.class).execute();

    final List<MachineImage> images = new ArrayList<MachineImage>();

    final String regionId = this.provider.getContext().getRegionId();
    CollectionUtils.forAllDo(vhds.getVhds(), new Closure() {
        @Override
        public void execute(Object input) {
            WAPVhdModel vhd = (WAPVhdModel) input;
            if(vhd.getEnabled().equalsIgnoreCase("true")) {
                MachineImage image = MachineImage.getInstance((vhd.getOwner() != null && vhd.getOwner().getRoleID() != null) ? vhd.getOwner().getRoleID() : "wap",
                        regionId,
                        vhd.getId(),
                        ImageClass.MACHINE,
                        MachineImageState.ACTIVE,
                        vhd.getName(),
                        vhd.getDescription() != null ? vhd.getDescription() : vhd.getName(),
                        Architecture.I64,
                        vhd.getOperatingSystemInstance().getOsType().toLowerCase().contains("windows") ? Platform.WINDOWS : Platform.UNIX);
                image.setTag("type", "vhd");
                images.add(image);
            }
        }
    });

    return images;
}
项目:dasein-cloud-azurepack    文件:AzurePackIpAddressSupport.java   
@Override
public @Nonnull Iterable<IpForwardingRule> listRulesForServer(@Nonnull final String serverId) throws InternalException, CloudException{
    if(serverId == null)
        throw new InternalException("Parameter serverId cannot be null");

    String stampId = provider.getDataCenterServices().listDataCenters(provider.getContext().getRegionId()).iterator().next().getProviderDataCenterId();
    WAPNatConnectionModel wapNatConnectionModel = getNatConnectionForServer(serverId, stampId);
    if(wapNatConnectionModel == null)
        return Collections.emptyList();

    HttpUriRequest listRulesRequest = new AzurePackNetworkRequests(provider).listRulesForConnection(wapNatConnectionModel.getId(), stampId).build();

    WAPNatRulesModel wapNatRulesModel = new AzurePackRequester(provider, listRulesRequest).withJsonProcessor(WAPNatRulesModel.class).execute();

    final ArrayList<IpForwardingRule> rules = new ArrayList<IpForwardingRule>();
    CollectionUtils.forAllDo(wapNatRulesModel.getRules(), new Closure() {
        @Override
        public void execute(Object input) {
            WAPNatRuleModel wapNatRuleModel = (WAPNatRuleModel)input;
            IpForwardingRule rule = new IpForwardingRule();
            rule.setServerId(serverId);
            rule.setProviderRuleId(wapNatRuleModel.getId());
            rule.setPrivatePort(Integer.valueOf(wapNatRuleModel.getInternalPort()));
            rule.setPublicPort(Integer.valueOf(wapNatRuleModel.getExternalPort()));
            if(wapNatRuleModel.getProtocol() != null)
                rule.setProtocol(Protocol.valueOf(wapNatRuleModel.getProtocol().toUpperCase()));

            rules.add(rule);
        }
    });

    return rules;
}
项目:dasein-cloud-azurepack    文件:AzurePackNetworkSupport.java   
@Override
public @Nonnull Iterable<Subnet> listSubnets(@Nonnull final String vlanId) throws CloudException, InternalException {
    List<DataCenter> dataCenters = new ArrayList(IteratorUtils.toList(this.provider.getDataCenterServices().listDataCenters(this.provider.getContext().getRegionId()).iterator()));
    String dataCenterId = dataCenters.get(0).getProviderDataCenterId();

    HttpUriRequest listSubnetsRequest = new AzurePackNetworkRequests(provider).listSubnets(dataCenterId).build();

    return new AzurePackRequester(provider, listSubnetsRequest).withJsonProcessor(new DriverToCoreMapper<WAPSubnetsModel, List<Subnet>>() {
        @Override
        public List<Subnet> mapFrom(WAPSubnetsModel entity) {
            final ArrayList<Subnet> subnets = new ArrayList<Subnet>();
            CollectionUtils.forAllDo(entity.getSubnets(), new Closure() {
                @Override
                public void execute(Object input) {
                    WAPSubnetModel subnetModel = (WAPSubnetModel) input;
                    if(subnetModel.getVmNetworkId().equalsIgnoreCase(vlanId)) {
                        subnets.add(Subnet.getInstance(provider.getContext().getAccountNumber(), provider.getContext().getRegionId(),
                                subnetModel.getVmNetworkId(),
                                subnetModel.getId(),
                                SubnetState.AVAILABLE,
                                subnetModel.getName(),
                                subnetModel.getName(),
                                subnetModel.getSubnet()));
                    }
                }
            });

            return subnets;
        }
    }, WAPSubnetsModel.class).execute();
}
项目:dasein-cloud-azurepack    文件:AzurePackDatabaseSupport.java   
@Nonnull
@Override
public Iterable<DatabaseProduct> listDatabaseProducts(@Nonnull final DatabaseEngine forEngine) throws CloudException, InternalException {
    if(forEngine == null)
        throw new InternalException("Please specify the DatabaseEngine for which you want to retrieve the products.");

    if(forEngine != DatabaseEngine.SQLSERVER_EE && forEngine != DatabaseEngine.MYSQL)
        return Arrays.asList();

    if(forEngine == DatabaseEngine.SQLSERVER_EE && !hasMSSql)
        return Arrays.asList();

    if(forEngine == DatabaseEngine.MYSQL && !hasMySql)
        return Arrays.asList();

    List<DataCenter> dataCenters = new ArrayList(IteratorUtils.toList(this.provider.getDataCenterServices().listDataCenters(this.provider.getContext().getRegionId()).iterator()));
    final String dataCenterId = dataCenters.get(0).getProviderDataCenterId();

    final ArrayList<DatabaseProduct> databaseProducts = new ArrayList<>();
    CollectionUtils.forAllDo(getDBProductsFromFile(), new Closure() {
        @Override
        public void execute(Object input) {
            WAPDatabaseProducts.WAPDatabaseProduct wapDatabaseProduct = (WAPDatabaseProducts.WAPDatabaseProduct)input;
            if(forEngine.name().equalsIgnoreCase(wapDatabaseProduct.getEngine())) {
                DatabaseProduct product = new DatabaseProduct(String.format("%s:%s", forEngine.name().toString().toLowerCase(), wapDatabaseProduct.getMaxStorage()), "default");
                product.setEngine(forEngine);
                product.setProviderDataCenterId(dataCenterId);
                product.setLicenseModel(getLicenseModel(wapDatabaseProduct.getLicense()));
                databaseProducts.add(product);
            }
        }
    });

    return databaseProducts;
}
项目:dasein-cloud-azurepack    文件:AzurePackDataCenterService.java   
@Override
public Collection<DataCenter> listDataCenters(final String providerRegionId) throws InternalException, CloudException {
    HttpUriRequest httpUriRequest = new AzurePackDataCenterRequests(provider).listClouds().build();

    WAPCloudsModel result = new AzurePackRequester(provider, httpUriRequest).withJsonProcessor(WAPCloudsModel.class).execute();

    List<WAPCloudModel> wapClouds = result.getClouds();
    CollectionUtils.filter(wapClouds, new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            return ((WAPCloudModel) object).getId().equalsIgnoreCase(providerRegionId);
        }
    });

    final List<DataCenter> dataCenters = new ArrayList<DataCenter>();

    CollectionUtils.forAllDo(wapClouds, new Closure() {
        @Override
        public void execute(Object input) {
            WAPCloudModel cloudModel = (WAPCloudModel) input;

            DataCenter dataCenter = new DataCenter();
            dataCenter.setName(cloudModel.getName());
            dataCenter.setActive(true);
            dataCenter.setAvailable(true);
            dataCenter.setRegionId(providerRegionId);
            dataCenter.setProviderDataCenterId(cloudModel.getStampId());

            dataCenters.add(dataCenter);
        }
    });

    return dataCenters;
}
项目:mars-sim    文件:ClosureChain.java   
/**
 *  Creates a new <code>ClosureChain</code>.
 */
public ClosureChain( Closure[] closures )
{
    super();
    closureArray = closures.clone();
    if( containsNull( closureArray ) ) {
        throw new IllegalArgumentException( "Closure array has a null element." );
    }
}
项目:mars-sim    文件:ClosureChain.java   
/**
 *  Creates a new <code>ClosureChain</code>.
 */
public ClosureChain( Collection closures )
{
    super();
    Closure[] temp = new Closure[ closures.size() ];
    closureArray = (Closure[]) closures.toArray( temp );
    if( containsNull( closureArray ) ) {
        throw new IllegalArgumentException( "Collection argument has a null element." );
    }
}
项目:mars-sim    文件:ClosureChain.java   
/**
 *  Creates a new <code>ClosureChain</code>.
 */
public ClosureChain( Closure first, Closure second )
{
    super();
    closureArray = new Closure[] { first, second };
    if( first == null ) {
        throw new IllegalArgumentException( "First Closure is null." );
    }
    if( second == null ) {
        throw new IllegalArgumentException( "Second Closure is null." );
    }
}
项目:Zoo    文件:Audio.java   
private static void setMasterVolumeJavaSound(final float volume) {
    runVolumeCommand(new Closure() {
        public void execute(Object input) {
            FloatControl volumeControl = (FloatControl) input;
            volumeControl.setValue(volume);
        }
    });
}
项目:Zoo    文件:Audio.java   
private static float getMasterVolumeJavaSound() throws IOException {
    final Float[] volumes = new Float[1];
    runVolumeCommand(new Closure() {
        public void execute(Object input) {
            FloatControl volumeControl = (FloatControl) input;
            volumes[0] = volumeControl.getValue();
        }
    });
    if(volumes[0]!=null) {
        return volumes[0];
    } else {
        throw new IOException("Cannot determine master volume level");
    }
}
项目:jannocessor    文件:PowerLinkedHashSet.java   
public PowerSet<E> each(final Operation<? super E> operation) {
    CollectionUtils.forAllDo(this, new Closure() {
        @SuppressWarnings("unchecked")
        public void execute(Object input) {
            operation.execute((E) input);
        }
    });
    return this;
}
项目:jannocessor    文件:PowerArrayList.java   
@SuppressWarnings("unchecked")
@Override
public PowerList<E> each(final Operation<? super E> operation) {
    CollectionUtils.forAllDo(this, new Closure() {

        public void execute(Object input) {
            operation.execute((E) input);
        }

    });

    return this;
}
项目:openhab-hdl    文件:Audio.java   
private static void setMasterVolumeJavaSound(final float volume) {
    runVolumeCommand(new Closure() {
        public void execute(Object input) {
            FloatControl volumeControl = (FloatControl) input;
            volumeControl.setValue(volume);
        }
    });
}
项目:openhab-hdl    文件:Audio.java   
private static float getMasterVolumeJavaSound() throws IOException {
    final Float[] volumes = new Float[1];
    runVolumeCommand(new Closure() {
        public void execute(Object input) {
            FloatControl volumeControl = (FloatControl) input;
            volumes[0] = volumeControl.getValue();
        }
    });
    if(volumes[0]!=null) {
        return volumes[0];
    } else {
        throw new IOException("Cannot determine master volume level");
    }
}
项目:xsd2xml    文件:SchemaUtilTest.java   
@Test
public void testGetNamesFromSchemaWithImport() throws Exception {
    final InputStream is = getClass().getResourceAsStream(elementFormXsd);
    assertNotNull(is);

    final StreamSource source = new StreamSource(is);
    final XmlSchemaCollection schemaColl = new XmlSchemaCollection();
    final URL baseUrl = SchemaUtilTest.class.getResource(elementFormXsd);
    final String baseUri = baseUrl.toURI().toString();

    schemaColl.setBaseUri(baseUri);


    final XmlSchema schema = schemaColl.read(source);
    assertNotNull(schema);

    System.out.println("There are " + schemaColl.getXmlSchemas().length + " schemas present");

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

}
项目:archiva    文件:RepositoryScannerInstance.java   
public RepositoryScannerInstance( ManagedRepository repository,
                                  List<KnownRepositoryContentConsumer> knownConsumerList,
                                  List<InvalidRepositoryContentConsumer> invalidConsumerList )
{
    this.repository = repository;
    this.knownConsumers = knownConsumerList;
    this.invalidConsumers = invalidConsumerList;

    addFileNameIncludePattern("**/*");

    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 );
    }
}
项目:archiva    文件:RepositoryScannerInstance.java   
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (excludeMatcher.stream().noneMatch(m -> m.matches(file)) && includeMatcher.stream().allMatch(m -> m.matches(file))) {
        log.debug( "Walk Step: {}, {}", file );

        stats.increaseFileCount();

        // consume files regardless - the predicate will check the timestamp
        Path repoPath = PathUtil.getPathFromUri( repository.getLocation() );
        BaseFile basefile = new BaseFile( repoPath.toString(), file.toFile() );

        // Timestamp finished points to the last successful scan, not this current one.
        if ( Files.getLastModifiedTime(file).toMillis() >= 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 );
        }

    }
    return FileVisitResult.CONTINUE;
}
项目:gocd    文件:FelixGoPluginOSGiFramework.java   
private Closure notifyPluginLoadedEvent(final GoPluginDescriptor pluginDescriptor) {
    return new Closure() {
        @Override
        public void execute(Object o) {
            PluginChangeListener pluginChangeListener = (PluginChangeListener) o;
            pluginChangeListener.pluginLoaded(pluginDescriptor);
        }
    };
}
项目:gocd    文件:FelixGoPluginOSGiFramework.java   
private Closure notifyPluginUnLoadedEvent(final GoPluginDescriptor pluginDescriptor) {
    return new Closure() {
        @Override
        public void execute(Object o) {
            PluginChangeListener pluginChangeListener = (PluginChangeListener) o;
            pluginChangeListener.pluginUnLoaded(pluginDescriptor);
        }
    };
}
项目:gocd    文件:DefaultPluginJarLocationMonitor.java   
@Override
public void pluginJarAdded(final PluginFileDetails pluginFileDetails) {
    doOnAllPluginJarChangeListener(new Closure() {
        public void execute(Object o) {
            ((PluginJarChangeListener) o).pluginJarAdded(pluginFileDetails);
        }
    });
}
项目:gocd    文件:DefaultPluginJarLocationMonitor.java   
@Override
public void pluginJarUpdated(final PluginFileDetails pluginFileDetails) {
    doOnAllPluginJarChangeListener(new Closure() {
        public void execute(Object o) {
            ((PluginJarChangeListener) o).pluginJarUpdated(pluginFileDetails);
        }
    });
}
项目:gocd    文件:DefaultPluginJarLocationMonitor.java   
@Override
public void pluginJarRemoved(final PluginFileDetails pluginFileDetails) {
    doOnAllPluginJarChangeListener(new Closure() {
        public void execute(Object o) {
            ((PluginJarChangeListener) o).pluginJarRemoved(pluginFileDetails);
        }
    });
}
项目:gocd    文件:DefaultPluginJarLocationMonitor.java   
private void doOnAllPluginJarChangeListener(Closure closure) {
    for (WeakReference<PluginJarChangeListener> listener : listeners) {
        PluginJarChangeListener changeListener = listener.get();
        if (changeListener == null) {
            continue;
        }

        try {
            closure.execute(changeListener);
        } catch (Exception e) {
            LOGGER.warn("Plugin listener failed", e);
        }
    }
}