소스 검색

avoid adding duplicates to nodes list

tags/2.0.1
Jonathan Cobb 5 년 전
부모
커밋
ca83d0e4ae
1개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. +4
    -4
      src/main/java/org/cobbzilla/util/collection/Topology.java

+ 4
- 4
src/main/java/org/cobbzilla/util/collection/Topology.java 파일 보기

@@ -15,10 +15,10 @@ public class Topology<T> {
private final List<Node<T>> nodes = new ArrayList<>();

public void addNode(T thing, Collection<T> refs) {
final Node<T> node = nodes.stream()
final Node<T> existingNode = nodes.stream()
.filter(n -> n.thing.equals(thing))
.findFirst()
.orElse(new Node<>(thing));
.findFirst().orElse(null);
final Node<T> node = existingNode != null ? existingNode : new Node<>(thing);

// add refs as edges; skip self-references
refs.stream().filter(ref -> !ref.equals(thing)).forEach(ref -> {
@@ -34,7 +34,7 @@ public class Topology<T> {
node.addEdge(newEdgeNode);
}
});
nodes.add(node);
if (existingNode == null) nodes.add(node);
}

static class Node<T> {


불러오는 중...
취소
저장