List of usage examples for org.apache.commons.collections Transformer transform
Object transform(Object input);
From source file:TransformerExampleV1.java
public static void main(String args[]) { Transformer transformer = TransformerUtils.invokerTransformer("append", new Class[] { String.class }, new Object[] { " a Transformer?" }); Object newObject = transformer.transform(new StringBuffer("Are you")); System.err.println(newObject); }
From source file:AIR.Common.collections.IGrouping.java
public static <K, V> List<IGrouping<K, V>> createGroups(Collection<V> list, Transformer transformer) { Map<K, IGrouping<K, V>> map = new HashMap<K, IGrouping<K, V>>(); for (V element : list) { @SuppressWarnings("unchecked") K groupValue = (K) transformer.transform(element); IGrouping<K, V> group = null; if (map.containsKey(groupValue)) { group = map.get(groupValue); } else {// w ww . ja v a 2 s . c o m group = new IGrouping<K, V>(groupValue); map.put(groupValue, group); } group.add(element); } return new ArrayList<IGrouping<K, V>>(map.values()); }
From source file:edu.isistan.carcha.util.Utils.java
/** * Transformed list.// ww w . jav a 2s. c o m * * @param list the list * @param transformer the transformer * @return the list */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static List transformedList(List list, Transformer transformer) { List ret = new ArrayList<Entity>(); for (Object item : list) { ret.add(transformer.transform(item)); } return ret; }
From source file:gov.nih.nci.caarray.security.SecurityPolicy.java
private static void applyTransformations(Set<SecurityPolicy> policies, Object entity, PropertyAccessor propAccessor) throws IllegalAccessException, InvocationTargetException { Transformer transformer = getPropertyTransformer(policies, propAccessor); if (transformer != null) { Object originalVal = propAccessor.get(entity); Object transformedVal = transformer.transform(originalVal); propAccessor.set(entity, transformedVal); }/*from www . ja va2 s.c o m*/ Closure mutator = getPropertyMutator(policies, propAccessor); if (mutator != null) { mutator.execute(propAccessor.get(entity)); } }
From source file:edu.harvard.med.screensaver.util.CollectionUtils.java
/** * Indexes a collection by creating a map that allows each element of the * specified collection to be looked up by its key. The key of each element is * determined by calling the <code>makeKey</code> Transformer on that * element. I sure miss Lisp./*from w ww .j av a 2s .c o m*/ * * @return a Map */ public static <K, E> Map<K, E> indexCollection(Collection c, final Transformer getKey, Class<K> keyClass, Class<E> elementClass) { final Map<K, E> map = new HashMap<K, E>(c.size()); org.apache.commons.collections.CollectionUtils.forAllDo(c, new Closure() { @SuppressWarnings("unchecked") public void execute(Object e) { map.put((K) getKey.transform(e), (E) e); } }); return map; }
From source file:com.phoenixst.plexus.GraphUtils.java
/** * Helper method for getFirstCommonNode(). *//*from w ww .ja va 2 s . com*/ private static List getWalk(Object node, Transformer incidentEdgeGetter) { List list = new ArrayList(); list.add(node); Graph.Edge edge = (Graph.Edge) incidentEdgeGetter.transform(node); while (edge != null) { node = edge.getOtherEndpoint(node); list.add(node); edge = (Graph.Edge) incidentEdgeGetter.transform(node); } list.add(null); return list; }
From source file:info.evanchik.eclipse.karaf.core.features.Bundle.java
@Override public Object getParent() { final Transformer transformer = new ElementTransformer(); return transformer.transform(element.getParentElement()); }
From source file:com.projity.grouping.core.model.NodeModelFactory.java
private void replicate(NodeModel source, Node sourceParentNode, Node newParentNode, NodeModel newModel, Transformer transformer) { Collection children = source.getHierarchy().getChildren(sourceParentNode); if (children != null) { Iterator i = children.iterator(); while (i.hasNext()) { Node sourceNode = (Node) i.next(); Object newImpl = transformer.transform(sourceNode.getImpl()); // make a new object from source if (newImpl == null) continue; Node newNode = NodeFactory.getInstance().createNode(newImpl); // make a new node newModel.add(newParentNode, newNode, NodeModel.SILENT); replicate(source, sourceNode, newNode, newModel, transformer); }/* w ww. j ava 2 s .co m*/ } }
From source file:com.phoenixst.plexus.traversals.PostOrderTraverser.java
/** * Creates a new <code>PostOrderTraverser</code>. If the * <code>graph</code> argument is <code>null</code>, the * specified <code>startNode</code> cannot be removed by {@link * #remove}.// www .jav a 2s .co m */ public PostOrderTraverser(Object startNode, Graph graph, Transformer traverserFactory) { super(); this.traverserFactory = traverserFactory; if (traverserFactory == null) { throw new IllegalArgumentException("Traverser Factory is null."); } if (graph == null) { // This is the only way to make sure that startNode is in // the graph in this case. traverserFactory.transform(startNode); } else if (!graph.containsNode(startNode)) { throw new NoSuchNodeException("Graph does not contain start node: " + startNode); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Constructor: Pushing trivial Traverser to " + startNode + " onto Traverser stack."); } traverserStack.push(new SingletonTraverser(graph, startNode, null)); }
From source file:com.phoenixst.plexus.traversals.Walker.java
/** * Creates a new <code>Walker</code>. If the <code>graph</code> * argument is <code>null</code>, the <code>Walker</code> will be * unmodifiable./*from w w w . j a v a2 s. c o m*/ */ public Walker(Object startNode, Graph graph, Transformer incidentEdgeGetter) { super(); this.graph = graph; this.incidentEdgeGetter = incidentEdgeGetter; if (incidentEdgeGetter == null) { throw new IllegalArgumentException("Incident Edge Getter is null."); } if (graph == null) { // This is the only way to make sure that startNode is in // the graph in this case. incidentEdgeGetter.transform(startNode); } else if (!graph.containsNode(startNode)) { throw new NoSuchNodeException("Graph does not contain start node: " + startNode); } currentNode = startNode; }