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:net.sf.wickedshell.domain.xmlShellDescriptor.XMLShellDescriptorDao.java

/**
 * Persist the <code>List</code> of <code>IXMLShellDescriptor</code>s.
 * /*  www.java  2  s.  c om*/
 * @param xmlShellDescriptors
 *            the <code>List</code> of <code>IXMLShellDescriptor</code>s
 */
public void writeXMLShellDescriptors(List<IXMLShellDescriptor> xmlShellDescriptors) throws IOException {
    String stateLocation = DomainPlugin.getDefault().getStateLocation().toOSString();
    File xmlShellDescriptorListDocumentFile = new File(stateLocation, DomainID.XML_SHELL_DESCRIPTORS_FILE);
    if (!xmlShellDescriptorListDocumentFile.exists()) {
        xmlShellDescriptorListDocumentFile.delete();
    }
    final XmlShellDescriptorListDocument xmlShellDescriptorListDocument = XmlShellDescriptorListDocument.Factory
            .newInstance();
    xmlShellDescriptorListDocument.addNewXmlShellDescriptorList();
    CollectionUtils.forAllDo(xmlShellDescriptors, new Closure() {
        /**
         * @see org.apache.commons.collections.Closure#execute(java.lang.Object)
         */
        public void execute(Object object) {
            IXMLShellDescriptor xmlShellDescriptor = (IXMLShellDescriptor) object;
            XmlShellDescriptorList xmlShellDescriptorList = xmlShellDescriptorListDocument
                    .getXmlShellDescriptorList();
            XmlShellDescriptor staticXMLShellDescriptor = xmlShellDescriptorList.addNewXmlShellDescriptor();
            // Transfer the data
            staticXMLShellDescriptor.setId(xmlShellDescriptor.getId());
            staticXMLShellDescriptor.setName(xmlShellDescriptor.getName());
            staticXMLShellDescriptor.setBinariesDirectory(xmlShellDescriptor.getBinariesDirectory());
            staticXMLShellDescriptor.setCharacterEncoding(xmlShellDescriptor.getCharacterEncoding());
            staticXMLShellDescriptor.setCommandDelimiter(xmlShellDescriptor.getCommandDelimiter());
            staticXMLShellDescriptor.setCustomRootDirectory(xmlShellDescriptor.getCustomRootDirectory());
            staticXMLShellDescriptor.setExecutable(xmlShellDescriptor.getExecutable());
            staticXMLShellDescriptor.setExecutableBatchFilesArray(xmlShellDescriptor.getExecutableBatchFiles());
            staticXMLShellDescriptor.setExecutableFilesArray(xmlShellDescriptor.getExecutableFiles());
            staticXMLShellDescriptor
                    .setExecutedCommandProvided(String.valueOf(xmlShellDescriptor.isExecutedCommandProvided()));
            staticXMLShellDescriptor.setLineFeedString(xmlShellDescriptor.getLineFeedString());
            staticXMLShellDescriptor.setOperatingSystemsArray(xmlShellDescriptor.getOperatingSystems());
            staticXMLShellDescriptor.setPathDelimiter(xmlShellDescriptor.getPathDelimiter());
            staticXMLShellDescriptor.setPathSeparator(xmlShellDescriptor.getPathSeparator());
            staticXMLShellDescriptor
                    .setSystemPathSeparator(String.valueOf(xmlShellDescriptor.getSystemPathSeparator()));
            staticXMLShellDescriptor
                    .setUiLineFeedProvided(String.valueOf(xmlShellDescriptor.isUiLineFeedProvided()));
        }
    });
    xmlShellDescriptorListDocument.save(xmlShellDescriptorListDocumentFile);
}

From source file:com.projity.grouping.core.summaries.ShallowChildWalker.java

public void execute(Object arg0) {
    Node node = (Node) arg0;
    Collection nodeList = nodeModel.getChildren(node);
    if (nodeList != null)
        CollectionUtils.forAllDo(nodeList, visitor);
}

From source file:de.berlios.gpon.wui.actions.data.ItemSearchAction.java

private void addAssociatedProperties(List idMapped, HashMap associatedPropertyMap) {

    // build up a pathDigest -> ipd-List mapping
    final Hashtable pathAndProperties = new Hashtable();

    CollectionUtils.forAllDo(associatedPropertyMap.keySet(), new Closure() {
        // foreach key in associatedPropertyMap do:
        public void execute(Object o) {
            String key = (String) o;

            String[] keySplit = ItemSearchForm.splitAssociatedPropertyKey(key);

            String pathDigest = keySplit[0];
            String ipdId = keySplit[1];

            if (!pathAndProperties.containsKey(pathDigest)) {
                pathAndProperties.put(pathDigest, new ArrayList());
            }//  www. ja v a  2s.  c om

            ((List) pathAndProperties.get(pathDigest)).add(new Long(ipdId));
        }
    });

    final String[] digests = (String[]) Collections.list(pathAndProperties.keys()).toArray(new String[0]);

    final PathResolver pathResolver = (PathResolver) getObjectForBeanId("pathResolver");

    CollectionUtils.forAllDo(idMapped, new Closure() {

        public void execute(Object o) {

            ItemMap im = (ItemMap) o;

            // foreach digest

            for (int digIdx = 0; digIdx < digests.length; digIdx++) {
                String digest = digests[digIdx];

                Set items = pathResolver.getItemsForPath(im.getItem().getId(), digest);

                if (items != null && items.size() > 0) {
                    if (items.size() > 1) {
                        throw new RuntimeException("more than one associated item found");
                    }

                    // get one & only item
                    Item item = ((Item[]) items.toArray(new Item[0]))[0];

                    Long[] ipds = (Long[]) ((List) pathAndProperties.get(digest)).toArray(new Long[0]);

                    ItemMappedById associatedImbi = new ItemMappedById(item);

                    for (int ipdIdx = 0; ipdIdx < ipds.length; ipdIdx++) {
                        Value value = associatedImbi.getValueObject(ipds[ipdIdx] + "");

                        if (value != null) {
                            im.addAdditionalAttribute(digest + "|" + ipds[ipdIdx], value);
                        }
                    }
                }
            }

        }
    });
}

From source file:com.projity.grouping.core.summaries.LeafWalker.java

public void execute(Object arg0) {
    Node node = (Node) arg0;
    Collection nodeList = nodeModel.getChildren(node);
    if (nodeList == null || nodeList.isEmpty()) { // if has no children
        if (visitor != null)
            visitor.execute(node); // add value
    } else {/*from  w ww  . j  ava2 s  .  c  o  m*/
        CollectionUtils.forAllDo(nodeList, this); // treat children
    }
}

From source file:com.projity.grouping.core.summaries.DeepChildWalker.java

public void execute(Object arg0) {
    Node node = (Node) arg0;
    Collection nodeList = nodeModel.getChildren(node);
    closure.execute(node);//from w  w  w  . jav  a2s .c om

    if (nodeList != null && (!parentsOnlyIfProject || !(node.getImpl() instanceof Project)))
        CollectionUtils.forAllDo(nodeList, this);
}

From source file:com.projity.functor.StringList.java

public static String commaSeparatedList(Collection collection) {
    StringList l = getInstance(StringValueTransformer.INSTANCE);
    l.setSeparator(",");
    CollectionUtils.forAllDo(collection, l);
    return l.toString();
}

From source file:com.projity.functor.StringList.java

public static String brSeparatedList(Collection collection) {
    StringList l = getInstance(StringValueTransformer.INSTANCE);
    l.setSeparator("<br>");
    CollectionUtils.forAllDo(collection, l);
    return l.toString();
}

From source file:com.projity.grouping.core.summaries.DeepChildSearcher.java

public void execute(Object arg0) {
    if (findClosure.result != null)
        return;/* w w w.  j  a v a 2  s. co m*/
    Node node = (Node) arg0;
    if (node != null)
        closure.execute(node);
    Collection nodeList = nodeModel.getChildren(node);
    if (nodeList != null)
        CollectionUtils.forAllDo(nodeList, this);
}

From source file:io.coala.experimental.dynabean.DynaBeanTest.java

@Test
public void testDynaBeans() throws Exception {
    // for usage, see
    // http://commons.apache.org/proper/commons-beanutils/javadocs/v1.9.2/apidocs/org/apache/commons/beanutils/package-summary.html#package_description

    final DynaBean dynaBean = new LazyDynaBean(); // Create LazyDynaBean
    final MutableDynaClass dynaClass = (MutableDynaClass) dynaBean.getDynaClass(); // get DynaClass

    dynaClass.add("amount", java.lang.Integer.class); // add property
    dynaClass.add("myMap", java.util.TreeMap.class); // add mapped property

    final DynaBean employee = dynaClass.newInstance();

    // TODO experiment with Jackson's AnnotationIntrospector to annotate
    // DynaBean#get(...) method with @JsonAnyGetter and #set(...) method
    // with @JsonAnySetter

    employee.set("address", new HashMap<String, String>());
    employee.set("activeEmployee", Boolean.FALSE);
    employee.set("firstName", "Fred");
    employee.set("lastName", "Flintstone");

    LOG.trace("Employee: " + JsonUtil.toPrettyJSON(employee));

    // set all <activeEmployee> attribute values to <true>
    final BeanPropertyValueChangeClosure closure = new BeanPropertyValueChangeClosure("activeEmployee",
            Boolean.TRUE);//  ww w  . j  av  a 2s.  co m

    final Collection<?> employees = Collections.singleton(employee);
    LOG.trace("Mutated employees: " + JsonUtil.toPrettyJSON(employees));

    // update the Collection
    CollectionUtils.forAllDo(employees, closure);

    // filter for beans with <activeEmployee> set to <false>
    final BeanPropertyValueEqualsPredicate predicate = new BeanPropertyValueEqualsPredicate("lastName",
            "Flintstone");

    // filter the Collection
    CollectionUtils.filter(employees, predicate);
    LOG.trace("Filtered employees: " + JsonUtil.toPrettyJSON(employees));
}

From source file:com.projity.pm.graphic.network.NetworkPopupMenu.java

/**
 * Because the styles may change, rebuild the menu each time
 *
 *//* w w  w  .j a  v a 2  s .  c  o m*/
protected void init() {
    removeAll();
    final JMenu bars = new JMenu(Messages.getString("Network.Popup.barStylesMenu"));
    CollectionUtils.forAllDo(interactor.getGraph().getBarStyles().getRows(), new Closure() {
        public void execute(Object arg0) {
            BarStyle barStyle = (BarStyle) arg0;
            BarMenuAction menuAction = new BarMenuAction(barStyle);
            bars.add(menuAction);

        }
    });
    add(bars);

}