Example usage for org.apache.commons.collections CollectionUtils forAllDo

List of usage examples for org.apache.commons.collections CollectionUtils forAllDo

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils forAllDo.

Prototype

public static void forAllDo(Collection collection, Closure closure) 

Source Link

Document

Executes the given closure on each element in the collection.

Usage

From source file:com.nwea.samples.apachecommons.collections.SampleCollectionUtilsTest.java

/**
 * @param maleStudents//from  www .  jav  a  2s  . c  o m
 */
private void printStudents(Collection<Student> students) {
    CollectionUtils.forAllDo(students, new Closure() {
        public void execute(Object arg0) {
            out.println(arg0.toString());
        }
    });
}

From source file:com.nwea.samples.apachecommons.collections.SampleCollectionUtils.java

@SuppressWarnings("unchecked")
public static void setDefaultHomeroomsBySex(Collection<Student> students, final String femaleHomeroom,
        final String maleHomeroom) {
    // predicate returns true if student sex is "F"
    Predicate ifStatement = new Predicate() {
        public boolean evaluate(Object obj) {
            Student student = (Student) obj;
            return student.getSex().equals("F");
        }/*from  ww w . j a v  a 2s .c  o m*/
    };

    // closure calls setHomeroom() on Student refs.
    // allows to set "homeRoom" var in instance initializer
    class SetHomeroom implements Closure {
        String homeRoom;

        public void execute(Object obj) {
            Student student = (Student) obj;
            student.setHomeroom(homeRoom);
        }
    }

    CollectionUtils.forAllDo(students, ClosureUtils.ifClosure(ifStatement, new SetHomeroom() {
        {
            homeRoom = femaleHomeroom;
        }
    }, new SetHomeroom() {
        {
            homeRoom = maleHomeroom;
        }
    })); // crazy braces/parens!
}

From source file:com.prodyna.bmw.server.aircraft.service.AircraftBusinessServiceBean.java

@Override
public List<Aircraft> readAircraftsForPilot(String pilotId) {
    List<PilotLicense> licnesesForPilot = pilotLicenseService.readLicensesForPilot(pilotId);

    final List<Aircraft> aircrafts = new ArrayList<Aircraft>();

    CollectionUtils.forAllDo(licnesesForPilot, new Closure() {
        @Override/* w  ww.j  av a 2  s  .  c  o m*/
        public void execute(Object arg0) {
            PilotLicense license = (PilotLicense) arg0;
            List<Aircraft> aircraftsForType = aircraftService
                    .getAircraftsForType(license.getAircraftType().getId());
            aircrafts.addAll(aircraftsForType);
        }
    });

    return aircrafts;
}

From source file:com.stratumsoft.xmlgen.SchemaUtilTest.java

@Test
public void testGetNames() throws Exception {
    final InputStream is = getClass().getResourceAsStream(personalXsd);
    assertNotNull(is);/*w  ww  . j av a 2s . co m*/

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

}

From source file:de.hybris.platform.b2bacceleratorfacades.order.populators.B2BUserGroupEditPermissionsPopulator.java

protected CustomerData populateUserGroupsEditPermissions(final CustomerData customerData) {
    final List<B2BUserGroupData> customerPermissionGroups = customerData.getPermissionGroups();

    if (!customerPermissionGroups.isEmpty()) {
        final SearchPageData<B2BUserGroupModel> currentUserPermissionGroups = getB2bCommerceB2bUserGroupService()
                .getPagedB2BUserGroups(createPageableData());
        final List<B2BUserGroupModel> results = currentUserPermissionGroups.getResults();

        CollectionUtils.forAllDo(customerPermissionGroups, new Closure() {
            @Override/* ww  w .  j  a  v  a  2s  . c  o m*/
            public void execute(final Object input) {
                final B2BUserGroupData b2bUserGroupData = (B2BUserGroupData) input;
                b2bUserGroupData.setEditable(isUserGroupAllowedToEditByCurrentUser(b2bUserGroupData, results));
            }
        });
    }
    return customerData;
}

From source file:com.newlandframework.avatarmq.broker.ProducerMessageHook.java

private void filterByTopic(String topic) {
    Predicate focusAllPredicate = new Predicate() {
        public boolean evaluate(Object object) {
            ConsumerClusters clusters = (ConsumerClusters) object;
            return clusters.findSubscriptionData(topic) != null;
        }//w  w  w .  j ava  2  s .  co m
    };

    AnyPredicate any = new AnyPredicate(new Predicate[] { focusAllPredicate });

    Closure joinClosure = new Closure() {
        public void execute(Object input) {
            if (input instanceof ConsumerClusters) {
                ConsumerClusters clusters = (ConsumerClusters) input;
                clustersSet.add(clusters);
            }
        }
    };

    Closure ignoreClosure = new Closure() {
        public void execute(Object input) {
        }
    };

    Closure ifClosure = ClosureUtils.ifClosure(any, joinClosure, ignoreClosure);

    CollectionUtils.forAllDo(focusTopicGroup, ifClosure);
}

From source file:com.architexa.diagrams.jdt.builder.ReloASTExtractor.java

public void removeAnnotations(List<Resource> srcResources) {
    CollectionUtils.forAllDo(srcResources, new Closure() {
        public void execute(Object arg0) {
            removeAnnotations(projectModel, (URI) arg0);
        }/*from w w  w . j  a  v a  2s .co  m*/
    });
}

From source file:com.stratumsoft.xmlgen.SchemaUtilTest.java

@Test
public void testGetNamesFromSchemaWithImport() throws Exception {
    final InputStream is = getClass().getResourceAsStream(elementFormXsd);
    assertNotNull(is);// w ww . j a  va  2s  . co  m

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

}

From source file:net.sf.wickedshell.domain.command.CommandDescriptorDao.java

/**
 * Persist the <code>List</code> of <code>ICommandDescriptor</code>.
 * /*  w  w w  .  jav a  2s .  co  m*/
 * @param commandDescriptors
 *            the <code>List</code> of <code>ICommandDescriptor</code>
 */
public void writeCommandHistory(List<ICommandDescriptor> commandDescriptors) throws IOException {
    String stateLocation = DomainPlugin.getDefault().getStateLocation().toOSString();
    File commandHistoryListDocumentFile = new File(stateLocation, DomainID.COMMAND_HISTORY_FILE);
    if (!commandHistoryListDocumentFile.exists()) {
        commandHistoryListDocumentFile.delete();
    }
    final CommandHistoryListDocument commandHistoryListDocument = CommandHistoryListDocument.Factory
            .newInstance();
    commandHistoryListDocument.addNewCommandHistoryList();
    CollectionUtils.forAllDo(commandDescriptors, new Closure() {
        /**
         * @see org.apache.commons.collections.Closure#execute(java.lang.Object)
         */
        public void execute(Object object) {
            ICommandDescriptor commandFileDescriptor = (ICommandDescriptor) object;
            CommandHistoryList commandHistoryList = commandHistoryListDocument.getCommandHistoryList();
            CommandDescriptor staticCommandDescriptor = commandHistoryList.addNewCommandDescriptor();
            // The command is stored in XML, so we need to remove ALL
            // invalid XML characters
            char[] commandCharacters = commandFileDescriptor.getCommand().toCharArray();
            StringBuffer validXMLCharacters = new StringBuffer();
            for (int charIndex = 0; charIndex < commandCharacters.length; charIndex++) {
                if (XMLChar.isValid(commandCharacters[charIndex])) {
                    validXMLCharacters.append(commandCharacters[charIndex]);
                }
            }
            staticCommandDescriptor.setCommand(validXMLCharacters.toString());
            staticCommandDescriptor.setShellDescriptorId(commandFileDescriptor.getShellDescriptorId());
        }
    });
    commandHistoryListDocument.save(commandHistoryListDocumentFile);
}

From source file:net.sf.wickedshell.domain.batch.BatchFileDescriptorDao.java

/**
 * Persist the <code>List</code> of <code>IBatchFileDescriptor</code>.
 * /* w w w .ja  v  a 2  s  .  c o  m*/
 * @param completions
 *        the <code>List</code> of <code>IBatchFileDescriptor</code>
 */
public void writeBatchFileDescriptors(List<IBatchFileDescriptor> batchFileDescriptors) throws IOException {
    String stateLocation = DomainPlugin.getDefault().getStateLocation().toOSString();
    File batchFileDescriptorListDocumentFile = new File(stateLocation, DomainID.BATCH_FILES_FILE);
    if (!batchFileDescriptorListDocumentFile.exists()) {
        batchFileDescriptorListDocumentFile.delete();
    }
    final BatchFileDescriptorListDocument batchFileDescriptorListDocument = BatchFileDescriptorListDocument.Factory
            .newInstance();
    batchFileDescriptorListDocument.addNewBatchFileDescriptorList();
    CollectionUtils.forAllDo(batchFileDescriptors, new Closure() {
        /**
         * @see org.apache.commons.collections.Closure#execute(java.lang.Object)
         */
        public void execute(Object object) {
            IBatchFileDescriptor batchFileDescriptor = (IBatchFileDescriptor) object;
            BatchFileDescriptorList batchFileDescriptorList = batchFileDescriptorListDocument
                    .getBatchFileDescriptorList();
            BatchFileDescriptor staticBatchFileDescriptor = batchFileDescriptorList.addNewBatchFileDescriptor();
            staticBatchFileDescriptor.setFilename(batchFileDescriptor.getFilename());
            staticBatchFileDescriptor.setParameters(batchFileDescriptor.getParameters());
        }
    });
    batchFileDescriptorListDocument.save(batchFileDescriptorListDocumentFile);
}