Skip to content

Commit

Permalink
Do not use the bounds on the collection items.
Browse files Browse the repository at this point in the history
  • Loading branch information
ielis committed Dec 13, 2023
1 parent 5c5fab3 commit 01038d1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ default Iterable<T> getChildren(T source, boolean includeSource) {
* or {@code false} otherwise.
* @return the collection with the child nodes.
*/
default Collection<? super T> extendWithChildren(T source, boolean includeSource) {
Collection<? super T> collection = new ArrayList<>();
default Collection<T> extendWithChildren(T source, boolean includeSource) {
Collection<T> collection = new ArrayList<>();
extendWithChildren(source, includeSource, collection);
return collection;
}
Expand All @@ -81,7 +81,7 @@ default Collection<? super T> extendWithChildren(T source, boolean includeSource
*/
default void extendWithChildren(T source,
boolean includeSource,
Collection<? super T> collection) {
Collection<T> collection) {
if (includeSource)
collection.add(source);
collection.addAll(getChildren(source));
Expand Down Expand Up @@ -151,7 +151,7 @@ default Iterable<T> getDescendants(T source, boolean includeSource) {
* or {@code false} otherwise.
* @return a collection with the descendant nodes.
*/
default Collection<? super T> extendWithDescendants(T source, boolean includeSource) {
default Collection<T> extendWithDescendants(T source, boolean includeSource) {
return extendWithDescendants(source, includeSource, ArrayList::new);
}

Expand All @@ -165,9 +165,9 @@ default Collection<? super T> extendWithDescendants(T source, boolean includeSou
* @param supplier the collection supplier.
* @param <C> the desired collection type
*/
default <C extends Collection<? super T>> C extendWithDescendants(T source,
boolean includeSource,
Supplier<C> supplier) {
default <C extends Collection<T>> C extendWithDescendants(T source,
boolean includeSource,
Supplier<C> supplier) {
C collection = supplier.get();
extendWithDescendants(source, includeSource, collection);
return collection;
Expand All @@ -183,7 +183,7 @@ default <C extends Collection<? super T>> C extendWithDescendants(T source,
*/
default void extendWithDescendants(T source,
boolean includeSource,
Collection<? super T> collection) {
Collection<T> collection) {
if (includeSource)
collection.add(source);
getDescendants(source).forEach(collection::add);
Expand All @@ -199,7 +199,7 @@ default void extendWithDescendants(T source,
*/
default void extendMultipleWithDescendants(Iterable<T> sources,
boolean includeSource,
Set<? super T> collection) {
Set<T> collection) {
for (T source : sources)
extendWithDescendants(source, includeSource, collection);
}
Expand Down Expand Up @@ -286,8 +286,8 @@ default Iterable<T> getParents(T source, boolean includeSource) {
* or {@code false} otherwise.
* @return the collection with the parent nodes.
*/
default Collection<? super T> extendWithParents(T source, boolean includeSource) {
Collection<? super T> collection = new ArrayList<>();
default Collection<T> extendWithParents(T source, boolean includeSource) {
Collection<T> collection = new ArrayList<>();
extendWithParents(source, includeSource, collection);
return collection;
}
Expand All @@ -302,7 +302,7 @@ default Collection<? super T> extendWithParents(T source, boolean includeSource)
*/
default void extendWithParents(T source,
boolean includeSource,
Collection<? super T> collection) {
Collection<T> collection) {
if (includeSource)
collection.add(source);
collection.addAll(getParents(source));
Expand Down Expand Up @@ -369,7 +369,7 @@ default Stream<T> getParentsStream(T source) {
* or {@code false} otherwise.
* @return a collection with the ancestors nodes.
*/
default Collection<? super T> extendWithAncestors(T source, boolean includeSource) {
default Collection<T> extendWithAncestors(T source, boolean includeSource) {
return extendWithAncestors(source, includeSource, ArrayList::new);
}

Expand All @@ -383,9 +383,9 @@ default Collection<? super T> extendWithAncestors(T source, boolean includeSourc
* @param supplier the collection supplier.
* @param <C> the desired collection type
*/
default <C extends Collection<? super T>> C extendWithAncestors(T source,
boolean includeSource,
Supplier<C> supplier) {
default <C extends Collection<T>> C extendWithAncestors(T source,
boolean includeSource,
Supplier<C> supplier) {
C ancestors = supplier.get();
extendWithAncestors(source, includeSource, ancestors);
return ancestors;
Expand All @@ -401,7 +401,7 @@ default <C extends Collection<? super T>> C extendWithAncestors(T source,
*/
default void extendWithAncestors(T source,
boolean includeSource,
Collection<? super T> collection) {
Collection<T> collection) {
if (includeSource)
collection.add(source);
getAncestors(source).forEach(collection::add);
Expand All @@ -417,7 +417,7 @@ default void extendWithAncestors(T source,
*/
default void extendMultipleWithAncestors(Iterable<T> sources,
boolean includeSource,
Set<? super T> collection) {
Set<T> collection) {
for (T source : sources)
extendWithAncestors(source, includeSource, collection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Iterable<T> getDescendants(T source, boolean includeSource) {
@Override
public void extendWithDescendants(T source,
boolean includeSource,
Collection<? super T> collection) {
Collection<T> collection) {
// TODO: a candidate for better implementation
OntologyGraph.super.extendWithDescendants(source, includeSource, collection);
}
Expand Down Expand Up @@ -122,7 +122,7 @@ public Iterable<T> getAncestors(T source, boolean includeSource) {
@Override
public void extendWithAncestors(T source,
boolean includeSource,
Collection<? super T> collection) {
Collection<T> collection) {
// TODO: a candidate for better implementation
OntologyGraph.super.extendWithAncestors(source, includeSource, collection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ChildrenTraversal {
"HP:03, ''",
})
public void getChildren(TermId source, String payload) {
Iterable<TermId> iterable = graph.getChildren(source, false);
Iterable<TermId> iterable = graph.getChildren(source);
Set<TermId> expected = parsePayload(payload);

iterableContainsTheExpectedItems(iterable, expected);
Expand All @@ -63,15 +63,15 @@ public void getChildren(TermId source, String payload) {
"HP:03, HP:03",
})
public void getChildrenIncludingTheSource(TermId source, String payload) {
Iterable<TermId> iterable = graph.getChildren(source, true);
Collection<TermId> iterable = graph.extendWithChildren(source, true);
Set<TermId> expected = parsePayload(payload);

iterableContainsTheExpectedItems(iterable, expected);
}

@Test
public void getChildrenUnknownSource() {
NodeNotPresentInGraphException e = assertThrows(NodeNotPresentInGraphException.class, () -> graph.getChildren(UNKNOWN, false));
NodeNotPresentInGraphException e = assertThrows(NodeNotPresentInGraphException.class, () -> graph.getChildren(UNKNOWN));
assertThat(e.getMessage(), equalTo("Item not found in the graph: HP:999"));
}

Expand Down Expand Up @@ -158,7 +158,7 @@ public void isDescendantOfUnknownSource() {
"HP:03, ''",
})
public void getDescendants(TermId source, String payload) {
Iterable<TermId> iterable = graph.getDescendants(source, false);
Iterable<TermId> iterable = graph.getDescendants(source);
Set<TermId> expected = parsePayload(payload);

iterableContainsTheExpectedItems(iterable, expected);
Expand All @@ -179,15 +179,15 @@ public void getDescendants(TermId source, String payload) {
"HP:03, HP:03",
})
public void getDescendantsIncludingTheSource(TermId source, String payload) {
Iterable<TermId> iterable = graph.getDescendants(source, true);
Iterable<TermId> iterable = graph.extendWithDescendants(source, true);
Set<TermId> expected = parsePayload(payload);

iterableContainsTheExpectedItems(iterable, expected);
}

@Test
public void getDescendantsUnknownSource() {
NodeNotPresentInGraphException e = assertThrows(NodeNotPresentInGraphException.class, () -> graph.getDescendants(UNKNOWN, false));
NodeNotPresentInGraphException e = assertThrows(NodeNotPresentInGraphException.class, () -> graph.getDescendants(UNKNOWN));
assertThat(e.getMessage(), equalTo("Item not found in the graph: HP:999"));
}

Expand All @@ -204,7 +204,7 @@ public class ParentsTraversal {
"HP:0110, HP:010;HP:011",
})
public void getParents(TermId source, String payload) {
Iterable<TermId> iterable = graph.getParents(source, false);
Iterable<TermId> iterable = graph.getParents(source);
Set<TermId> expected = parsePayload(payload);

iterableContainsTheExpectedItems(iterable, expected);
Expand All @@ -218,15 +218,15 @@ public void getParents(TermId source, String payload) {
"HP:0110, HP:0110;HP:010;HP:011",
})
public void getParentsIncludingTheSource(TermId source, String payload) {
Iterable<TermId> iterable = graph.getParents(source, true);
Iterable<TermId> iterable = graph.extendWithParents(source, true);
Set<TermId> expected = parsePayload(payload);

iterableContainsTheExpectedItems(iterable, expected);
}

@Test
public void getParentsUnknownSource() {
NodeNotPresentInGraphException e = assertThrows(NodeNotPresentInGraphException.class, () -> graph.getParents(UNKNOWN, false));
NodeNotPresentInGraphException e = assertThrows(NodeNotPresentInGraphException.class, () -> graph.getParents(UNKNOWN));
assertThat(e.getMessage(), equalTo("Item not found in the graph: HP:999"));
}

Expand Down Expand Up @@ -279,7 +279,7 @@ public class AncestorTraversal {
"HP:03, HP:1",
})
public void getAncestors(TermId source, String payload) {
Iterable<TermId> iterable = graph.getAncestors(source, false);
Iterable<TermId> iterable = graph.getAncestors(source);
Set<TermId> expected = parsePayload(payload);

iterableContainsTheExpectedItems(iterable, expected);
Expand All @@ -294,7 +294,7 @@ public void getAncestors(TermId source, String payload) {
"HP:03, HP:03;HP:1",
})
public void getAncestorsIncludingTheSource(TermId source, String payload) {
Iterable<TermId> iterable = graph.getAncestors(source, true);
Iterable<TermId> iterable = graph.extendWithAncestors(source, true);
Set<TermId> expected = parsePayload(payload);

iterableContainsTheExpectedItems(iterable, expected);
Expand Down Expand Up @@ -331,7 +331,7 @@ public void isAncestorOfUnknownSource() {

@Test
public void getAncestorsUnknownSource() {
NodeNotPresentInGraphException e = assertThrows(NodeNotPresentInGraphException.class, () -> graph.getAncestors(UNKNOWN, false));
NodeNotPresentInGraphException e = assertThrows(NodeNotPresentInGraphException.class, () -> graph.getAncestors(UNKNOWN));
assertThat(e.getMessage(), equalTo("Item not found in the graph: HP:999"));
}

Expand Down Expand Up @@ -476,7 +476,7 @@ public void root(TermId root) {
public void getParents(TermId root) {
OntologyGraph<TermId> subgraph = graph.extractSubgraph(root);

assertThat(subgraph.getParents(root, false), is(emptyIterableOf(TermId.class)));
assertThat(subgraph.getParents(root), is(emptyIterableOf(TermId.class)));
}

@ParameterizedTest
Expand All @@ -497,7 +497,7 @@ public void getParents(TermId root) {
public void getAncestors(TermId root) {
OntologyGraph<TermId> subgraph = graph.extractSubgraph(root);

assertThat(subgraph.getAncestors(root, false), is(emptyIterableOf(TermId.class)));
assertThat(subgraph.getAncestors(root), is(emptyIterableOf(TermId.class)));
}

@ParameterizedTest
Expand All @@ -519,7 +519,7 @@ public void getChildren(TermId root, String expected) {
OntologyGraph<TermId> subgraph = graph.extractSubgraph(root);

Set<TermId> expectedIds = parsePayload(expected);
iterableContainsTheExpectedItems(subgraph.getChildren(root, false), expectedIds);
iterableContainsTheExpectedItems(subgraph.getChildren(root), expectedIds);
}

@ParameterizedTest
Expand All @@ -541,7 +541,7 @@ public void getDescendants(TermId root, String expected) {
OntologyGraph<TermId> subgraph = graph.extractSubgraph(root);

Set<TermId> expectedIds = parsePayload(expected);
iterableContainsTheExpectedItems(subgraph.getDescendants(root, false), expectedIds);
iterableContainsTheExpectedItems(subgraph.getDescendants(root), expectedIds);
}
}

Expand Down

0 comments on commit 01038d1

Please sign in to comment.