List of usage examples for org.apache.commons.collections CollectionUtils transform
public static void transform(Collection collection, Transformer transformer)
From source file:info.magnolia.cms.util.ContentUtilTest.java
@Test public void testOrderAfterLastNode() throws RepositoryException, IOException { MockHierarchyManager hm = MockUtil.createHierarchyManager("/node/a\n" + "/node/b\n" + "/node/c\n"); Content node = hm.getContent("/node"); Content a = node.getContent("a"); ContentUtil.orderAfter(a, "c"); Collection<Content> result = node.getChildren(); CollectionUtils.transform(result, new Transformer() { @Override//from ww w . j a va 2 s. c o m public Object transform(Object childObj) { return ((Content) childObj).getName(); } }); assertEquals(asList("b", "c", "a"), result); }
From source file:jp.ikedam.jenkins.plugins.extensible_choice_parameter.GlobalTextareaChoiceListProviderJenkinsTest.java
@SuppressWarnings("unchecked") // CollectionUtils.transformedCollection is not generic. @Test// w w w .j a v a 2 s .c o m public void testDescriptorDoFillNameItems() { GlobalTextareaChoiceListProvider.DescriptorImpl descriptor = getDescriptor(); // Easy case { List<String> nameList = Arrays.asList("entry1", "entry2", "entry3"); @SuppressWarnings("rawtypes") List choiceListEntry = new ArrayList(nameList); CollectionUtils.transform(choiceListEntry, new Transformer() { @Override public Object transform(Object input) { return new GlobalTextareaChoiceListEntry((String) input, "value1\nvalue2\n", false); } }); descriptor.setChoiceListEntryList(choiceListEntry); ListBoxModel fillList = descriptor.doFillNameItems(); @SuppressWarnings("rawtypes") List optionList = new ArrayList(nameList); CollectionUtils.transform(optionList, new Transformer() { @Override public Object transform(Object input) { String name = (String) input; return new ListBoxModel.Option(name, name); } }); ListBoxModel expected = new ListBoxModel(optionList); assertListBoxEquals("Easy case", expected, fillList); } // Empty { descriptor.setChoiceListEntryList(new ArrayList<GlobalTextareaChoiceListEntry>(0)); ListBoxModel fillList = descriptor.doFillNameItems(); ListBoxModel expected = new ListBoxModel(); assertListBoxEquals("Empty", expected, fillList); } // null { descriptor.setChoiceListEntryList(null); ListBoxModel fillList = descriptor.doFillNameItems(); ListBoxModel expected = new ListBoxModel(); assertListBoxEquals("null", expected, fillList); } }
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/*from w w w. j av a2s.co m*/ 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 .ja v a 2 s. c om public Object transform(Object childObj) { return ((Content) childObj).getName(); } }); assertEquals(asList("a", "b", "d", "e", "f", "c"), result); }
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//w w w .j a v a 2 s .co 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// www . j a v a 2 s .c o m public Object transform(Object childObj) { return ((Content) childObj).getName(); } }); assertEquals(asList("a", "c", "b"), result); }
From source file:net.sf.wickedshell.ui.shell.viewer.proposal.CompletionController.java
/** * Identifies all possible enviromental value completion for the given * prefix./*from ww w .j a v a 2s. c om*/ * * @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//from www. ja v a 2 s.co m public Object transform(Object childObj) { return ((Content) childObj).getName(); } }); assertEquals(Arrays.asList(new String[] { "c", "a", "b" }), result); }
From source file:com.architexa.diagrams.relo.jdt.parts.CompartmentedCodeUnitEditPart.java
protected void emptyCompartments() { List<EditPart> visChildren = getVisibleEditPartChildren(); List<Object> txVisChildren = new ArrayList<Object>(visChildren); CollectionUtils.transform(txVisChildren, new Transformer() { public Object transform(Object input) { if (input instanceof ArtifactEditPart) { return ((ArtifactEditPart) input).getArtifact(); } else return null; }/*from w ww . ja v a 2 s. co m*/ }); removeChildrenArtifacts(txVisChildren); }
From source file:info.magnolia.cms.util.ContentUtilTest.java
@Test public void testOrderAfterFirstNodeMoreThanThreeVariation1() 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("f"); ContentUtil.orderAfter(c, "a"); Collection<Content> result = node.getChildren(); CollectionUtils.transform(result, new Transformer() { @Override//from w ww .ja va2 s . co m public Object transform(Object childObj) { return ((Content) childObj).getName(); } }); assertEquals(asList("a", "f", "b", "c", "d", "e"), result); }