本文整理汇总了Java中org.apache.commons.collections15.functors.ConstantTransformer类的典型用法代码示例。如果您正苦于以下问题:Java ConstantTransformer类的具体用法?Java ConstantTransformer怎么用?Java ConstantTransformer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstantTransformer类属于org.apache.commons.collections15.functors包,在下文中一共展示了ConstantTransformer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSwitchMapTransformer
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
public void testSwitchMapTransformer() {
Transformer a = TransformerUtils.constantTransformer("A");
Transformer b = TransformerUtils.constantTransformer("B");
Transformer c = TransformerUtils.constantTransformer("C");
Map map = new HashMap();
map.put("HELLO", a);
map.put("THERE", b);
assertEquals(null, TransformerUtils.switchMapTransformer(map).transform("WELL"));
assertEquals("A", TransformerUtils.switchMapTransformer(map).transform("HELLO"));
assertEquals("B", TransformerUtils.switchMapTransformer(map).transform("THERE"));
map.put(null, c);
assertEquals("C", TransformerUtils.switchMapTransformer(map).transform("WELL"));
assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchMapTransformer(new HashMap()));
map = new HashMap();
map.put(null, null);
assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchMapTransformer(map));
try {
TransformerUtils.switchMapTransformer(null);
fail();
} catch (IllegalArgumentException ex) {
}
}
示例2: actionPerformed
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent();
if(viewerPanel.isEdgeLabel()){
viewerPanel.getVisualizationViewer().getRenderContext().setEdgeLabelTransformer(new ConstantTransformer(null));
viewerPanel.getVisualizationViewer().repaint();
viewerPanel.setEdgeLabel(false);
}
else{
viewerPanel.getVisualizationViewer().getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<String>());
viewerPanel.getVisualizationViewer().repaint();
viewerPanel.setEdgeLabel(true);
}
}
示例3: MinimumSpanningForest
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
/**
* Creates a minimum spanning forest from the supplied graph, populating the
* supplied Forest, which must be empty.
* If the supplied root is null, or not present in the Graph,
* then an arbitrary Graph vertex will be selected as the root.
* If the Minimum Spanning Tree does not include all vertices of the
* Graph, then a leftover vertex is selected as a root, and another
* tree is created
* @param graph the Graph to find MST in
* @param forest the Forest to populate. Must be empty
* @param root first Tree root, may be null
*/
@SuppressWarnings("unchecked")
public MinimumSpanningForest(Graph<V, E> graph, Forest<V,E> forest,
V root) {
if(forest.getVertexCount() != 0) {
throw new IllegalArgumentException("Supplied Forest must be empty");
}
this.graph = graph;
this.forest = forest;
this.weights = LazyMap.decorate(new HashMap<E,Double>(),
new ConstantTransformer(1.0));
Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges());
if(graph.getVertices().contains(root)) {
this.forest.addVertex(root);
}
updateForest(forest.getVertices(), unfinishedEdges);
}
示例4: newLayout
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
private Layout<Node, Edge> newLayout(final Diagram diagram) {
final Layout<Node, Edge> diagramLayout;
if (layout != null && layout.startsWith("spring")) {
diagramLayout = new SpringLayout<Node, Edge>(diagram, new ConstantTransformer(Integer.parseInt(config("spring", "100"))));
} else if (layout != null && layout.startsWith("kk")) {
Distance<Node> distance = new DijkstraDistance<Node, Edge>(diagram);
if (layout.endsWith("unweight")) {
distance = new UnweightedShortestPath<Node, Edge>(diagram);
}
diagramLayout = new KKLayout<Node, Edge>(diagram, distance);
} else if (layout != null && layout.equalsIgnoreCase("circle")) {
diagramLayout = new CircleLayout<Node, Edge>(diagram);
} else if (layout != null && layout.equalsIgnoreCase("fr")) {
diagramLayout = new FRLayout<Node, Edge>(diagram);
} else {
final LevelLayout levelLayout = new LevelLayout(diagram);
levelLayout.adjust = adjust;
diagramLayout = levelLayout;
}
return diagramLayout;
}
示例5: VisualizationImageServerDemo
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
/**
*
*/
public VisualizationImageServerDemo() {
// create a simple graph for the demo
graph = new DirectedSparseMultigraph<String, Number>();
String[] v = createVertices(10);
createEdges(v);
vv = new VisualizationImageServer<String,Number>(new KKLayout<String,Number>(graph), new Dimension(600,600));
vv.getRenderer().setVertexRenderer(
new GradientVertexRenderer<String,Number>(
Color.white, Color.red,
Color.white, Color.blue,
vv.getPickedVertexState(),
false));
vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.lightGray));
vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.lightGray));
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
// create a frome to hold the graph
final JFrame frame = new JFrame();
Container content = frame.getContentPane();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Image im = vv.getImage(new Point2D.Double(300,300), new Dimension(600,600));
Icon icon = new ImageIcon(im);
JLabel label = new JLabel(icon);
content.add(label);
frame.pack();
frame.setVisible(true);
}
示例6: testConstantTransformer
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
public void testConstantTransformer() {
assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(null));
assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cObject));
assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cString));
assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cInteger));
assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.constantTransformer(null));
}
示例7: testMapTransformer
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
public void testMapTransformer() {
Map map = new HashMap();
map.put(null, new Integer(0));
map.put(cObject, new Integer(1));
map.put(cString, new Integer(2));
assertEquals(new Integer(0), TransformerUtils.mapTransformer(map).transform(null));
assertEquals(new Integer(1), TransformerUtils.mapTransformer(map).transform(cObject));
assertEquals(new Integer(2), TransformerUtils.mapTransformer(map).transform(cString));
assertEquals(null, TransformerUtils.mapTransformer(map).transform(cInteger));
assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.mapTransformer(null));
}
示例8: actionPerformed
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent();
if(viewerPanel.isVertexLabel()){
viewerPanel.getVisualizationViewer().getRenderContext().setVertexLabelTransformer(new ConstantTransformer(null));
viewerPanel.getVisualizationViewer().repaint();
viewerPanel.setVertexLabel(false);
}
else{
viewerPanel.getVisualizationViewer().getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
viewerPanel.getVisualizationViewer().repaint();
viewerPanel.setVertexLabel(true);
}
}
示例9: TreePane
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
public TreePane(Dominoes domino) {
// create a simple graph for the demo
graph = new DelegateForest<>();
graph.addVertex(domino.getHistoric());
this.createTree(domino.getHistoric());
treeLayout = new TreeLayout<>(graph);
final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
vv = new VisualizationViewer<>(treeLayout, new Dimension(600, 600));
vv.setBackground(Color.white);
vv.getRenderContext().setVertexFillPaintTransformer(new ConstantTransformer(Color.GRAY));
vv.getRenderContext().setEdgeFillPaintTransformer(new ConstantTransformer(Color.BLACK));
vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.setGraphMouse(graphMouse);
// add a listener for ToolTips
vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.WHITE));
SwingNode s = new SwingNode();
s.setContent(vv);
this.getChildren().add(s);
}
示例10: VertexShapeFactory
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
/**
* Creates a <code>VertexShapeFactory</code> with a constant size of
* 10 and a constant aspect ratio of 1.
*/
@SuppressWarnings("unchecked")
public VertexShapeFactory()
{
this(new ConstantTransformer(10),
new ConstantTransformer(1.0f));
}
示例11: BetweennessCentrality
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
/**
* Calculates betweenness scores based on the all-pairs unweighted shortest paths
* in the graph.
* @param graph the graph for which the scores are to be calculated
*/
@SuppressWarnings("unchecked")
public BetweennessCentrality(Graph<V, E> graph)
{
initialize(graph);
computeBetweenness(new LinkedList<V>(), new ConstantTransformer(1));
}
示例12: HITSWithPriors
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
/**
* Creates an instance for the specified graph, vertex priors, and random
* jump probability (alpha). The edge weights default to 1.0.
* @param g the input graph
* @param vertex_priors the prior probability for each vertex
* @param alpha the probability of a random jump at each step
*/
@SuppressWarnings("unchecked")
public HITSWithPriors(Hypergraph<V,E> g,
Transformer<V, HITS.Scores> vertex_priors, double alpha)
{
super(g, new ConstantTransformer(1.0), vertex_priors, alpha);
disappearing_potential = new HITS.Scores(0,0);
}
示例13: getShape
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Transformer<V, Shape> getShape() {
Transformer<V, Shape> vertexShapeTransformer = new ConstantTransformer(
new Ellipse2D.Float(-currentSize, -currentSize,
currentSize * 2, currentSize * 2));
return vertexShapeTransformer;
}
示例14: startFunction
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
public JPanel startFunction() {
Graph<Integer,Number> g = getGraph();
Layout<Integer,Number> layout = new FRLayout<Integer,Number>(g);
// layout.setSize(new Dimension(5000,5000));
vv = new VisualizationViewer<Integer,Number>(layout);
PickedState<Integer> picked_state = vv.getPickedVertexState();
// affineTransformer = vv.getLayoutTransformer();
self_loop = new SelfLoopEdgePredicate<Integer,Number>();
// create decorators
seedFillColor = new SeedFillColor<Integer>(picked_state);
seedDrawColor = new SeedDrawColor<Integer>(picked_state);
ewcs =
new EdgeWeightStrokeFunction<Number>(edge_weight);
vsh = new VertexStrokeHighlight<Integer,Number>(g, picked_state);
vff = new VertexFontTransformer<Integer>();
eff = new EdgeFontTransformer<Number>();
vs_none = new ConstantTransformer(null);
es_none = new ConstantTransformer(null);
vssa = new VertexShapeSizeAspect<Integer,Number>(g, voltages);
show_edge = new DirectionDisplayPredicate<Integer,Number>(true, true);
show_arrow = new DirectionDisplayPredicate<Integer,Number>(true, false);
show_vertex = new VertexDisplayPredicate<Integer,Number>(false);
// uses a gradient edge if unpicked, otherwise uses picked selection
edgeDrawPaint =
new GradientPickedEdgePaintFunction<Integer,Number>(
new PickableEdgePaintTransformer<Number>(
vv.getPickedEdgeState(),Color.black,Color.cyan), vv);
edgeFillPaint =
new GradientPickedEdgePaintFunction<Integer,Number>(
new PickableEdgePaintTransformer<Number>(
vv.getPickedEdgeState(),Color.black,Color.cyan), vv);
vv.getRenderContext().setVertexFillPaintTransformer(seedFillColor);
vv.getRenderContext().setVertexDrawPaintTransformer(seedDrawColor);
vv.getRenderContext().setVertexStrokeTransformer(vsh);
vv.getRenderContext().setVertexLabelTransformer(vs_none);
vv.getRenderContext().setVertexFontTransformer(vff);
vv.getRenderContext().setVertexShapeTransformer(vssa);
vv.getRenderContext().setVertexIncludePredicate(show_vertex);
vv.getRenderContext().setEdgeDrawPaintTransformer( edgeDrawPaint );
vv.getRenderContext().setEdgeLabelTransformer(es_none);
vv.getRenderContext().setEdgeFontTransformer(eff);
vv.getRenderContext().setEdgeStrokeTransformer(ewcs);
vv.getRenderContext().setEdgeIncludePredicate(show_edge);
vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Integer,Number>());
vv.getRenderContext().setEdgeArrowPredicate(show_arrow);
vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.black));
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
vv.setBackground(Color.white);
GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(vv);
jp.add(scrollPane);
gm = new DefaultModalGraphMouse<Integer, Number>();
vv.setGraphMouse(gm);
gm.add(new PopupGraphMousePlugin());
addBottomControls( jp );
vssa.setScaling(true);
vv.setVertexToolTipTransformer(new VoltageTips<Number>());
vv.setToolTipText("<html><center>Use the mouse wheel to zoom<p>Click and Drag the mouse to pan<p>Shift-click and Drag to Rotate</center></html>");
return jp;
}
示例15: init
import org.apache.commons.collections15.functors.ConstantTransformer; //导入依赖的package包/类
@Override
public void init() {
//create a graph
Graph<Number,Number> ig = Graphs.<Number,Number>synchronizedDirectedGraph(new DirectedSparseMultigraph<Number,Number>());
ObservableGraph<Number,Number> og = new ObservableGraph<Number,Number>(ig);
og.addGraphEventListener(new GraphEventListener<Number,Number>() {
public void handleGraphEvent(GraphEvent<Number, Number> evt) {
System.err.println("got "+evt);
}});
this.g = og;
//create a graphdraw
layout = new FRLayout2<Number,Number>(g);
// ((FRLayout)layout).setMaxIterations(200);
vv = new VisualizationViewer<Number,Number>(layout, new Dimension(600,600));
JRootPane rp = this.getRootPane();
rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
getContentPane().setLayout(new BorderLayout());
getContentPane().setBackground(java.awt.Color.lightGray);
getContentPane().setFont(new Font("Serif", Font.PLAIN, 12));
vv.getModel().getRelaxer().setSleepTime(500);
vv.setGraphMouse(new DefaultModalGraphMouse<Number,Number>());
vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>());
vv.setForeground(Color.white);
getContentPane().add(vv);
switchLayout = new JButton("Switch to SpringLayout");
switchLayout.addActionListener(new ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent ae) {
Dimension d = new Dimension(600,600);
if (switchLayout.getText().indexOf("Spring") > 0) {
switchLayout.setText("Switch to FRLayout");
layout = new SpringLayout<Number,Number>(g,
new ConstantTransformer(EDGE_LENGTH));
layout.setSize(d);
vv.getModel().setGraphLayout(layout, d);
} else {
switchLayout.setText("Switch to SpringLayout");
layout = new FRLayout<Number,Number>(g, d);
vv.getModel().setGraphLayout(layout, d);
}
}
});
getContentPane().add(switchLayout, BorderLayout.SOUTH);
timer = new Timer();
}