Example usage for org.apache.commons.collections Transformer Transformer

List of usage examples for org.apache.commons.collections Transformer Transformer

Introduction

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

Prototype

Transformer

Source Link

Usage

From source file:mondrian.olap.IdBatchResolver.java

/**
 * Returns a collection of strings corresponding to the name
 * or uniqueName of each OlapElement in olapElements, based on the
 * flag uniqueName.//w w  w  .  ja v  a2 s.c o m
 */
private Collection<String> getOlapElementNames(OlapElement[] olapElements, final boolean uniqueName) {
    return CollectionUtils.collect(Arrays.asList(olapElements), new Transformer() {
        public Object transform(Object o) {
            return uniqueName ? ((OlapElement) o).getUniqueName() : ((OlapElement) o).getName();
        }
    });
}

From source file:info.magnolia.cms.util.ContentUtilTest.java

@Test
public void testOrderAfterMidNodeMoreThanThreeVariation2() throws RepositoryException, IOException {
    MockHierarchyManager hm = MockUtil.createHierarchyManager(
            "/node/a\n" + "/node/b\n" + "/node/c\n" + "/node/d\n" + "/node/e\n" + "/node/f\n");
    Content node = hm.getContent("/node");
    Content c = node.getContent("e");
    ContentUtil.orderAfter(c, "b");
    Collection<Content> result = node.getChildren();
    CollectionUtils.transform(result, new Transformer() {
        @Override/*  w w  w. j  a v a  2 s  .  c o m*/
        public Object transform(Object childObj) {
            return ((Content) childObj).getName();
        }
    });
    assertEquals(asList("a", "b", "e", "c", "d", "f"), result);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.coordinator.DegreeCurricularPlanManagementDispatchAction.java

private List<InfoCurricularCourseScope> getInfoCurricularCourseScopes(
        InfoCurricularCourse infoCurricularCourse) {
    CurricularCourse curricularCourse = (CurricularCourse) FenixFramework
            .getDomainObject(infoCurricularCourse.getExternalId());
    List<InfoCurricularCourseScope> infoScopes = (List) CollectionUtils.collect(curricularCourse.getScopesSet(),
            new Transformer() {

                @Override//from w  ww .j a v  a  2 s.  c  o m
                public Object transform(Object arg0) {
                    CurricularCourseScope curricularCourseScope = (CurricularCourseScope) arg0;
                    return InfoCurricularCourseScope.newInfoFromDomain(curricularCourseScope);
                }

            });
    return infoScopes;
}

From source file:ddf.catalog.source.solr.SolrMetacardClient.java

public void deleteByIds(String fieldName, List<? extends Serializable> identifiers, boolean forceCommit)
        throws IOException, SolrServerException {
    if (identifiers == null || identifiers.size() == 0) {
        return;// w  w  w  . j a  va  2 s .c  o  m
    }

    if (Metacard.ID.equals(fieldName)) {
        CollectionUtils.transform(identifiers, new Transformer() {
            @Override
            public Object transform(Object o) {
                return o.toString();
            }
        });
        client.deleteById((List<String>) identifiers);
    } else {
        if (identifiers.size() < SolrCatalogProvider.MAX_BOOLEAN_CLAUSES) {
            client.deleteByQuery(getIdentifierQuery(fieldName, identifiers));
        } else {
            int i = 0;
            for (i = SolrCatalogProvider.MAX_BOOLEAN_CLAUSES; i < identifiers
                    .size(); i += SolrCatalogProvider.MAX_BOOLEAN_CLAUSES) {
                client.deleteByQuery(getIdentifierQuery(fieldName,
                        identifiers.subList(i - SolrCatalogProvider.MAX_BOOLEAN_CLAUSES, i)));
            }
            client.deleteByQuery(getIdentifierQuery(fieldName,
                    identifiers.subList(i - SolrCatalogProvider.MAX_BOOLEAN_CLAUSES, identifiers.size())));
        }
    }

    if (forceCommit) {
        client.commit();
    }
}

From source file:info.magnolia.cms.util.ContentUtilTest.java

@Test
public void testOrderBeforeFirstNodeVariation1() throws RepositoryException, IOException {
    MockHierarchyManager hm = MockUtil.createHierarchyManager(
            "/node/a\n" + "/node/b\n" + "/node/c\n" + "/node/d\n" + "/node/e\n" + "/node/f\n");
    Content node = hm.getContent("/node");
    Content c = node.getContent("c");
    ContentUtil.orderBefore(c, "a");
    Collection<Content> result = node.getChildren();
    CollectionUtils.transform(result, new Transformer() {
        @Override//from   w w  w .j  ava2s .c o  m
        public Object transform(Object childObj) {
            return ((Content) childObj).getName();
        }
    });
    assertEquals(asList("c", "a", "b", "d", "e", "f"), result);
}

From source file:info.magnolia.cms.util.ContentUtilTest.java

@Test
public void testOrderBeforeFirstNodeVariation2() throws RepositoryException, IOException {
    MockHierarchyManager hm = MockUtil.createHierarchyManager(
            "/node/a\n" + "/node/b\n" + "/node/c\n" + "/node/d\n" + "/node/e\n" + "/node/f\n");
    Content node = hm.getContent("/node");
    Content c = node.getContent("b");
    ContentUtil.orderBefore(c, "a");
    Collection<Content> result = node.getChildren();
    CollectionUtils.transform(result, new Transformer() {
        @Override//from  www. j  a  v a 2s .c o m
        public Object transform(Object childObj) {
            return ((Content) childObj).getName();
        }
    });
    assertEquals(asList("b", "a", "c", "d", "e", "f"), result);
}

From source file:io.wcm.caconfig.extensions.persistence.impl.ToolsConfigPagePersistenceStrategy.java

@SuppressWarnings("unchecked")
private Iterator<Resource> getResourceInheritanceChainInternal(final Collection<String> bucketNames,
        final String configName, final Iterator<String> paths, final ResourceResolver resourceResolver) {

    // find all matching items among all configured paths
    Iterator<Resource> matchingResources = IteratorUtils.transformedIterator(paths, new Transformer() {

        @Override/* ww w .  java  2s  .  c om*/
        public Object transform(Object input) {
            String path = (String) input;
            for (String bucketName : bucketNames) {
                final String name = bucketName + "/" + configName;
                final String configPath = buildResourcePath(path, name);
                Resource resource = resourceResolver.getResource(configPath);
                if (resource != null) {
                    log.trace("+ Found matching config resource for inheritance chain: {}", configPath);
                    return resource;
                } else {
                    log.trace("- No matching config resource for inheritance chain: {}", configPath);
                }
            }
            return null;
        }
    });
    Iterator<Resource> result = IteratorUtils.filteredIterator(matchingResources,
            PredicateUtils.notNullPredicate());
    if (result.hasNext()) {
        return result;
    }
    return null;
}

From source file:info.magnolia.cms.util.ContentUtilTest.java

@Test
public void testOrderBeforeFirstNodeVariation3() throws RepositoryException, IOException {
    MockHierarchyManager hm = MockUtil.createHierarchyManager(
            "/node/a\n" + "/node/b\n" + "/node/c\n" + "/node/d\n" + "/node/e\n" + "/node/f\n");
    Content node = hm.getContent("/node");
    Content c = node.getContent("a");
    ContentUtil.orderBefore(c, "b");
    Collection<Content> result = node.getChildren();
    CollectionUtils.transform(result, new Transformer() {
        @Override/*from   w  ww  .  j a v a  2  s  .  c  o  m*/
        public Object transform(Object childObj) {
            return ((Content) childObj).getName();
        }
    });
    assertEquals(asList("a", "b", "c", "d", "e", "f"), result);
}

From source file:com.alkacon.opencms.comments.CmsCommentsAccess.java

/**
 * Returns the number of comments a given author has written.<p>
 * //from  w ww.j  a  va 2s  .c  o m
 * To use this method you have to define a field called {@link CmsCommentFormHandler#FIELD_USERNAME}.<p>
 * 
 * @return a map where the key is the author name and the value the number of comments
 */
public Map getCountByAuthor() {

    if (m_countByAuthor == null) {
        m_countByAuthor = LazyMap.decorate(new HashMap(), new Transformer() {

            /**
             * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
             */
            public Object transform(Object input) {

                String author = String.valueOf(input);
                CmsFormDatabaseFilter filter = CmsFormDatabaseFilter.HEADERS;
                filter = filter.filterFormId(CmsCommentForm.FORM_ID);
                filter = filter.filterField(CmsCommentFormHandler.FIELD_USERNAME, author);
                try {
                    return new Integer(CmsFormDataAccess.getInstance().countForms(filter));
                } catch (SQLException e) {
                    if (LOG.isErrorEnabled()) {
                        LOG.error(e.getLocalizedMessage(), e);
                    }
                }
                return new Integer(0);
            }
        });
    }
    return m_countByAuthor;
}

From source file:mondrian.olap.IdBatchResolverTest.java

private Set<String> getResolvedNames(Map<QueryPart, QueryPart> resolvedIdents) {
    return new HashSet(CollectionUtils.collect(resolvedIdents.keySet(), new Transformer() {
        public Object transform(Object o) {
            return o.toString();
        }//from w  ww .  j av a 2 s  . c  o  m
    }));
}