Class Graph<T>

Type Parameters:
T - 节点类型
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Map.Entry<T,Collection<T>>>, Map<T,Collection<T>>, MultiValueMap<T,T>, Wrapper<Map<T,Collection<T>>>, Provider

public class Graph<T> extends SetValueMap<T,T>
支持处理无向图结构的Map,本质上是基于SetValueMap实现的邻接表
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • Graph

      public Graph()
  • Method Details

    • putEdge

      public void putEdge(T target1, T target2)
      添加边
      Parameters:
      target1 - 节点
      target2 - 节点
    • containsEdge

      public boolean containsEdge(T target1, T target2)
      是否存在边
      Parameters:
      target1 - 节点
      target2 - 节点
      Returns:
      是否
    • removeEdge

      public void removeEdge(T target1, T target2)
      移除边
      Parameters:
      target1 - 节点
      target2 - 节点
    • removePoint

      public void removePoint(T target)
      移除节点,并删除该节点与其他节点之间连成的边
      Parameters:
      target - 目标对象
    • containsAssociation

      public boolean containsAssociation(T target1, T target2)
      两节点是否存在直接或间接的关联
      Parameters:
      target1 - 节点
      target2 - 节点
      Returns:
      两节点是否存在关联
    • getAssociatedPoints

      public Collection<T> getAssociatedPoints(T target, boolean includeTarget)
      按广度优先,获得节点的所有直接或间接关联的节点,节点默认按添加顺序排序
      Parameters:
      target - 节点
      includeTarget - 是否包含查询节点
      Returns:
      节点的所有关联节点
    • getAdjacentPoints

      public Collection<T> getAdjacentPoints(T target)
      获取节点的邻接节点
      Parameters:
      target - 节点
      Returns:
      邻接节点