Interface Graph<T>

Type Parameters:
T - the type of vertex in this graph
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Graph<T>
An interface for weighted directed graph (network)
Since:
1.1
  • Method Summary

    Modifier and Type
    Method
    Description
    default Map<T,Number>
    edges(T vertex)
    Returns the edges of the given vertex, or null if this graph contains no given vertex.
    default double
    Calculate the distance for the given path
    static <T> Graph<T>
    of(Map<T,Map<T,Number>> schema)
    Creates a Graph object by given schema.
    The schema of this graph.
  • Method Details

    • schema

      Map<T,Map<T,Number>> schema()
      The schema of this graph. In a graph schema, each vertex is assigned an edge map. If the vertex has no edges, then it should be assigned an empty map.
      Returns:
      the graph scheme
    • edges

      default Map<T,Number> edges(T vertex)
      Returns the edges of the given vertex, or null if this graph contains no given vertex.

      A return value of null does not necessarily indicate that the specified vertex is not present in the graph; it's also possible that in the graph schema, null was specified for the edges of this vertex instead of an empty map.

      Parameters:
      vertex - vertex
      Returns:
      all links for the given vertex or null if no such vertex in the graph
    • getDistance

      default double getDistance(List<T> path)
      Calculate the distance for the given path
      Parameters:
      path - the list of vertices representing the path
      Returns:
      distance for the given path as double
      Throws:
      NullPointerException - if path is incorrect and contains more than one vertex
    • of

      static <T> Graph<T> of(Map<T,Map<T,Number>> schema)
      Creates a Graph object by given schema. In a graph schema, each vertex is assigned an edge map. If the vertex has no edges, then it should be assigned an empty map.
      Type Parameters:
      T - the type of vertex in this graph
      Parameters:
      schema - of the graph
      Returns:
      graph object with given schema