Class RangeUtils

java.lang.Object
org.aksw.commons.util.range.RangeUtils

public class RangeUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.google.common.collect.Range<Long>
     
    static final com.google.common.collect.Range<Long>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <I extends Comparable<I>, O extends Comparable<O>, V>
    com.google.common.collect.Range<O>
    apply(com.google.common.collect.Range<I> range, V value, BiFunction<? super I, ? super V, ? extends O> op)
    Apply a binary operator (e.g.
    static <C extends Comparable<C>>
    int
    compareToLowerBound(com.google.common.collect.Range<C> a, com.google.common.collect.Range<C> b)
    Compare the lower bounds of two canonical ranges.
    static <C extends Comparable<C>>
    int
    compareToUpperBound(com.google.common.collect.Range<C> a, com.google.common.collect.Range<C> b)
    Compare the upper bounds of two canonical ranges.
    static PageInfo<Long>
    computeRange(com.google.common.collect.Range<Long> range, long pageSize)
     
    static <T extends Comparable<T>>
    com.google.common.collect.Range<T>
    create(Endpoint<? extends T> lower, Endpoint<? extends T> upper)
    Create a range from two endpoints.
    static <T extends Comparable<T>>
    com.google.common.collect.Range<T>
    create(T lower, com.google.common.collect.BoundType lowerType, T upper, com.google.common.collect.BoundType upperType)
    Create method similar to Range.range(Comparable, BoundType, Comparable, BoundType) with the difference that null can be used as values in order to denote 'below/above all'.
    static com.google.common.collect.Range<Long>
    createRange(Long limit, Long offset)
    Create a range from limit and offset.
    static <C extends Comparable<C>>
    com.google.common.collect.RangeSet<C>
    gaps(com.google.common.collect.Range<C> request, com.google.common.collect.RangeSet<C> ranges)
    Compute the set of gaps for the given request range.
    static <K extends Comparable<K>, V>
    Set<Map.Entry<com.google.common.collect.Range<K>, V>>
    getIntersectingRanges(com.google.common.collect.Range<K> r, Collection<Map.Entry<com.google.common.collect.Range<K>, V>> ranges)
     
    static <T extends Comparable<T>>
    Endpoint<T>
    getLowerEndpoint(com.google.common.collect.Range<T> range)
     
    static <T extends Comparable<T>>
    Endpoint<T>
    getUpperEndpoint(com.google.common.collect.Range<T> range)
     
    static int
    intLength(com.google.common.collect.Range<Long> range)
     
    static boolean
    isDiscrete(com.google.common.collect.RangeSet<?> rangeSet)
    True iff all ranges are singletons
    static boolean
    isDiscrete(Collection<? extends com.google.common.collect.Range<?>> ranges)
     
    static boolean
    isSingleton(com.google.common.collect.Range<?> range)
     
    static boolean
    isSingleton(com.google.common.collect.RangeSet<?> rangeSet)
     
    static boolean
    isSingleton(Collection<? extends com.google.common.collect.Range<?>> ranges)
     
    static <C extends Comparable<C>>
    com.google.common.collect.Range<C>
    makeAbsolute(com.google.common.collect.Range<C> outer, com.google.common.collect.Range<C> relative, com.google.common.collect.DiscreteDomain<C> domain, BiFunction<C,Long,C> addition)
    Convert a range relative within another one to an absolute range
    static <I extends Comparable<I>, O extends Comparable<O>>
    com.google.common.collect.Range<O>
    map(com.google.common.collect.Range<I> range, BiFunction<? super I, com.google.common.collect.BoundType, Endpoint<? extends O>> lowerEndpointMapper, BiFunction<? super I, com.google.common.collect.BoundType, Endpoint<? extends O>> upperEndpointMapper)
    Return a new range with each lower and upper endpoint of the input range passed through a separate transformation function.
    static <I extends Comparable<I>, O extends Comparable<O>>
    com.google.common.collect.Range<O>
    map(com.google.common.collect.Range<I> range, Function<? super I, ? extends O> mapper)
    Return a new range with each concrete endpoint of the input range passed through a transformation function
    static com.google.common.collect.Range<Long>
    multiplyByPageSize(com.google.common.collect.Range<Long> range, long pageSize)
     
    static double
    pickDouble(com.google.common.collect.Range<Double> range, Random random)
     
    static long
    pickLong(com.google.common.collect.Range<Long> range, Random random)
     
    static double
    randomDouble(com.google.common.collect.Range<? extends Number> range, Random random)
    Return a random double value within the given range.
    scheduleRangeSupply(NavigableMap<Long,Long> supplyOffsetToEndpoint, com.google.common.collect.RangeSet<Long> demandGaps, long maxRedundantSize, long maxSupplierRange)
    Given a map [start, end) pairs (start inclusive, end exclusive) of initial suppliers, return a schedule that covers the set of gaps.
    static <C extends Comparable<C>>
    com.google.common.collect.Range<C>
    shift(com.google.common.collect.Range<C> rawRange, long distance, com.google.common.collect.DiscreteDomain<C> domain, BiFunction<C,Long,C> addition)
     
    static com.google.common.collect.Range<Long>
    shiftLong(com.google.common.collect.Range<Long> rawRange, long distance)
     
    static long
    sizeLong(com.google.common.collect.Range<Long> range)
     
    static com.google.common.collect.Range<Long>
    startFromZero(com.google.common.collect.Range<Long> range)
     
    static Stream<Long>
    streamEnclosingRanges(NavigableMap<Long,Long> offsetToEndpoint, long start, long end)
    Streams all enclosing ranges (if any) ordered by decreasing offset based on offsetToKey
    static <T> List<T>
    subList(List<T> list, com.google.common.collect.Range<Integer> subRange)
     
    static CountInfo
    toCountInfo(com.google.common.collect.Range<? extends Number> range)
     
    static <T extends Comparable<T>>
    Optional<T>
    tryGetSingleton(com.google.common.collect.Range<T> range)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • rangeStartingWithZero

      public static final com.google.common.collect.Range<Long> rangeStartingWithZero
    • RANGE_LONG

      public static final com.google.common.collect.Range<Long> RANGE_LONG
  • Constructor Details

    • RangeUtils

      public RangeUtils()
  • Method Details

    • sizeLong

      public static long sizeLong(com.google.common.collect.Range<Long> range)
    • intLength

      public static int intLength(com.google.common.collect.Range<Long> range)
    • subList

      public static <T> List<T> subList(List<T> list, com.google.common.collect.Range<Integer> subRange)
    • tryGetSingleton

      public static <T extends Comparable<T>> Optional<T> tryGetSingleton(com.google.common.collect.Range<T> range)
    • isDiscrete

      public static boolean isDiscrete(com.google.common.collect.RangeSet<?> rangeSet)
      True iff all ranges are singletons
    • isDiscrete

      public static boolean isDiscrete(Collection<? extends com.google.common.collect.Range<?>> ranges)
    • isSingleton

      public static boolean isSingleton(com.google.common.collect.RangeSet<?> rangeSet)
    • isSingleton

      public static boolean isSingleton(Collection<? extends com.google.common.collect.Range<?>> ranges)
    • isSingleton

      public static boolean isSingleton(com.google.common.collect.Range<?> range)
    • pickLong

      public static long pickLong(com.google.common.collect.Range<Long> range, Random random)
    • pickDouble

      public static double pickDouble(com.google.common.collect.Range<Double> range, Random random)
    • toCountInfo

      public static CountInfo toCountInfo(com.google.common.collect.Range<? extends Number> range)
    • makeAbsolute

      public static <C extends Comparable<C>> com.google.common.collect.Range<C> makeAbsolute(com.google.common.collect.Range<C> outer, com.google.common.collect.Range<C> relative, com.google.common.collect.DiscreteDomain<C> domain, BiFunction<C,Long,C> addition)
      Convert a range relative within another one to an absolute range
      Parameters:
      outer -
      relative -
      domain -
      addition -
      Returns:
    • shiftLong

      public static com.google.common.collect.Range<Long> shiftLong(com.google.common.collect.Range<Long> rawRange, long distance)
    • shift

      public static <C extends Comparable<C>> com.google.common.collect.Range<C> shift(com.google.common.collect.Range<C> rawRange, long distance, com.google.common.collect.DiscreteDomain<C> domain, BiFunction<C,Long,C> addition)
    • getIntersectingRanges

      public static <K extends Comparable<K>, V> Set<Map.Entry<com.google.common.collect.Range<K>, V>> getIntersectingRanges(com.google.common.collect.Range<K> r, Collection<Map.Entry<com.google.common.collect.Range<K>, V>> ranges)
    • startFromZero

      public static com.google.common.collect.Range<Long> startFromZero(com.google.common.collect.Range<Long> range)
    • apply

      public static <I extends Comparable<I>, O extends Comparable<O>, V> com.google.common.collect.Range<O> apply(com.google.common.collect.Range<I> range, V value, BiFunction<? super I, ? super V, ? extends O> op)
      Apply a binary operator (e.g. multiplication, addition, ...) to any endpoint of the range and a given value.
      Type Parameters:
      I -
      Parameters:
      range -
      value -
      op -
      Returns:
    • map

      public static <I extends Comparable<I>, O extends Comparable<O>> com.google.common.collect.Range<O> map(com.google.common.collect.Range<I> range, Function<? super I, ? extends O> mapper)
      Return a new range with each concrete endpoint of the input range passed through a transformation function
    • map

      public static <I extends Comparable<I>, O extends Comparable<O>> com.google.common.collect.Range<O> map(com.google.common.collect.Range<I> range, BiFunction<? super I, com.google.common.collect.BoundType, Endpoint<? extends O>> lowerEndpointMapper, BiFunction<? super I, com.google.common.collect.BoundType, Endpoint<? extends O>> upperEndpointMapper)
      Return a new range with each lower and upper endpoint of the input range passed through a separate transformation function. The lower and upper endpoint mappers may return null to indicate the absence of a lower or upper bound in the mapped range, respectively.
    • multiplyByPageSize

      public static com.google.common.collect.Range<Long> multiplyByPageSize(com.google.common.collect.Range<Long> range, long pageSize)
    • computeRange

      public static PageInfo<Long> computeRange(com.google.common.collect.Range<Long> range, long pageSize)
    • gaps

      public static <C extends Comparable<C>> com.google.common.collect.RangeSet<C> gaps(com.google.common.collect.Range<C> request, com.google.common.collect.RangeSet<C> ranges)
      Compute the set of gaps for the given request range. This is the complement of the given ranges constrained to the request range.
    • scheduleRangeSupply

      public static NavigableMap<Long,Long> scheduleRangeSupply(NavigableMap<Long,Long> supplyOffsetToEndpoint, com.google.common.collect.RangeSet<Long> demandGaps, long maxRedundantSize, long maxSupplierRange)
      Given a map [start, end) pairs (start inclusive, end exclusive) of initial suppliers, return a schedule that covers the set of gaps.
      Type Parameters:
      K -
      Parameters:
      demandGaps -
      maxRedundantSize - The maximum number of consecutive items that may be fetched redundantly without enforcing a separate request.
      maxSupplierRange - The maximum number of items a single supplier can supply.
      offsetToKey -
      keyToMaxOffset - // If there are multiple candidates with the same offset then only the one with the highest max offset should be chosen
    • streamEnclosingRanges

      public static Stream<Long> streamEnclosingRanges(NavigableMap<Long,Long> offsetToEndpoint, long start, long end)
      Streams all enclosing ranges (if any) ordered by decreasing offset based on offsetToKey
      Type Parameters:
      K -
      Parameters:
      start -
      end -
      offsetToKey -
      keyToMaxOffset -
      Returns:
    • createRange

      public static com.google.common.collect.Range<Long> createRange(Long limit, Long offset)
      Create a range from limit and offset. Either or both may be null.
    • create

      public static <T extends Comparable<T>> com.google.common.collect.Range<T> create(T lower, com.google.common.collect.BoundType lowerType, T upper, com.google.common.collect.BoundType upperType)
      Create method similar to Range.range(Comparable, BoundType, Comparable, BoundType) with the difference that null can be used as values in order to denote 'below/above all'. The respective bound type is then ignored.
    • create

      public static <T extends Comparable<T>> com.google.common.collect.Range<T> create(Endpoint<? extends T> lower, Endpoint<? extends T> upper)
      Create a range from two endpoints. If either an endpoint or it's value is null then it is considered as unbounded.
    • getLowerEndpoint

      public static <T extends Comparable<T>> Endpoint<T> getLowerEndpoint(com.google.common.collect.Range<T> range)
    • getUpperEndpoint

      public static <T extends Comparable<T>> Endpoint<T> getUpperEndpoint(com.google.common.collect.Range<T> range)
    • compareToLowerBound

      public static <C extends Comparable<C>> int compareToLowerBound(com.google.common.collect.Range<C> a, com.google.common.collect.Range<C> b)
      Compare the lower bounds of two canonical ranges. This means the bound type is ignored. If both endpoints are absent they are considered equal and the result is 0
    • compareToUpperBound

      public static <C extends Comparable<C>> int compareToUpperBound(com.google.common.collect.Range<C> a, com.google.common.collect.Range<C> b)
      Compare the upper bounds of two canonical ranges. This means the bound type is ignored. If both endpoints are absent they are considered equal and the result is 0
    • randomDouble

      public static double randomDouble(com.google.common.collect.Range<? extends Number> range, Random random)
      Return a random double value within the given range. Open bounds are capped at Double.MIN_VALUE and MAX_VALUE, respectively. TODO This method currently does not respect exclusive bounds