Package edu.uci.ics.jung.graph
Class OrderedKAryTree<V,E>
- java.lang.Object
-
- edu.uci.ics.jung.graph.AbstractGraph<V,E>
-
- edu.uci.ics.jung.graph.AbstractTypedGraph<V,E>
-
- edu.uci.ics.jung.graph.OrderedKAryTree<V,E>
-
- All Implemented Interfaces:
edu.uci.ics.jung.graph.DirectedGraph<V,E>,edu.uci.ics.jung.graph.Forest<V,E>,edu.uci.ics.jung.graph.Graph<V,E>,edu.uci.ics.jung.graph.Hypergraph<V,E>,edu.uci.ics.jung.graph.Tree<V,E>,java.io.Serializable
public class OrderedKAryTree<V,E> extends AbstractTypedGraph<V,E> implements edu.uci.ics.jung.graph.Tree<V,E>
An implementation ofTreein which each vertex has <= k children. The value of 'k' is specified by the constructor parameter. A specific child (edge) can be retrieved directly by specifying the index at which the child is located. By default, new (child) vertices are added at the lowest index available, if no index is specified.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classOrderedKAryTree.VertexData
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<E,edu.uci.ics.jung.graph.util.Pair<V>>edge_vpairsprotected intheightprotected intorderprotected Vrootprotected java.util.Map<V,OrderedKAryTree.VertexData>vertex_data-
Fields inherited from class edu.uci.ics.jung.graph.AbstractTypedGraph
edge_type
-
-
Constructor Summary
Constructors Constructor Description OrderedKAryTree(int order)Creates a new instance with the specified order (maximum number of children).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddEdge(E edge, edu.uci.ics.jung.graph.util.Pair<? extends V> endpoints, edu.uci.ics.jung.graph.util.EdgeType edgeType)Addsedgeto this graph with the specifiedendpointsandEdgeType.booleanaddEdge(E edge, java.util.Collection<? extends V> vertices, edu.uci.ics.jung.graph.util.EdgeType edge_type)booleanaddEdge(E e, V parent, V child)booleanaddEdge(E e, V parent, V child, int index)Adds the specifiedchildvertex and edgeeto the graph with the specified parent vertexparent.booleanaddEdge(E e, V v1, V v2, edu.uci.ics.jung.graph.util.EdgeType edge_type)booleanaddVertex(V vertex)booleancontainsEdge(E edge)booleancontainsVertex(V vertex)EfindEdge(V v1, V v2)java.util.Collection<E>findEdgeSet(V v1, V v2)VgetChild(V vertex, int index)Returns the child ofvertexat positionindexin this tree, ornullif it has no child at that position.intgetChildCount(V vertex)Returns the number of children thatvertexhas.EgetChildEdge(V vertex, int index)Returns the child edge of the vertex at indexindex.java.util.Collection<E>getChildEdges(V vertex)java.util.Collection<V>getChildren(V vertex)Returns an ordered list ofvertex's child vertices.intgetDepth(V vertex)VgetDest(E directed_edge)intgetEdgeCount()java.util.Collection<E>getEdges()edu.uci.ics.jung.graph.util.Pair<V>getEndpoints(E edge)static <V,E>
org.apache.commons.collections4.Factory<edu.uci.ics.jung.graph.DirectedGraph<V,E>>getFactory(int order)Returns aFactorythat creates an instance of this graph type.intgetHeight()Returns the height of the tree, or -1 if the tree is empty.intgetIncidentCount(E edge)java.util.Collection<E>getIncidentEdges(V vertex)java.util.Collection<V>getIncidentVertices(E edge)java.util.Collection<E>getInEdges(V vertex)intgetNeighborCount(V vertex)java.util.Collection<V>getNeighbors(V vertex)VgetOpposite(V vertex, E edge)java.util.Collection<E>getOutEdges(V vertex)VgetParent(V vertex)EgetParentEdge(V vertex)intgetPredecessorCount(V vertex)java.util.Collection<V>getPredecessors(V vertex)VgetRoot()VgetSource(E directed_edge)intgetSuccessorCount(V vertex)java.util.Collection<V>getSuccessors(V vertex)java.util.Collection<edu.uci.ics.jung.graph.Tree<V,E>>getTrees()intgetVertexCount()java.util.Collection<V>getVertices()intinDegree(V vertex)booleanisDest(V vertex, E edge)booleanisIncident(V vertex, E edge)booleanisLeaf(V vertex)Returnstrueifvertexis a leaf of this tree, i.e., if it has no children.booleanisNeighbor(V v1, V v2)booleanisPredecessor(V v1, V v2)Returns true iffv1is the parent ofv2.booleanisRoot(V vertex)Returnstrueifvertexis a leaf of this tree, i.e., if it has no children.booleanisSource(V vertex, E edge)booleanisSuccessor(V v1, V v2)intoutDegree(V vertex)booleanremoveEdge(E edge)booleanremoveVertex(V vertex)-
Methods inherited from class edu.uci.ics.jung.graph.AbstractTypedGraph
getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, hasEqualEdgeType, validateEdgeType
-
Methods inherited from class edu.uci.ics.jung.graph.AbstractGraph
addEdge, addEdge, degree, getValidatedEndpoints, toString
-
-
-
-
Field Detail
-
vertex_data
protected java.util.Map<V,OrderedKAryTree.VertexData> vertex_data
-
height
protected int height
-
root
protected V root
-
order
protected int order
-
-
Method Detail
-
getFactory
public static <V,E> org.apache.commons.collections4.Factory<edu.uci.ics.jung.graph.DirectedGraph<V,E>> getFactory(int order)
Returns aFactorythat creates an instance of this graph type.- Type Parameters:
V- the vertex type for the graph factoryE- the edge type for the graph factory
-
getChildCount
public int getChildCount(V vertex)
Returns the number of children thatvertexhas.
-
getChildEdge
public E getChildEdge(V vertex, int index)
Returns the child edge of the vertex at indexindex.- Parameters:
vertex-index-- Returns:
- the child edge of the vertex at index
index
-
getChildren
public java.util.Collection<V> getChildren(V vertex)
Returns an ordered list ofvertex's child vertices. If there is no child in position i, then the list will containnullin position i. Ifvertexhas no children then the empty set will be returned.
-
getDepth
public int getDepth(V vertex)
-
getHeight
public int getHeight()
Returns the height of the tree, or -1 if the tree is empty.
-
getRoot
public V getRoot()
-
addEdge
public boolean addEdge(E e, V parent, V child, int index)
Adds the specifiedchildvertex and edgeeto the graph with the specified parent vertexparent. Ifindexis greater than or equal to 0, then the child is placed at positionindex; if it is less than 0, the child is placed at the lowest available position; if it is greater than or equal to the order of this tree, an exception is thrown.- See Also:
Graph.addEdge(java.lang.Object, java.lang.Object, java.lang.Object)
-
getOpposite
public V getOpposite(V vertex, E edge)
- Specified by:
getOppositein interfaceedu.uci.ics.jung.graph.Graph<V,E>- Overrides:
getOppositein classAbstractGraph<V,E>- See Also:
Graph.getOpposite(java.lang.Object, java.lang.Object)
-
getPredecessorCount
public int getPredecessorCount(V vertex)
- Specified by:
getPredecessorCountin interfaceedu.uci.ics.jung.graph.Graph<V,E>- Overrides:
getPredecessorCountin classAbstractGraph<V,E>- Returns:
- 0 if
vertexis the root, -1 if the vertex is not an element of this tree, and 1 otherwise - See Also:
Graph.getPredecessorCount(java.lang.Object)
-
getSuccessorCount
public int getSuccessorCount(V vertex)
- Specified by:
getSuccessorCountin interfaceedu.uci.ics.jung.graph.Graph<V,E>- Overrides:
getSuccessorCountin classAbstractGraph<V,E>- See Also:
Graph.getSuccessorCount(java.lang.Object)
-
inDegree
public int inDegree(V vertex)
-
isLeaf
public boolean isLeaf(V vertex)
Returnstrueifvertexis a leaf of this tree, i.e., if it has no children.- Parameters:
vertex- the vertex to be queried- Returns:
trueifoutDegree(vertex)==0
-
isPredecessor
public boolean isPredecessor(V v1, V v2)
Returns true iffv1is the parent ofv2. Note that ifv2is the root andv1isnull, this method returnstrue.- Specified by:
isPredecessorin interfaceedu.uci.ics.jung.graph.Graph<V,E>- Overrides:
isPredecessorin classAbstractGraph<V,E>- See Also:
Graph.isPredecessor(java.lang.Object, java.lang.Object)
-
isRoot
public boolean isRoot(V vertex)
Returnstrueifvertexis a leaf of this tree, i.e., if it has no children.- Parameters:
vertex- the vertex to be queried- Returns:
trueifoutDegree(vertex)==0
-
isSuccessor
public boolean isSuccessor(V v1, V v2)
- Specified by:
isSuccessorin interfaceedu.uci.ics.jung.graph.Graph<V,E>- Overrides:
isSuccessorin classAbstractGraph<V,E>- See Also:
Graph.isSuccessor(java.lang.Object, java.lang.Object)
-
outDegree
public int outDegree(V vertex)
-
addEdge
public boolean addEdge(E edge, java.util.Collection<? extends V> vertices, edu.uci.ics.jung.graph.util.EdgeType edge_type)
-
addVertex
public boolean addVertex(V vertex)
-
isIncident
public boolean isIncident(V vertex, E edge)
- Specified by:
isIncidentin interfaceedu.uci.ics.jung.graph.Hypergraph<V,E>- Overrides:
isIncidentin classAbstractGraph<V,E>- See Also:
Hypergraph.isIncident(java.lang.Object, java.lang.Object)
-
isNeighbor
public boolean isNeighbor(V v1, V v2)
- Specified by:
isNeighborin interfaceedu.uci.ics.jung.graph.Hypergraph<V,E>- Overrides:
isNeighborin classAbstractGraph<V,E>- See Also:
Hypergraph.isNeighbor(java.lang.Object, java.lang.Object)
-
containsEdge
public boolean containsEdge(E edge)
-
containsVertex
public boolean containsVertex(V vertex)
-
findEdgeSet
public java.util.Collection<E> findEdgeSet(V v1, V v2)
- Specified by:
findEdgeSetin interfaceedu.uci.ics.jung.graph.Hypergraph<V,E>- Overrides:
findEdgeSetin classAbstractGraph<V,E>- See Also:
Hypergraph.findEdgeSet(java.lang.Object, java.lang.Object)
-
getChild
public V getChild(V vertex, int index)
Returns the child ofvertexat positionindexin this tree, ornullif it has no child at that position.- Parameters:
vertex- the vertex to query- Returns:
- the child of
vertexat positionindexin this tree, ornullif it has no child at that position - Throws:
java.lang.ArrayIndexOutOfBoundsException- ifindexis not in the range[0, order-1]
-
getEdgeCount
public int getEdgeCount()
-
getEdges
public java.util.Collection<E> getEdges()
-
getIncidentCount
public int getIncidentCount(E edge)
- Specified by:
getIncidentCountin interfaceedu.uci.ics.jung.graph.Hypergraph<V,E>- Overrides:
getIncidentCountin classAbstractGraph<V,E>- See Also:
Hypergraph.getIncidentCount(java.lang.Object)
-
getIncidentVertices
public java.util.Collection<V> getIncidentVertices(E edge)
- Specified by:
getIncidentVerticesin interfaceedu.uci.ics.jung.graph.Hypergraph<V,E>- Overrides:
getIncidentVerticesin classAbstractGraph<V,E>- See Also:
Hypergraph.getIncidentVertices(java.lang.Object)
-
getNeighborCount
public int getNeighborCount(V vertex)
- Specified by:
getNeighborCountin interfaceedu.uci.ics.jung.graph.Hypergraph<V,E>- Overrides:
getNeighborCountin classAbstractGraph<V,E>- See Also:
Hypergraph.getNeighborCount(java.lang.Object)
-
getVertexCount
public int getVertexCount()
-
getVertices
public java.util.Collection<V> getVertices()
-
removeEdge
public boolean removeEdge(E edge)
-
removeVertex
public boolean removeVertex(V vertex)
-
addEdge
public boolean addEdge(E edge, edu.uci.ics.jung.graph.util.Pair<? extends V> endpoints, edu.uci.ics.jung.graph.util.EdgeType edgeType)
Description copied from class:AbstractGraphAddsedgeto this graph with the specifiedendpointsandEdgeType.- Specified by:
addEdgein classAbstractGraph<V,E>- Returns:
- true iff the graph was modified as a result of this call
-
-