本文整理汇总了Java中edu.uci.ics.jung.graph.Tree类的典型用法代码示例。如果您正苦于以下问题:Java Tree类的具体用法?Java Tree怎么用?Java Tree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tree类属于edu.uci.ics.jung.graph包,在下文中一共展示了Tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBfs
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Test
public void testBfs() throws Exception {
DirectedGraph<URI, URI> graph = new DirectedSparseGraph<>();
graph.addVertex( YURI );
graph.addVertex( YUGO );
graph.addEdge( YPY, YURI, YUGO, EdgeType.DIRECTED );
Collection<URI> roots = Arrays.asList( YURI );
GraphToTreeConverter.Search search = GraphToTreeConverter.Search.BFS;
Forest<URI, URI> result = GraphToTreeConverter.convert( graph, roots, search );
assertEquals( 1, result.getTrees().size() );
Tree<URI, URI> tree = result.getTrees().iterator().next();
assertEquals( YURI, tree.getRoot() );
assertEquals( YUGO, tree.getChildren( YURI ).iterator().next() );
}
示例2: createGraph
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Override
public Graph<String, String> createGraph() {
Tree<String, String> graph = new DelegateTree<String, String>();
if (clusterModel.getRootNode() == null) {
return graph;
}
HierarchicalClusterNode root = clusterModel.getRootNode();
graph.addVertex("Root");
vertexMap.put("Root", root);
for (HierarchicalClusterNode subNode : clusterModel.getRootNode().getSubNodes()) {
createGraph(graph, "Root", subNode);
}
return graph;
}
示例3: testDfs
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Test
public void testDfs() throws Exception {
DirectedGraph<URI, URI> graph = new DirectedSparseGraph<>();
graph.addVertex( YURI );
graph.addVertex( YUGO );
graph.addEdge( YPY, YURI, YUGO, EdgeType.DIRECTED );
Collection<URI> roots = Arrays.asList( YURI );
GraphToTreeConverter.Search search = GraphToTreeConverter.Search.DFS;
Forest<URI, URI> result = GraphToTreeConverter.convert( graph, roots, search );
assertEquals( 1, result.getTrees().size() );
Tree<URI, URI> tree = result.getTrees().iterator().next();
assertEquals( YURI, tree.getRoot() );
assertEquals( YUGO, tree.getChildren( YURI ).iterator().next() );
}
示例4: print
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
private static void print( Tree<Parameter, Integer> tree, Parameter node ) {
if ( log.isDebugEnabled() ) {
StringBuilder sb = new StringBuilder( "Parameter Tree:" );
int depth = tree.getDepth( node );
for ( int i = 0; i < depth; i++ ) {
sb.append( " " );
}
sb.append( tree.getRoot().equals( node ) ? "<root>" : node );
log.debug( sb.toString() );
for ( Parameter p : tree.getChildren( node ) ) {
print( tree, p );
}
}
}
示例5: testRenameCluster
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Test
public void testRenameCluster() {
Tree<ClusterVO, ItemAssocVO<Integer,Integer>> clusters = clusterService.getClustersForTenant(1);
ClusterVO root = clusters.getRoot();
printCluster(clusters, root);
assertThat(clusters.getHeight(), is(2));
assertThat(clusters.getChildCount(root), is(2));
assertThat(clusters.getVertexCount(), is(5));
assertThat(clusterService.loadCluster(1,"CLUSTER3"), IsNull.nullValue());
try {
clusterService.renameCluster(1, "CLUSTER1", "CLUSTER3");
} catch (ClusterException ce) {
logger.info(ce);
}
printCluster(clusters, root);
assertThat(clusters.getHeight(), is(2));
assertThat(clusters.getChildCount(root), is(2));
assertThat(clusters.getVertexCount(), is(5));
assertThat(clusterService.loadCluster(1,"CLUSTER3"), IsNull.notNullValue());
}
示例6: getRoots
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
private Collection<V> getRoots(Forest<V, E> forest) {
Set<V> roots = new HashSet<V>();
for (Tree<V, E> tree : forest.getTrees()) {
roots.add(tree.getRoot());
}
return roots;
}
示例7: getTrees
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
public Collection<Tree<V, E>> getTrees() {
Collection<Tree<V,E>> trees = new HashSet<Tree<V,E>>();
for(V v : getRoots()) {
Tree<V,E> tree = new DelegateTree<V,E>();
tree.addVertex(v);
TreeUtils.growSubTree(this, tree, v);
trees.add(tree);
}
return trees;
}
示例8: convertq
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
/**
* Converts the given graph "quietly." It will not throw exceptions, but will
* skip edges to vertices that already have a parent edge
*
* @param graph
* @param root
* @return
*/
public Tree<V, E> convertq( DirectedGraph<V, E> graph, V root ) {
try {
return iconvert( graph, root, false );
}
catch ( Exception x ) {
log.error( "BUG: this exception should never be thrown!" );
}
return null;
}
示例9: printTree
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
public static <V, E> void printTree( V root,
Tree<V, E> tree, int depth ) {
StringBuilder sb = new StringBuilder();
for ( int i = 0; i < depth; i++ ) {
sb.append( " " );
}
sb.append( root );
log.debug( sb.toString() );
for ( V child : tree.getChildren( root ) ) {
printTree( child, tree, depth + 1 );
}
}
示例10: actionPerformed
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Override
public void actionPerformed( ActionEvent e ) {
ValueFactory vf = new ValueFactoryImpl();
Forest<SEMOSSVertex, SEMOSSEdge> forest
= GraphToTreeConverter.convertq( graph, selecteds, Search.BFS );
List<Value[]> rows = new ArrayList<>();
for ( Tree<SEMOSSVertex, SEMOSSEdge> tree : forest.getTrees() ) {
SEMOSSVertex root = tree.getRoot();
// we want a dfs of the tree to keep the nodes in a path together
Queue<SEMOSSVertex> q = Collections.asLifoQueue( new ArrayDeque<>() );
q.addAll( tree.getChildren( root ) );
while ( !q.isEmpty() ) {
SEMOSSVertex child = q.poll();
Value row[] = {
root.getURI(),
vf.createLiteral( tree.getDepth( child ) ),
child.getURI(),
child.getType()
};
rows.add( row );
q.addAll( tree.getChildren( child ) );
}
}
GridPlaySheet grid = new GridPlaySheet();
grid.create( rows, Arrays.asList( "Root Vertex", "Hops", "Child Vertex",
"Child Type" ), gps.getEngine() );
gps.addSibling( "Hops Downstream", grid );
}
示例11: fillInCombos
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
private void fillInCombos( Tree<Parameter, Integer> tree ) {
// we only need to run queries for the toplevel parameters, because
// everything else is handled by the item listener
for ( Parameter p : tree.getChildren( tree.getRoot() ) ) {
requery( p );
}
}
示例12: testGetClustersForTenant
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Test
public void testGetClustersForTenant() {
// before();
Tree <ClusterVO, ItemAssocVO<Integer,Integer>> clusters = clusterService.getClustersForTenant(1);
ClusterVO root = clusters.getRoot();
logger.info("name: " + root.getName());
logger.info("descr: " + root.getDescription());
logger.info("id: " + root.getItem().getItem());
logger.info("tenant: " + root.getItem().getTenant());
logger.info("type: " + root.getItem().getType());
// ClusterVO child = new ClusterVO(root.getItem().getTenant(),1000, root.getItem().getType(),"Cluster1", "The first Cluster!");
// try {
// clusterService.addCluster(1, "testCluster","This is a testCluster", ClusterService.ROOT);
// clusterService.addCluster(1, "testCluster2","This is testCluster2", ClusterService.ROOT);
// clusterService.addCluster(1, "testCluster3","This is testCluster3", ClusterService.ROOT);
//
// clusterService.addCluster(1, "testCluster4","This is testCluster4", "testCluster");
//
// } catch (ClusterException ce) {
// logger.error(ce);
// }
//
// logger.info(clusters.containsVertex(child));
// logger.info(clusters.getChildCount(root));
// logger.info(clusters.getChildCount(child));
// logger.info(clusters.getParent(child).getName());
// Collection<ClusterVO> children = clusters.getChildren(root);
// for (ClusterVO clusterVO : children) {
// logger.info(clusterVO.getName());
// }
//
//
// logger.info(clusters.toString());
}
示例13: testRemoveCluster
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Test
public void testRemoveCluster() {
Tree<ClusterVO, ItemAssocVO<Integer,Integer>> clusters = clusterService.getClustersForTenant(1);
ClusterVO root = clusters.getRoot();
printCluster(clusters, root);
assertThat(clusters.getHeight(), is(2));
assertThat(clusters.getChildCount(root), is(2));
assertThat(clusters.getVertexCount(), is(5));
clusterService.removeCluster(1, "CLUSTER1");
assertThat(clusters.getHeight(), is(1));
assertThat(clusters.getChildCount(root), is(1));
assertThat(clusters.getVertexCount(), is(2));
printCluster(clusters, root);
}
示例14: testMoveCluster
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Test
public void testMoveCluster() {
Tree<ClusterVO, ItemAssocVO<Integer,Integer>> clusters = clusterService.getClustersForTenant(1);
ClusterVO root = clusters.getRoot();
printCluster(clusters, root);
assertThat(clusters.getHeight(), is(2));
assertThat(clusters.getChildCount(root), is(2));
assertThat(clusters.getVertexCount(), is(5));
clusterService.moveCluster(1, "CLUSTER1", "CLUSTER2");
assertThat(clusters.getHeight(), is(3));
assertThat(clusters.getChildCount(root), is(1));
assertThat(clusters.getVertexCount(), is(5));
printCluster(clusters, root);
}
示例15: addItemToCluster_shouldThrowWhenNotAdded
import edu.uci.ics.jung.graph.Tree; //导入依赖的package包/类
@Test(expected = ClusterException.class)
public void addItemToCluster_shouldThrowWhenNotAdded() throws ClusterException {
Tree<ClusterVO, ItemAssocVO<Integer,Integer>> clusters = clusterService.getClustersForTenant(1);
ClusterVO root = clusters.getRoot();
ItemVO<Integer, Integer> newItem = new ItemVO<Integer, Integer>(TENANT_EASYREC.getId(), 1, 1);
int rowsModified = clusterService.addItemToCluster(root, newItem);
assertThat(rowsModified, is(1));
// this should throw
rowsModified = clusterService.addItemToCluster(root, newItem);
}