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:info.magnolia.test.mock.MockContentTest.java

@Test
public void testOrderBefore() throws RepositoryException, IOException {
    MockHierarchyManager hm = MockUtil.createHierarchyManager("/node/a\n" + "/node/b\n" + "/node/c\n");
    Content node = hm.getContent("/node");
    node.orderBefore("c", "b");
    Collection<Content> result = node.getChildren();
    // transform to collection of names
    CollectionUtils.transform(result, new Transformer() {
        @Override/*  w ww  .jav a2 s.c om*/
        public Object transform(Object childObj) {
            return ((Content) childObj).getName();
        }
    });
    assertEquals(Arrays.asList(new String[] { "a", "c", "b" }), result);
}

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

@Test
public void testOrderAfterLastNodeVariation1() 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 a = node.getContent("c");
    ContentUtil.orderAfter(a, "f");
    Collection<Content> result = node.getChildren();
    CollectionUtils.transform(result, new Transformer() {
        @Override//from  ww  w .  java2 s.  com
        public Object transform(Object childObj) {
            return ((Content) childObj).getName();
        }
    });
    assertEquals(asList("a", "b", "d", "e", "f", "c"), result);
}

From source file:gov.nih.nci.caarray.web.fileupload.MonitoredMultiPartRequest.java

/**
 * {@inheritDoc}/*from w w  w .  ja va2s.c  om*/
 */
public String[] getFilesystemName(String fieldName) {
    return transformFileItemsForField(fieldName, ArrayUtils.EMPTY_STRING_ARRAY, new Transformer() {
        public Object transform(Object o) {
            return ((DiskFileItem) o).getStoreLocation().getName();
        }
    });
}

From source file:net.big_oh.algorithms.graph.clique.MaximalCliqueFinderFunctionalTest.java

private void testFindMaximalCliques_MultipleCliques_WithNoise(int numNonCliqueNodes, int... cliqueSizes) {
    if (numNonCliqueNodes < 0) {
        throw new IllegalArgumentException("numNonCliqueNodes cannot be less than zero.");
    }//from   w ww. ja  v a  2  s  .  c o m

    if (cliqueSizes.length <= 0) {
        throw new IllegalArgumentException("must provide one or more cliqueSize arguments.");
    }

    final CliqueTestGraphBuilder graphBuilder = new CliqueTestGraphBuilder();
    for (int cliqueSize : cliqueSizes) {
        graphBuilder.addClique(cliqueSize);
    }
    graphBuilder.setNumNonCliqueNodes(numNonCliqueNodes);

    final JungUndirectedGraph multiCliqueGraph = graphBuilder.build();

    // find cliques of size 3 or greater; can't use size 2 because of noise
    // nodes that are connected to one node in each clique
    Set<Set<JungVertex>> maximalCliques = cliqueFinder.findMaximalCliques(multiCliqueGraph, 3);

    assertNotNull(maximalCliques);
    assertEquals("Failed to find expected number of maximal cliques.", cliqueSizes.length,
            maximalCliques.size());

    // extract the _sizes_ of all discovered maximal cliques
    @SuppressWarnings("unchecked")
    Collection<Integer> maximalCliqueSizes = CollectionUtils.collect(maximalCliques, new Transformer() {
        public Object transform(Object input) {
            Set<JungVertex> clique = (Set<JungVertex>) input;
            return Integer.valueOf(clique.size());
        }
    });

    // the collection of input clique sizes should be equal to the
    // collection of discovered clique sizes
    assertTrue(CollectionUtils.isEqualCollection(Arrays.asList(ArrayUtils.toObject(cliqueSizes)),
            maximalCliqueSizes));
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.manager.executionCourseManagement.SeperateExecutionCourse.java

private static Set<String> getExecutionCourseCodes(ExecutionSemester executionSemester) {
    Collection<ExecutionCourse> executionCourses = executionSemester.getAssociatedExecutionCoursesSet();
    return new HashSet<String>(CollectionUtils.collect(executionCourses, new Transformer() {
        @Override//from ww w .j a  va2s . co m
        public Object transform(Object arg0) {
            ExecutionCourse executionCourse = (ExecutionCourse) arg0;
            return executionCourse.getSigla().toUpperCase();
        }
    }));
}

From source file:info.magnolia.test.mock.MockContentTest.java

@Test
public void testOrderBefore2() throws RepositoryException, IOException {
    MockHierarchyManager hm = MockUtil.createHierarchyManager("/node/a\n" + "/node/b\n" + "/node/c\n");
    Content node = hm.getContent("/node");
    node.orderBefore("a", "c");
    Collection<Content> result = node.getChildren();
    // transform to collection of names
    CollectionUtils.transform(result, new Transformer() {
        @Override//from w w w. ja  va  2 s . c  o  m
        public Object transform(Object childObj) {
            return ((Content) childObj).getName();
        }
    });
    assertEquals(Arrays.asList(new String[] { "b", "a", "c" }), result);
}

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

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

From source file:mondrian.olap.IdBatchResolver.java

/**
 * Filters the children list to those that contain identifiers
 * we think we can batch resolve, then transforms the Id list
 * to the corresponding NameSegment.//ww w  .ja  v a 2s.c  o m
 */
private List<Id.NameSegment> collectChildrenNameSegments(final Member parentMember, List<Id> children) {
    filter(children, new Predicate() {
        // remove children we can't support
        public boolean evaluate(Object theId) {
            Id id = (Id) theId;
            return !Util.matches(parentMember, id.getSegments()) && supportedIdentifier(id);
        }
    });
    return new ArrayList(CollectionUtils.collect(children, new Transformer() {
        // convert the collection to a list of NameSegments
        public Object transform(Object theId) {
            Id id = (Id) theId;
            return getLastSegment(id);
        }
    }));
}

From source file:net.sf.wickedshell.ui.shell.viewer.proposal.CompletionController.java

/**
 * Identifies all possible enviromental value completion for the given
 * prefix.//from w w w  . ja va 2  s . c  o  m
 * 
 * @return the <code>List</code> of <code>Completions</code> referring
 *         to the given prefix
 */
@SuppressWarnings("unchecked")
public static List getEnviromentalValueCompletions(IShellDescriptor descriptor,
        final String environmentalValuePrefix, final String command) {
    List currentEnviromentalValueCompletions = new ArrayList();
    CollectionUtils.select(descriptor.getEnviromentalValues().entrySet(), new Predicate() {
        public boolean evaluate(Object object) {
            Entry entry = (Entry) object;
            String enviromentalValue = (String) entry.getKey();
            return enviromentalValue.toLowerCase().startsWith(environmentalValuePrefix.toLowerCase());
        }
    }, currentEnviromentalValueCompletions);
    CollectionUtils.transform(currentEnviromentalValueCompletions, new Transformer() {
        public Object transform(Object object) {
            Entry entry = (Entry) object;
            String completion = command + (String) entry.getKey();
            String description = (String) entry.getKey() + " <" + (String) entry.getValue()
                    + "> - Environmental value (Cascading completion)";
            String imagePath = "img/environmentalValue.gif";
            return ICompletion.Factory.newInstance(completion, description, imagePath);
        }
    });

    Collections.sort(currentEnviromentalValueCompletions, new CompletionComparator());
    return currentEnviromentalValueCompletions;
}

From source file:info.magnolia.test.mock.MockContentTest.java

@Test
public void testOrderBeforeFirstNode() throws RepositoryException, IOException {
    MockHierarchyManager hm = MockUtil.createHierarchyManager("/node/a\n" + "/node/b\n" + "/node/c\n");
    Content node = hm.getContent("/node");
    node.orderBefore("c", "a");
    Collection<Content> result = node.getChildren();
    // transform to collection of names
    CollectionUtils.transform(result, new Transformer() {
        @Override//  w  ww  .ja  v a 2 s. c o m
        public Object transform(Object childObj) {
            return ((Content) childObj).getName();
        }
    });
    assertEquals(Arrays.asList(new String[] { "c", "a", "b" }), result);
}