MCPcopy
hub / github.com/google/guava / create

Method create

guava/src/com/google/common/collect/ContiguousSet.java:62–95  ·  view source on GitHub ↗

Returns a {@code ContiguousSet} containing the same values in the given domain {@linkplain Range#contains contained} by the range. @throws IllegalArgumentException if neither range nor the domain has a lower bound, or if neither has an upper bound @since 13.0

(
      Range<C> range, DiscreteDomain<C> domain)

Source from the content-addressed store, hash-verified

60 * @since 13.0
61 */
62 public static <C extends Comparable> ContiguousSet<C> create(
63 Range<C> range, DiscreteDomain<C> domain) {
64 checkNotNull(range);
65 checkNotNull(domain);
66 Range<C> effectiveRange = range;
67 try {
68 if (!range.hasLowerBound()) {
69 effectiveRange = effectiveRange.intersection(Range.atLeast(domain.minValue()));
70 }
71 if (!range.hasUpperBound()) {
72 effectiveRange = effectiveRange.intersection(Range.atMost(domain.maxValue()));
73 }
74 } catch (NoSuchElementException e) {
75 throw new IllegalArgumentException(e);
76 }
77
78 boolean empty;
79 if (effectiveRange.isEmpty()) {
80 empty = true;
81 } else {
82 /*
83 * requireNonNull is safe because the effectiveRange operations above would have thrown or
84 * effectiveRange.isEmpty() would have returned true.
85 */
86 C afterLower = requireNonNull(range.lowerBound.leastValueAbove(domain));
87 C beforeUpper = requireNonNull(range.upperBound.greatestValueBelow(domain));
88 // Per class spec, we are allowed to throw CCE if necessary
89 empty = Range.compareOrThrow(afterLower, beforeUpper) > 0;
90 }
91
92 return empty
93 ? new EmptyContiguousSet<C>(domain)
94 : new RegularContiguousSet<C>(effectiveRange, domain);
95 }
96
97 /**
98 * Returns a nonempty contiguous set containing all {@code int} values from {@code lower}

Callers 15

intersectionMethod · 0.95
closedMethod · 0.95
closedOpenMethod · 0.95
sizeMethod · 0.95
computeNextMethod · 0.95
indexOfMethod · 0.95
setUpMethod · 0.95
QuantilesBenchmarkClass · 0.95
testEqualsMethod · 0.95
testSerializationMethod · 0.95

Calls 12

atLeastMethod · 0.95
atMostMethod · 0.95
compareOrThrowMethod · 0.95
isEmptyMethod · 0.65
checkNotNullMethod · 0.45
hasLowerBoundMethod · 0.45
intersectionMethod · 0.45
minValueMethod · 0.45
hasUpperBoundMethod · 0.45
maxValueMethod · 0.45
leastValueAboveMethod · 0.45
greatestValueBelowMethod · 0.45

Tested by 15

setUpMethod · 0.76
testEqualsMethod · 0.76
testSerializationMethod · 0.76
testCreate_noMinMethod · 0.76
testCreate_noMaxMethod · 0.76
testCreate_emptyMethod · 0.76
testHeadSetMethod · 0.76
testHeadSet_tooSmallMethod · 0.76
testTailSetMethod · 0.76
testTailSet_tooLargeMethod · 0.76
testSubSetMethod · 0.76