Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-6698] Add Javadoc to PartiallyOrderedSet#getNonChildren and getNonParents to clarify their behavior #4054

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public class PartiallyOrderedSet<E> extends AbstractSet<E> {
* in the set.
*/
private final Node<E> topNode;
/**
* Synthetic node to hold all nodes that have no children. It does not appear
* in the set.
*/
private final Node<E> bottomNode;

/**
Expand Down Expand Up @@ -681,10 +685,22 @@ private void closure(Function<E, Iterable<E>> generator, E e, ImmutableList.Buil
}
}

/**
* Returns all elements in the set that are not children. These elements appear at the top of
* the poset, and they usually referred to as roots/maximal elements of the poset.
*
* @return a list of elements that are not children.
*/
public List<E> getNonChildren() {
return strip(topNode.childList);
}

/**
* Returns all elements in the set that are not parents. These elements appear at the bottom of
* the poset, and they usually referred to as leafs/minimal elements of the poset.
*
* @return a list of elements that are not parents.
*/
public List<E> getNonParents() {
return strip(bottomNode.parentList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -180,6 +181,30 @@ private static boolean isBitSuperset(Integer e1, Integer e2) {
assertEqualsList("['ab', 'abcd']", poset.getAncestors("'a'"));
}

@Test void testGetNonParentsOnLteIntPosetReturnsMinValue() {
PartiallyOrderedSet<Integer> poset =
new PartiallyOrderedSet<>((i, j) -> i <= j, Arrays.asList(20, 30, 40));
assertThat(poset.getNonParents(), hasToString("[20]"));
}

@Test void testGetNonChildrenOnLteIntPosetReturnsMaxValue() {
PartiallyOrderedSet<Integer> poset =
new PartiallyOrderedSet<>((i, j) -> i <= j, Arrays.asList(20, 30, 40));
assertThat(poset.getNonChildren(), hasToString("[40]"));
}

@Test void testGetNonParentsOnGteIntPosetReturnsMaxValue() {
PartiallyOrderedSet<Integer> poset =
new PartiallyOrderedSet<>((i, j) -> i >= j, Arrays.asList(20, 30, 40));
assertThat(poset.getNonParents(), hasToString("[40]"));
}

@Test void testGetNonChildrenOnGteIntPosetReturnsMinValue() {
PartiallyOrderedSet<Integer> poset =
new PartiallyOrderedSet<>((i, j) -> i >= j, Arrays.asList(20, 30, 40));
assertThat(poset.getNonChildren(), hasToString("[20]"));
}

@Test void testPosetTricky() {
final PartiallyOrderedSet<String> poset =
new PartiallyOrderedSet<>(STRING_SUBSET_ORDERING);
Expand All @@ -195,6 +220,8 @@ private static boolean isBitSuperset(Integer e1, Integer e2) {
printValidate(poset);
poset.add("'ab'");
printValidate(poset);
assertThat(poset.getNonChildren(), hasToString("['ac', 'ab']"));
assertThat(poset.getNonParents(), hasToString("['a', 'b']"));
}

@Test void testPosetBits() {
Expand Down
Loading