List of usage examples for org.apache.commons.collections15 Transformer transform
public O transform(I input);
From source file:org.datacleaner.widgets.visualization.JobGraphTransformers.java
public Transformer<Context<Graph<Object, JobGraphLink>, JobGraphLink>, Shape> getEdgeShapeTransformer() { final String edgeStyle = _userPreferences.getAdditionalProperties() .get(USER_PREFERENCES_PROPERTY_EDGE_STYLE); final Transformer<Context<Graph<Object, JobGraphLink>, JobGraphLink>, Shape> baseTransformer = getBaseEdgeShapeTransformer( edgeStyle);/*from w w w. j a va 2 s. com*/ return new Transformer<Context<Graph<Object, JobGraphLink>, JobGraphLink>, Shape>() { @Override public Shape transform(Context<Graph<Object, JobGraphLink>, JobGraphLink> input) { final Shape result = baseTransformer.transform(input); final JobGraphLink link = input.element; if (isCompoundRequirementLink(link)) { // make a double link (actually a wedge, but close // enough) to show that there are more than one filter // outcome coming from this source return new EdgeShape.Wedge<Object, JobGraphLink>(10).transform(input); } return result; } }; }
From source file:org.drugis.addis.entities.Study.java
private void transformMeasurementKeys(final Transformer<MeasurementKey, MeasurementKey> transform) { for (final MeasurementKey oldKey : new HashSet<MeasurementKey>(d_measurements.keySet())) { final MeasurementKey newKey = transform.transform(oldKey); if (oldKey != newKey) { final BasicMeasurement measurement = d_measurements.get(oldKey); d_measurements.remove(oldKey); d_measurements.put(newKey, measurement); }/*ww w. j a v a2s . c o m*/ } }
From source file:org.drugis.addis.entities.Study.java
private void transformUsedBy(final Transformer<UsedBy, UsedBy> transformer) { for (final StudyActivity sa : d_studyActivities) { final Set<UsedBy> newUsedBys = new HashSet<UsedBy>(); for (final UsedBy oldUsedBy : sa.getUsedBy()) { newUsedBys.add(transformer.transform(oldUsedBy)); }// www . j a v a 2 s .c o m sa.setUsedBy(newUsedBys); } }
From source file:org.drugis.mtc.jags.JagsSyntaxModel.java
/** * Transform the given map from parameters to -1 or +1 to a sum expression. *///ww w. j a v a 2 s . c o m public static String writeExpression(Map<NetworkParameter, Integer> pmtz, Transformer<NetworkParameter, String> transform) { List<String> terms = new ArrayList<String>(); final Set<NetworkParameter> keys = new TreeSet<NetworkParameter>(new ParameterComparator()); keys.addAll(pmtz.keySet()); for (NetworkParameter key : keys) { terms.add((pmtz.get(key) == -1 ? "-" : "") + transform.transform(key)); } return StringUtils.join(terms, " + "); }
From source file:org.drugis.mtc.parameterization.NetworkModel.java
/** * Apply a transformation to all (t_1, t_2) pairs of treatments where indexOf(t_1) < indexOf(t_2). *///from w w w.j a v a 2s. co m public static <O> List<O> transformTreatmentPairs(Network network, Transformer<Pair<Treatment>, ? extends O> transformer) { int n = network.getTreatments().size(); List<O> list = new ArrayList<O>(); for (int i = 0; i < n - 1; ++i) { for (int j = i + 1; j < n; ++j) { final Treatment ti = network.getTreatments().get(i); final Treatment tj = network.getTreatments().get(j); list.add(transformer.transform(new Pair<Treatment>(ti, tj))); } } return list; }
From source file:org.eclipse.titanium.graph.utils.GraphVizWriter.java
/** * Saves a given graph to a dot file, it also creates the file, or overwrites the old one * @param g/*from w ww .j a v a 2s . c o m*/ * : The jung graph to save * @param filename * : A string that points to the destination of the save * @param labeler * : A node object -> Node name converter object * @param graphName * : The name of the graph to export (usually this is set the project's name) * @throws IOException * On IO error */ public void save(final Graph<V, E> g, final String filename, final Transformer<V, String> labeler, final String graphName) throws IOException { final SortedSet<V> nodes = new TreeSet<V>(); final Map<V, SortedSet<V>> successors = new HashMap<V, SortedSet<V>>(); for (final V source : g.getVertices()) { final Collection<V> actSuccessors = g.getSuccessors(source); final SortedSet<V> successorTree = new TreeSet<V>(); for (final V destination : actSuccessors) { successorTree.add(destination); } nodes.add(source); successors.put(source, successorTree); } final BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(filename), "UTF-8")); writer.write("digraph \"" + graphName + "\" {\n"); for (final V from : nodes) { final Collection<V> actSuccessors = successors.get(from); for (final V to : actSuccessors) { writer.write("\t\"" + labeler.transform(from) + "\" -> \"" + labeler.transform(to) + "\";\n"); } if (g.getPredecessorCount(from) == 0 && actSuccessors.isEmpty()) { writer.write("\t\"" + labeler.transform(from) + "\";\n"); } } writer.write("}"); writer.close(); }
From source file:org.opendaylight.nic.of.renderer.algorithm.SuurballeAlgorithm.java
private Number calculateCost(final Transformer<V, Number> transformer, final E edge, final V source, final V destination) { double cost = 0; if (transformer.transform(source) != null) { double edgeWeight = defaultEdgeWeight.transform(edge).doubleValue(); double destinationWeight = (transformer.transform(destination).doubleValue()); double sourceWeight = transformer.transform(source).doubleValue(); cost = (edgeWeight - (destinationWeight + sourceWeight)); if (Math.abs(cost) < 0.000001) { cost = 0;//from w ww. j a v a 2s .c o m } else { cost = Double.POSITIVE_INFINITY; } } return cost; }
From source file:org.opendaylight.topoprocessing.utils.SuurballeAlgorithm.java
/** * Modify the cost of each edge in the graph by replacing the cost w(u,v) of every edge: * * <pre>/*w w w . j a v a2 s. co m*/ * c'(v,w) = c(v,w) - d (s,w) + d (s,v) * </pre> * * @param graph1 the graph * @param slTrans The shortest length transformer * @return the transformed graph */ private Transformer<E, Double> transformationFunction(Graph<V, E> graph1, Transformer<V, Number> slTrans) { Map<E, Double> map = new LinkedHashMap<E, Double>(); for (E link : graph1.getEdges()) { double newWeight; if (slTrans.transform(graph1.getSource(link)) == null) { newWeight = Double.MAX_VALUE; } else { newWeight = nev.transform(link) - slTrans.transform(graph1.getDest(link)).doubleValue() + slTrans.transform(graph1.getSource(link)).doubleValue(); if (Math.abs(newWeight) < MIN_WEIGHT) newWeight = 0; } map.put(link, newWeight); } return MapTransformer.getInstance(map); }
From source file:org.springframework.core.convert.support.ExtendedConversionUtils.java
public static final <S, T> Converter<S, T> toConverter(final Transformer<? super S, ? extends T> xformer) { Assert.notNull(xformer, "No transformer"); return new Converter<S, T>() { @Override// w w w .j a va 2 s . c o m public T convert(S source) { return xformer.transform(source); } }; }
From source file:org.springframework.jdbc.repo.impl.AbstractRawPropertiesRepoImpl.java
@Override public E getEntity(String id, Transformer<Map<String, ?>, ? extends E> transformer) { if (transformer == null) { throw new IllegalArgumentException("getEntity(" + id + ") no transformer"); }// w w w . j a v a2 s .com Map<String, Serializable> props = getProperties(id); if (ExtendedMapUtils.isEmpty(props)) { return null; } else { return transformer.transform(props); } }