Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2003, the JUNG Project and the Regents of the University | |
3 | * of California | |
4 | * All rights reserved. | |
5 | * | |
6 | * This software is open-source under the BSD license; see either | |
7 | * "license.txt" or | |
8 | * http://jung.sourceforge.net/license.txt for a description. | |
9 | */ | |
10 | package edu.uci.ics.jung.graph.impl; | |
11 | ||
12 | import edu.uci.ics.jung.graph.DirectedGraph; | |
13 | import edu.uci.ics.jung.graph.Edge; | |
14 | import edu.uci.ics.jung.graph.Vertex; | |
15 | import edu.uci.ics.jung.graph.predicates.TreePredicate; | |
16 | import edu.uci.ics.jung.utils.UserData; | |
17 | ||
18 | /** | |
19 | * An implementation of <code>Graph</code> that consists of a | |
20 | * <code>Vertex</code> set and a <code>DirectedEdge</code> set. | |
21 | * Further, a vertex can have no more than one incoming directed | |
22 | * edge (enforced with <code>TreePredicate</code>); the tree must | |
23 | * define a root vertex at construction time. | |
24 | * This implementation does NOT ALLOW parallel edges. | |
25 | * <code>SimpleDirectedSparseVertex</code> is the most efficient | |
26 | * vertex for this graph type. | |
27 | * | |
28 | * <p>Edge constraints imposed by this class: DIRECTED_EDGE, | |
29 | * <code>TreePredicate</code>, NOT_PARALLEL_EDGE | |
30 | * | |
31 | * <p>For additional system and user constraints defined for | |
32 | * this class, see the superclasses of this class.</p> | |
33 | * | |
34 | * @author Danyel Fisher | |
35 | * @author Joshua O'Madadhain | |
36 | * | |
37 | * @see DirectedSparseVertex | |
38 | * @see DirectedSparseEdge | |
39 | */ | |
40 | public class SparseTree extends SparseGraph | |
41 | implements DirectedGraph { | |
42 | ||
43 | protected Vertex mRoot; | |
44 | 1 | public static final Object SPARSE_ROOT_KEY = "edu.uci.ics.jung.graph.impl.SparseTree.RootKey"; |
45 | 1 | public static final Object IN_TREE_KEY = "edu.uci.ics.jung.graph.impl.SparseTree.InTreeKey"; |
46 | ||
47 | /** | |
48 | * @param root | |
49 | */ | |
50 | 1 | public SparseTree(Vertex root) { |
51 | 1 | edge_requirements.add(TreePredicate.getInstance()); |
52 | 1 | edge_requirements.add(DIRECTED_EDGE); |
53 | 1 | edge_requirements.add(NOT_PARALLEL_EDGE); |
54 | ||
55 | 1 | this.mRoot = root; |
56 | 1 | addVertex( root ); |
57 | 1 | mRoot.setUserDatum(SPARSE_ROOT_KEY, SPARSE_ROOT_KEY, UserData.SHARED); |
58 | 1 | mRoot.setUserDatum(IN_TREE_KEY, IN_TREE_KEY, UserData.SHARED); |
59 | 1 | } |
60 | ||
61 | /** | |
62 | * @return the root of this tree | |
63 | */ | |
64 | public Vertex getRoot() { | |
65 | 1 | return mRoot; |
66 | } | |
67 | ||
68 | /** | |
69 | * @see edu.uci.ics.jung.graph.Graph#addEdge(edu.uci.ics.jung.graph.Edge) | |
70 | */ | |
71 | public Edge addEdge(Edge e) { | |
72 | 5 | Edge rv = super.addEdge(e); |
73 | 2 | Vertex dest = (Vertex) rv.getEndpoints().getSecond(); |
74 | 2 | dest.setUserDatum(IN_TREE_KEY, IN_TREE_KEY, UserData.SHARED); |
75 | 2 | return rv; |
76 | } | |
77 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |