Class JungGraph<U>

java.lang.Object
es.uam.eps.ir.relison.graph.jung.JungGraph<U>
Type Parameters:
U - type of the users
All Implemented Interfaces:
Graph<U>, UnweightedGraph<U>, java.io.Serializable
Direct Known Subclasses:
DirectedJungGraph, UndirectedJungGraph

public abstract class JungGraph<U>
extends java.lang.Object
implements UnweightedGraph<U>
JUNG graph Wrapper. Edges weights and types are not allowed in this types of graphs.
See Also:
Serialized Form
  • Field Details

    • graph

      protected final edu.uci.ics.jung.graph.Graph<U,​java.lang.Integer> graph
      The JUNG Graph we are using
  • Constructor Details

    • JungGraph

      public JungGraph​(edu.uci.ics.jung.graph.Graph<U,​java.lang.Integer> graph)
      Constructor.
      Parameters:
      graph - The Jung graph.
  • Method Details

    • addNode

      public boolean addNode​(U node)
      Description copied from interface: Graph
      Adds a new node to the graph.
      Specified by:
      addNode in interface Graph<U>
      Parameters:
      node - The new node to add.
      Returns:
      true if the node is correctly added, false if not.
    • addEdge

      public boolean addEdge​(U nodeA, U nodeB, double weight, int type, boolean insertNodes)
      Description copied from interface: Graph
      Adds a weighted edge to the graph.
      Specified by:
      addEdge in interface Graph<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.
    • getAllNodes

      public java.util.stream.Stream<U> getAllNodes()
      Description copied from interface: Graph
      Gets all the nodes in the graph.
      Specified by:
      getAllNodes in interface Graph<U>
      Returns:
      a stream of all the nodes in the graph.
    • getIncidentNodes

      public java.util.stream.Stream<U> getIncidentNodes​(U node)
      Description copied from interface: Graph
      Given a node, finds all the nodes u such that the edge (u to node) is in the graph.
      Specified by:
      getIncidentNodes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream of the incident nodes.
    • getAdjacentNodes

      public java.util.stream.Stream<U> getAdjacentNodes​(U node)
      Description copied from interface: Graph
      Given a node, finds all the nodes u such that the edge (node to u) is in the graph.
      Specified by:
      getAdjacentNodes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream containing the adjacent nodes.
    • getNeighbourNodes

      public java.util.stream.Stream<U> getNeighbourNodes​(U node)
      Description copied from interface: Graph
      Given a node, finds all the nodes u so that either (node to u) or (u to node) are in the graph.
      Specified by:
      getNeighbourNodes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream containing all the nodes in the neighbourhood.
    • getMutualNodes

      public java.util.stream.Stream<U> getMutualNodes​(U node)
      Description copied from interface: Graph
      Given a node, finds all the nodes u such that the edges (node to u) and (u to node) are in the graph.
      Specified by:
      getMutualNodes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream containing all the nodes which share reciprocal links.
    • degree

      public int degree​(U node)
      Description copied from interface: Graph
      Calculates the degree of a node.
      Specified by:
      degree in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      the degree of the node if it is contained in the graph, -1 otherwise.
    • getIncidentEdgesCount

      public int getIncidentEdgesCount​(U node)
      Description copied from interface: Graph
      Calculates the number of incident edges of a node (not necessarily equal to the in-degree).
      Specified by:
      getIncidentEdgesCount in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      the number of incident neighbours of the node if it is contained in the graph, -1 if not.
    • getAdjacentEdgesCount

      public int getAdjacentEdgesCount​(U node)
      Description copied from interface: Graph
      Calculates the number of adjacent edges of a node (not necessarily equal to the out-degree).
      Specified by:
      getAdjacentEdgesCount in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      the degree of the node if it is contained in the graph, -1 if not.
    • getNeighbourEdgesCount

      public int getNeighbourEdgesCount​(U node)
      Description copied from interface: Graph
      Calculates the total number of edges which reach a node or start from it (not necessarily equal to the degree).
      Specified by:
      getNeighbourEdgesCount in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      the degree of the node if it is contained in the graph, -1 if not.
    • getMutualEdgesCount

      public int getMutualEdgesCount​(U node)
      Description copied from interface: Graph
      Calculates the total number of adjacent edges of a node such that there is an incident reciprocal link towards the node.
      Specified by:
      getMutualEdgesCount in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      the number of reciprocal links starting from the node.
    • containsVertex

      public boolean containsVertex​(U node)
      Description copied from interface: Graph
      Checks if a vertex exists in the graph.
      Specified by:
      containsVertex in interface Graph<U>
      Parameters:
      node - The vertex to check.
      Returns:
      true if the vertex is contained in the graph, false if not.
    • containsEdge

      public boolean containsEdge​(U nodeA, U nodeB)
      Description copied from interface: Graph
      Checks if an edge exists in the graph.
      Specified by:
      containsEdge in interface Graph<U>
      Parameters:
      nodeA - The incident node.
      nodeB - The adjacent node.
      Returns:
      true if the edge is contained in the graph, false if not.
    • getEdgeType

      public int getEdgeType​(U nodeA, U nodeB)
      Description copied from interface: Graph
      Obtains the type of an edge in the graph
      Specified by:
      getEdgeType in interface Graph<U>
      Parameters:
      nodeA - The incident node.
      nodeB - The adjacent node.
      Returns:
      The corresponding type. If the edge does not exist, -1.
    • getIncidentNodesTypes

      public java.util.stream.Stream<Weight<U,​java.lang.Integer>> getIncidentNodesTypes​(U node)
      Description copied from interface: Graph
      Given a node, finds the types of the edges from the nodes u such that the edge (u to node) is in the graph.
      Specified by:
      getIncidentNodesTypes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream of the incident nodes and types.
    • getAdjacentNodesTypes

      public java.util.stream.Stream<Weight<U,​java.lang.Integer>> getAdjacentNodesTypes​(U node)
      Description copied from interface: Graph
      Given a node, finds the types of the edges towards the nodes u such that the edge (node to u) is in the graph.
      Specified by:
      getAdjacentNodesTypes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream containing the adjacent nodes and types.
    • getNeighbourNodesTypes

      public java.util.stream.Stream<Weight<U,​java.lang.Integer>> getNeighbourNodesTypes​(U node)
      Description copied from interface: Graph
      Given a node, finds the types of the edges from the nodes u such that the edge (node to u) or the edge (u to node) are in the graph.
      Specified by:
      getNeighbourNodesTypes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream containing all the nodes in the neighbourhood and types.
    • getMutualNodesTypes

      public java.util.stream.Stream<Weight<U,​java.lang.Integer>> getMutualNodesTypes​(U node)
      Description copied from interface: Graph
      Given a node, find the types of edges from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.
      Specified by:
      getMutualNodesTypes in interface Graph<U>
      Parameters:
      node - the node.
      Returns:
      a stream containing all the nodes in the neighbourhood and types.
    • getNeighbourhoodTypes

      public java.util.stream.Stream<Weight<U,​java.lang.Integer>> getNeighbourhoodTypes​(U node, EdgeOrientation direction)
      Description copied from interface: Graph
      Gets all the types of the edges in the neighbourhood of a node given by a direction. In the mutual case, it does not work (types are categorical values), so an empty stream is returned.
      Specified by:
      getNeighbourhoodTypes in interface Graph<U>
      Parameters:
      node - The node.
      direction - The direction of the links.
      Returns:
      A stream containing the corresponding neighbourhood.
    • getVertexCount

      public long getVertexCount()
      Description copied from interface: Graph
      Measures the number of nodes in the network.
      Specified by:
      getVertexCount in interface Graph<U>
      Returns:
      the number of nodes.
    • getAdjacentMutualNodesTypes

      public java.util.stream.Stream<Weight<U,​java.lang.Integer>> getAdjacentMutualNodesTypes​(U node)
      Description copied from interface: Graph
      Given a node, finds the types of the edges towards the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.
      Specified by:
      getAdjacentMutualNodesTypes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream containing all the nodes in the neighbourhood and types.
    • getIncidentMutualNodesTypes

      public java.util.stream.Stream<Weight<U,​java.lang.Integer>> getIncidentMutualNodesTypes​(U node)
      Description copied from interface: Graph
      Given a node, finds the types of the edges from the nodes u such that the edge (node to u) and the edge (u to node) are in the graph.
      Specified by:
      getIncidentMutualNodesTypes in interface Graph<U>
      Parameters:
      node - The node.
      Returns:
      A stream containing all the nodes in the neighbourhood and types.
    • getEdgeCount

      public long getEdgeCount()
      Description copied from interface: Graph
      Measures the number of edges in the network.
      Specified by:
      getEdgeCount in interface Graph<U>
      Returns:
      the number of edges.
    • complement

      public Graph<U> complement()
      Description copied from interface: Graph
      Complements the graph
      Specified by:
      complement in interface Graph<U>
      Returns:
      the complementary graph.
    • getIsolatedNodes

      public java.util.stream.Stream<U> getIsolatedNodes()
      Description copied from interface: Graph
      Obtains the set of nodes without edges.
      Specified by:
      getIsolatedNodes in interface Graph<U>
      Returns:
      the set of nodes without edges.
    • getNodesWithNeighbors

      public java.util.stream.Stream<U> getNodesWithNeighbors​(EdgeOrientation direction)
      Description copied from interface: Graph
      Obtains the set of nodes with edges in a particular direction.
      Specified by:
      getNodesWithNeighbors in interface Graph<U>
      Parameters:
      direction - the particular direction
      Returns:
      the set of nodes with edges in the given direction.
    • getNodesWithAdjacentNeighbors

      public java.util.stream.Stream<U> getNodesWithAdjacentNeighbors()
      Description copied from interface: Graph
      Obtains the set of nodes which have adjacent edges.
      Specified by:
      getNodesWithAdjacentNeighbors in interface Graph<U>
      Returns:
      the set of nodes which have adjacent edges.
    • getNodesWithIncidentNeighbors

      public java.util.stream.Stream<U> getNodesWithIncidentNeighbors()
      Description copied from interface: Graph
      Obtains the set of nodes which have incident edges.
      Specified by:
      getNodesWithIncidentNeighbors in interface Graph<U>
      Returns:
      the set of nodes which have incident edges.
    • getNodesWithNeighbors

      public java.util.stream.Stream<U> getNodesWithNeighbors()
      Description copied from interface: Graph
      Obtains the set of nodes having either incident or adjacent edges.
      Specified by:
      getNodesWithNeighbors in interface Graph<U>
      Returns:
      the set of nodes which have incident or adjacent edges.
    • getNodesWithMutualNeighbors

      public java.util.stream.Stream<U> getNodesWithMutualNeighbors()
      Description copied from interface: Graph
      Obtains the set of nodes having mutual edges.
      Specified by:
      getNodesWithMutualNeighbors in interface Graph<U>
      Returns:
      the set of nodes which have mutual edges.
    • hasAdjacentNeighbors

      public boolean hasAdjacentNeighbors​(U u)
      Description copied from interface: Graph
      Checks if the user has adjacent edges or not.
      Specified by:
      hasAdjacentNeighbors in interface Graph<U>
      Parameters:
      u - The user.
      Returns:
      true if the user has adjacent edges, false if it is a sink or isolated node.
    • hasIncidentNeighbors

      public boolean hasIncidentNeighbors​(U u)
      Description copied from interface: Graph
      Checks if the user has incident edges or not.
      Specified by:
      hasIncidentNeighbors in interface Graph<U>
      Parameters:
      u - the user.
      Returns:
      true if the user has incident edges, false if it is a source or isolated node.
    • hasNeighbors

      public boolean hasNeighbors​(U u)
      Description copied from interface: Graph
      Checks if the user shares at least an edge with other user.
      Specified by:
      hasNeighbors in interface Graph<U>
      Parameters:
      u - The user.
      Returns:
      true if the user is not isolated, false otherwise.
    • hasMutualNeighbors

      public boolean hasMutualNeighbors​(U u)
      Description copied from interface: Graph
      Checks if the user has mutual edges.
      Specified by:
      hasMutualNeighbors in interface Graph<U>
      Parameters:
      u - The user.
      Returns:
      true if the user has mutual edges, false otherwise.
    • getAdjacencyMatrixMap

      public Index<U> getAdjacencyMatrixMap()
      Description copied from interface: Graph
      For an adjacency matrix, obtains the mapping between indexes and nodes.
      Specified by:
      getAdjacencyMatrixMap in interface Graph<U>
      Returns:
      the mapping between indexes and nodes.
    • updateEdgeType

      public boolean updateEdgeType​(U nodeA, U nodeB, int type)
      Description copied from interface: Graph
      Updates the type of an edge.
      Specified by:
      updateEdgeType in interface Graph<U>
      Parameters:
      nodeA - The incident node.
      nodeB - The adjacent node.
      type - The new type.
      Returns:
      true if everything goes OK, false if the edge does not exist or something fails.