com.groiss.reporting.data
Class ReportingGraph<N,E>

java.lang.Object
  extended by com.groiss.reporting.data.ReportingGraph<N,E>
Type Parameters:
N - the class of the nodes
E - the class of the edges

public class ReportingGraph<N,E>
extends java.lang.Object

Simple graph implementation with nodes and edges which may handle n edges connecting 2 nodes.


Field Summary
protected  java.util.ArrayList<E>[][] edges
           
protected  java.util.ArrayList<N> nodes
           
 
Constructor Summary
ReportingGraph()
           
 
Method Summary
 void addEdge(N node1, N node2, E edge)
          Connect 2 nodes with the given edge
 int addNode(N node)
           
 boolean existsDirectEdge(N n1, N n2)
          check if 2 Nodes are connected by 1 (and only one) edge
 java.util.ArrayList<E> getEdges(N node)
          get all Edges connected with the given node
 java.util.List<E> getEdges(N n1, N n2)
          get All Edges connecting the start and end node directly
 N getEndNode(N startNode, E edge)
          return the endnode of an egde
 N getNodeWithMostEdges()
          returns the node with the most edges connected, can be used as center of the graph
 N getNodeWithMostEdges(java.util.List<N> oneOfThisnodes)
          returns the node with the most edges connected, can be used as center of the graph
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodes

protected java.util.ArrayList<N> nodes

edges

protected java.util.ArrayList<E>[][] edges
Constructor Detail

ReportingGraph

public ReportingGraph()
Method Detail

size

public int size()
Returns:
the amount of nodes

addNode

public int addNode(N node)

addEdge

public void addEdge(N node1,
                    N node2,
                    E edge)
Connect 2 nodes with the given edge

Parameters:
node1 -
node2 -
edge -

getEdges

public java.util.ArrayList<E> getEdges(N node)
get all Edges connected with the given node

Parameters:
node -
Returns:
a ArrayList containing all edges connected to the node

existsDirectEdge

public boolean existsDirectEdge(N n1,
                                N n2)
check if 2 Nodes are connected by 1 (and only one) edge

Parameters:
n1 - startnode
n2 - endnode
Returns:
true if n1 and n2 are connected by 1 edge

getEdges

public java.util.List<E> getEdges(N n1,
                                  N n2)
get All Edges connecting the start and end node directly

Parameters:
n1 - start node
n2 - end note
Returns:
a list of edges

getNodeWithMostEdges

public N getNodeWithMostEdges(java.util.List<N> oneOfThisnodes)
returns the node with the most edges connected, can be used as center of the graph

Parameters:
nodes - only nodes in this list will be handled and returned.
Returns:
the node with the most connections

getNodeWithMostEdges

public N getNodeWithMostEdges()
returns the node with the most edges connected, can be used as center of the graph

Returns:
the node with the most connections

getEndNode

public N getEndNode(N startNode,
                    E edge)
return the endnode of an egde

Parameters:
startNode -
edge - - the edge to follow
Returns:
the end node


@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.