Class RangeSets

java.lang.Object
org.apache.calcite.util.RangeSets

public class RangeSets extends Object
Utilities for Guava RangeSet.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Consumer of Range values.
    static interface 
    Deconstructor for Range values.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <C extends Comparable<C>>
    int
    compare(com.google.common.collect.Range<C> r0, com.google.common.collect.Range<C> r1)
    Compares two ranges.
    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.
    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.
    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.
    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.
    static <C extends Comparable<C>>
    void
    forEach(com.google.common.collect.Range<C> range, RangeSets.Consumer<C> consumer)
     
    static <C extends Comparable<C>>
    void
    forEach(com.google.common.collect.RangeSet<C> rangeSet, RangeSets.Consumer<C> consumer)
     
    static <C extends Comparable<C>>
    int
    hashCode(com.google.common.collect.RangeSet<C> rangeSet)
    Computes a hash code for a range set.
    static <C extends Comparable<C>>
    boolean
    isOpenInterval(com.google.common.collect.RangeSet<C> rangeSet)
    Returns whether a range set is a single open interval.
    static <C extends Comparable<C>>
    boolean
    isPoint(com.google.common.collect.Range<C> range)
    Returns whether a range is a point.
    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.
    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>
    Creates a consumer that prints values to a StringBuilder.
    static <C extends Comparable<C>>
    com.google.common.collect.RangeSet<C>
    Returns the unrestricted range set.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static <C extends Comparable<C>> com.google.common.collect.RangeSet<C> 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 upon Set.hashCode()).

      The algorithm is based on List.hashCode(), which is well-defined because RangeSet.asRanges() is sorted.

    • isPoint

      public static <C extends Comparable<C>> boolean isPoint(com.google.common.collect.Range<C> range)
      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 a StringBuilder.