MCPcopy Create free account
hub / github.com/apache/calcite / distinctList

Method distinctList

core/src/main/java/org/apache/calcite/util/Util.java:2353–2367  ·  view source on GitHub ↗

Converts a list into a list with unique elements. The order is preserved; the second and subsequent occurrences are removed. If the list is already unique it is returned unchanged.

(List<E> list)

Source from the content-addressed store, hash-verified

2351 *
2352 * <p>If the list is already unique it is returned unchanged. */
2353 public static <E> List<E> distinctList(List<E> list) {
2354 // If the list is small, check for duplicates using pairwise comparison.
2355 if (list.size() < QUICK_DISTINCT) {
2356 if (isDistinct(list)) {
2357 return list;
2358 }
2359 } else {
2360 // Lists that have all the same element are common. Avoiding creating a
2361 // set.
2362 if (allSameElement(list)) {
2363 return ImmutableList.of(list.get(0));
2364 }
2365 }
2366 return ImmutableList.copyOf(new LinkedHashSet<>(list));
2367 }
2368
2369 /** Returns whether all of the elements of a list are equal.
2370 * The list is assumed to be non-empty. */

Callers 6

testDistinctListMethod · 0.95
setOpMethod · 0.95
analyzeMethod · 0.95
getTypeMethod · 0.95
containsMethod · 0.95
containsOrderlessMethod · 0.95

Calls 6

isDistinctMethod · 0.95
allSameElementMethod · 0.95
sizeMethod · 0.65
ofMethod · 0.65
getMethod · 0.65
copyOfMethod · 0.65

Tested by 1

testDistinctListMethod · 0.76