Package es.uam.eps.ir.relison.graph.tree
Interface Tree<U>
- Type Parameters:
U
- Type of the nodes.
- All Superinterfaces:
DirectedGraph<U>
,Graph<U>
,java.io.Serializable
- All Known Subinterfaces:
UnweightedTree<U>
,WeightedTree<U>
- All Known Implementing Classes:
FastTree
,FastUnweightedTree
,FastWeightedTree
public interface Tree<U> extends DirectedGraph<U>
Interface for managing and creating tree graphs.
-
Method Summary
Modifier and Type Method Description default boolean
addChild(U parent, U child)
Adds a child to a given node.default boolean
addChild(U parent, U child, double weight)
Adds a child to a given nodeboolean
addChild(U parent, U child, double weight, int type)
Adds a child to a given node.default boolean
addEdge(U nodeA, U nodeB, double weight, int type, boolean insertNodes)
Adds a weighted edge to the graph.default boolean
addNode(U node)
Adds a new node to the graph.boolean
addRoot(U root)
Adds a root to the tree.java.util.stream.Stream<U>
getChildren(U u)
Obtains the direct children of a node.long
getChildrenCount(U u)
Gets the number of children of a node.java.util.stream.Stream<Weight<U,java.lang.Double>>
getChildrenWeights(U u)
Obtains the weights of the children of a node.Tree<U>
getDescendants(U parent)
Obtains the subtree formed by the user and its descendants.java.util.stream.Stream<U>
getLeaves()
Obtain the leaves of the tree.java.util.stream.Stream<U>
getLeaves(U u)
Obtains the leaves of a tree that come from a certain nodejava.util.stream.Stream<U>
getLevel(int level)
Obtains all the nodes in a given level of the tree.java.util.Map<java.lang.Integer,java.util.Set<U>>
getLevels()
Obtains all the nodes on each level.U
getParent(U u)
Obtains the parent of a node.double
getParentWeight(U u)
Obtains the weight of the edge between a node and its parentU
getRoot()
Obtains the root of the graph.boolean
isAscendant(U parent, U child)
Checks if a node is ascendant of another onedefault boolean
isChild(U child, U parent)
Checks if a node is the parent of another one.default boolean
isDescendant(U child, U parent)
Checks if a node is descendant of another oneboolean
isLeaf(U u)
Indicates if the node is a leaf or not.boolean
isParent(U parent, U child)
Checks if a node is the parent of another one.boolean
isRoot(U u)
Indicates if the node is the root node or not.Methods inherited from interface es.uam.eps.ir.relison.graph.DirectedGraph
degree, degree, getNeighbourEdgesCount, getNeighbourhood, getNeighbourhoodSize, getNeighbourhoodTypes, getNeighbourhoodWeights, getSinks, getSources, inDegree, isDirected, mutualDegree, outDegree
Methods inherited from interface es.uam.eps.ir.relison.graph.Graph
addEdge, addEdge, addEdge, addEdge, addEdge, complement, containsEdge, containsVertex, getAdjacencyMatrix, getAdjacencyMatrixMap, getAdjacentEdgesCount, getAdjacentMutualNodesTypes, getAdjacentMutualNodesWeights, getAdjacentNodes, getAdjacentNodesCount, getAdjacentNodesTypes, getAdjacentNodesWeights, getAllNodes, getEdgeCount, getEdgeType, getEdgeWeight, getIncidentEdgesCount, getIncidentMutualNodesTypes, getIncidentMutualNodesWeights, getIncidentNodes, getIncidentNodesCount, getIncidentNodesTypes, getIncidentNodesWeights, getIsolatedNodes, getMutualEdgesCount, getMutualNodes, getMutualNodesCount, getMutualNodesTypes, getMutualNodesWeights, getNeighbourNodes, getNeighbourNodesCount, getNeighbourNodesTypes, getNeighbourNodesWeights, getNodesWithAdjacentNeighbors, getNodesWithIncidentNeighbors, getNodesWithMutualNeighbors, getNodesWithNeighbors, getNodesWithNeighbors, getVertexCount, hasAdjacentNeighbors, hasIncidentNeighbors, hasMutualNeighbors, hasNeighbors, hasNeighbors, isMultigraph, isMutual, isWeighted, removeEdge, removeNode, updateEdgeType, updateEdgeWeight
-
Method Details
-
getRoot
U getRoot()Obtains the root of the graph.- Returns:
- the root of the graph.
-
getLeaves
java.util.stream.Stream<U> getLeaves()Obtain the leaves of the tree.- Returns:
- a stream containing the leaves of the tree.
-
getLeaves
Obtains the leaves of a tree that come from a certain node- Parameters:
u
- the leaves of the tree.- Returns:
- a stream containing the selected leaves of the tree.
-
getLevel
Obtains all the nodes in a given level of the tree. Root equal to 0.- Parameters:
level
- the level to retrieve.- Returns:
- the nodes in the corresponding level.
-
getLevels
java.util.Map<java.lang.Integer,java.util.Set<U>> getLevels()Obtains all the nodes on each level.- Returns:
- all the nodes on each level.
-
getChildren
Obtains the direct children of a node.- Parameters:
u
- the parent node- Returns:
- A stream containing the children of a node. If it is a leaf, an empty stream is returned. If the node does not exist, null.
-
getChildrenCount
Gets the number of children of a node.- Parameters:
u
- the node.- Returns:
- the number of children, -1 if the node does not exist.
-
getChildrenWeights
Obtains the weights of the children of a node.- Parameters:
u
- The parent node.- Returns:
- A stream containing the children of the node if it exists, null if not.
-
getParentWeight
Obtains the weight of the edge between a node and its parent- Parameters:
u
- The child node- Returns:
- The weight if the node exists and it is not the root, NaN otherwise.
-
getParent
Obtains the parent of a node.- Parameters:
u
- the child.- Returns:
- the parent of the node, null if the node does not exist, or the node is the root.
-
isLeaf
Indicates if the node is a leaf or not.- Parameters:
u
- the user- Returns:
- true if the node is a leaf, false if the node is not a leaf or it does not exist.
-
isRoot
Indicates if the node is the root node or not.- Parameters:
u
- the user.- Returns:
- true if the node is the root, false if the node is not the root or it does not exist.
-
addRoot
Adds a root to the tree.- Parameters:
root
- the new root of the tree.- Returns:
- true if the root is correctly added, false if there is already a root in the graph.
-
addChild
Adds a child to a given node.- Parameters:
parent
- the parent node.child
- the child node to add.- Returns:
- true if the child is correctly added, false if not.
-
addChild
Adds a child to a given node- Parameters:
parent
- the parent node.child
- the child node to add.weight
- the weight of the edge- Returns:
- true if the child is correctly added, false if not.
-
addChild
Adds a child to a given node.- Parameters:
parent
- the parent node.child
- the child node to add.weight
- the weight of the edge.type
- the type of the edge.- Returns:
- true if the child is correcly added, false if not.
-
isParent
Checks if a node is the parent of another one.- Parameters:
parent
- the parent node.child
- the node we want to check.- Returns:
- true if the child
-
isChild
Checks if a node is the parent of another one.- Parameters:
child
- the node we want to check.parent
- the parent node.- Returns:
- true if the child
-
getDescendants
Obtains the subtree formed by the user and its descendants.- Parameters:
parent
- the parent node.- Returns:
- a tree rooted in the parent if the node exists, null if not
-
isAscendant
Checks if a node is ascendant of another one- Parameters:
parent
- the first node (the possible ascendant)child
- the second node (the possible descendant)- Returns:
- true if the second node descends from the first, false if not.
-
isDescendant
Checks if a node is descendant of another one- Parameters:
child
- the first node (the possible descendant)parent
- the second node (the possible ascendant)- Returns:
- true if the second node descends from the first, false if not.
-
addNode
Description copied from interface:Graph
Adds a new node to the graph. -
addEdge
Description copied from interface:Graph
Adds a weighted edge to the graph.- Specified by:
addEdge
in interfaceGraph<U>
- Parameters:
nodeA
- The incident node.nodeB
- The adjacent node.weight
- The weight.type
- The edge type.insertNodes
- If true, nodes will be inserted if they do not exist. If false, the edge will only be added if both nodes are inserted.- Returns:
- if the edge is correctly added, false if not.
-