Package org.apache.calcite.util
Class RangeSets
java.lang.Object
org.apache.calcite.util.RangeSets
Utilities for Guava
RangeSet
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Consumer ofRange
values.static interface
Deconstructor forRange
values. -
Method Summary
Modifier and TypeMethodDescriptionstatic <C extends Comparable<C>>
intcompare
(com.google.common.collect.Range<C> r0, com.google.common.collect.Range<C> r1) Compares two ranges.static <C extends Comparable<C>>
intcompare
(com.google.common.collect.RangeSet<C> s0, com.google.common.collect.RangeSet<C> s1) Compares two range sets.static <C extends Comparable<C>,
C2 extends Comparable<C2>>
com.google.common.collect.Range<C2>Copies a range.static <C extends Comparable<C>,
C2 extends Comparable<C2>>
com.google.common.collect.RangeSet<C2>Copies a range set.static <C extends Comparable<C>>
intcountPoints
(com.google.common.collect.RangeSet<C> rangeSet) Returns the number of ranges in a range set that are points.static <C extends Comparable<C>>
voidforEach
(com.google.common.collect.Range<C> range, RangeSets.Consumer<C> consumer) static <C extends Comparable<C>>
voidforEach
(com.google.common.collect.RangeSet<C> rangeSet, RangeSets.Consumer<C> consumer) static <C extends Comparable<C>>
inthashCode
(com.google.common.collect.RangeSet<C> rangeSet) Computes a hash code for a range set.static <C extends Comparable<C>>
booleanisOpenInterval
(com.google.common.collect.RangeSet<C> rangeSet) Returns whether a range set is a single open interval.static <C extends Comparable<C>>
booleanisPoint
(com.google.common.collect.Range<C> range) Returns whether a range is a point.static <C extends Comparable<C>,
R>
Rmap
(com.google.common.collect.Range<C> range, RangeSets.Handler<C, R> handler) Calls the appropriate handler method for the type of range.static <C extends Comparable<C>,
C2 extends Comparable<C2>>
com.google.common.collect.RangeSet<C2>map
(com.google.common.collect.RangeSet<C> rangeSet, RangeSets.Handler<C, com.google.common.collect.Range<C2>> handler) Calls the appropriate handler method for each range in a range set, creating a new range set from the results.static <C extends Comparable<C>>
com.google.common.collect.RangeSet<C>minus
(com.google.common.collect.RangeSet<C> rangeSet, com.google.common.collect.Range<C> range) Subtracts a range from a range set.static <C extends Comparable<C>>
RangeSets.Consumer<C>printer
(StringBuilder sb, BiConsumer<StringBuilder, C> valuePrinter) Creates a consumer that prints values to aStringBuilder
.static <C extends Comparable<C>>
com.google.common.collect.RangeSet<C>Returns the unrestricted range set.
-
Method Details
-
minus
public static <C extends Comparable<C>> com.google.common.collect.RangeSet<C> minus(com.google.common.collect.RangeSet<C> rangeSet, com.google.common.collect.Range<C> range) Subtracts a range from a range set. -
rangeSetAll
Returns the unrestricted range set. -
compare
public static <C extends Comparable<C>> int compare(com.google.common.collect.RangeSet<C> s0, com.google.common.collect.RangeSet<C> s1) Compares two range sets. -
compare
public static <C extends Comparable<C>> int compare(com.google.common.collect.Range<C> r0, com.google.common.collect.Range<C> r1) Compares two ranges. -
hashCode
public static <C extends Comparable<C>> int hashCode(com.google.common.collect.RangeSet<C> rangeSet) Computes a hash code for a range set.This method does not compute the same result as
RangeSet.hashCode()
. That is a poor hash code because it is based uponSet.hashCode()
).The algorithm is based on
List.hashCode()
, which is well-defined becauseRangeSet.asRanges()
is sorted. -
isPoint
Returns whether a range is a point. -
isOpenInterval
public static <C extends Comparable<C>> boolean isOpenInterval(com.google.common.collect.RangeSet<C> rangeSet) Returns whether a range set is a single open interval. -
countPoints
public static <C extends Comparable<C>> int countPoints(com.google.common.collect.RangeSet<C> rangeSet) Returns the number of ranges in a range set that are points.If every range in a range set is a point then it can be converted to a SQL IN list.
-
map
public static <C extends Comparable<C>,C2 extends Comparable<C2>> com.google.common.collect.RangeSet<C2> map(com.google.common.collect.RangeSet<C> rangeSet, RangeSets.Handler<C, com.google.common.collect.Range<C2>> handler) Calls the appropriate handler method for each range in a range set, creating a new range set from the results. -
map
public static <C extends Comparable<C>,R> R map(com.google.common.collect.Range<C> range, RangeSets.Handler<C, R> handler) Calls the appropriate handler method for the type of range. -
copy
public static <C extends Comparable<C>,C2 extends Comparable<C2>> com.google.common.collect.RangeSet<C2> copy(com.google.common.collect.RangeSet<C> rangeSet, Function<C, C2> map) Copies a range set. -
copy
public static <C extends Comparable<C>,C2 extends Comparable<C2>> com.google.common.collect.Range<C2> copy(com.google.common.collect.Range<C> range, Function<C, C2> map) Copies a range. -
forEach
public static <C extends Comparable<C>> void forEach(com.google.common.collect.RangeSet<C> rangeSet, RangeSets.Consumer<C> consumer) -
forEach
public static <C extends Comparable<C>> void forEach(com.google.common.collect.Range<C> range, RangeSets.Consumer<C> consumer) -
printer
public static <C extends Comparable<C>> RangeSets.Consumer<C> printer(StringBuilder sb, BiConsumer<StringBuilder, C> valuePrinter) Creates a consumer that prints values to aStringBuilder
.
-