|
2 | 2 |
|
3 | 3 | import java.util.*;
|
4 | 4 | import java.util.function.Function;
|
| 5 | +import java.util.stream.Collectors; |
5 | 6 | import java.util.stream.Stream;
|
6 | 7 |
|
7 | 8 | /**
|
@@ -60,34 +61,34 @@ public Map<T, Set<Content<T,V>>> getContents() {
|
60 | 61 |
|
61 | 62 | /**
|
62 | 63 | * @param pcs A PCS triple.
|
63 |
| - * @return Another PCS that matches the argument PCS on everything but root. |
| 64 | + * @return All PCSes that are root conflicting with the provided PCS. |
64 | 65 | */
|
65 |
| - public Optional<Pcs<T>> getOtherRoot(Pcs<T> pcs) { |
| 66 | + public List<Pcs<T>> getOtherRoots(Pcs<T> pcs) { |
66 | 67 | return Stream.of(pcs.getPredecessor(), pcs.getSuccessor()).flatMap(
|
67 | 68 | node -> Stream.of(predecessors.get(node), successors.get(node))
|
68 | 69 | .filter(Objects::nonNull)
|
69 | 70 | .flatMap(Set::stream)
|
70 |
| - ).filter(p -> !p.getRoot().equals(pcs.getRoot())).findFirst(); |
| 71 | + ).filter(p -> !p.getRoot().equals(pcs.getRoot())).collect(Collectors.toList()); |
71 | 72 | }
|
72 | 73 |
|
73 | 74 | /**
|
74 | 75 | * @param pcs A PCS triple.
|
75 |
| - * @return Another PCS that matches the argument PCS on everything but successor. |
| 76 | + * @return All PCSes that are successor conflicting with the provided PCS. |
76 | 77 | */
|
77 |
| - public Optional<Pcs<T>> getOtherSuccessor(Pcs<T> pcs) { |
| 78 | + public List<Pcs<T>> getOtherSuccessors(Pcs<T> pcs) { |
78 | 79 | return predecessors.getOrDefault(pcs.getPredecessor(), EMPTY_PCS_SET).stream()
|
79 | 80 | .filter(p -> !p.getSuccessor().equals(pcs.getSuccessor()))
|
80 |
| - .findFirst(); |
| 81 | + .collect(Collectors.toList()); |
81 | 82 | }
|
82 | 83 |
|
83 | 84 | /**
|
84 | 85 | * @param pcs A PCS triple.
|
85 |
| - * @return Another PCS that matches the argument PCS on everything but predecessor. |
| 86 | + * @return All PCSes that are predecessor conflicting with the provided PCS. |
86 | 87 | */
|
87 |
| - public Optional<Pcs<T>> getOtherPredecessor(Pcs<T> pcs) { |
| 88 | + public List<Pcs<T>> getOtherPredecessors(Pcs<T> pcs) { |
88 | 89 | return successors.getOrDefault(pcs.getSuccessor(), EMPTY_PCS_SET).stream()
|
89 | 90 | .filter(p -> !p.getPredecessor().equals(pcs.getPredecessor()))
|
90 |
| - .findFirst(); |
| 91 | + .collect(Collectors.toList()); |
91 | 92 | }
|
92 | 93 |
|
93 | 94 | /**
|
|
0 commit comments