Skip to content

Commit

Permalink
Allow alternate GroupedList constructor to be public, but add warning…
Browse files Browse the repository at this point in the history
…s regarding the integrity of the structure to various operations.

PiperOrigin-RevId: 169715233
  • Loading branch information
shreyax authored and katre committed Sep 25, 2017
1 parent ca6b46d commit 3c6c45f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/com/google/devtools/build/lib/util/GroupedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public GroupedList() {
this.elements = new ArrayList<>(1);
}

// Only for use when uncompressing a GroupedList.
private GroupedList(int size, List<Object> elements) {
// Use with caution as there are no checks in place for the integrity of the resulting object
// (no de-duping or verifying there are no nested lists).
public GroupedList(int size, List<Object> elements) {
this.size = size;
this.elements = new ArrayList<>(elements);
}
Expand Down Expand Up @@ -99,6 +100,8 @@ public Set<T> append(GroupedListHelper<T> helper) {
return uniquifier;
}

// Use with caution as there are no checks in place for the integrity of the resulting object
// (no de-duping).
public void appendGroup(Collection<T> group) {
// Do a check to make sure we don't have lists here. Note that if group is empty,
// Iterables.getFirst will return null, and null is not instanceof List.
Expand Down Expand Up @@ -356,9 +359,12 @@ private static <E> List<Object> remove(List<Object> elements, Set<E> toRemove) {
* <p>If it contains a single element, then that element must not be {@code null}, and that
* element is added to {@param elements}.
*
* <p>If it contains more than one element, then an {@link ImmutableList} copy of {@param item}
* is added as the next element of {@param elements}. (This means {@param elements} may contain
* both raw objects and {@link ImmutableList}s.)
* <p>If it contains more than one element, then an {@link ImmutableList} copy of {@param item} is
* added as the next element of {@param elements}. (This means {@param elements} may contain both
* raw objects and {@link ImmutableList}s.)
*
* <p>Use with caution as there are no checks in place for the integrity of the resulting object
* (no de-duping or verifying there are no nested lists).
*/
private static void addItem(Collection<?> item, List<Object> elements) {
switch (item.size()) {
Expand Down

0 comments on commit 3c6c45f

Please sign in to comment.