Package org.aksw.commons.util.range
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 com.google.common.collect.Range<Long>RANGE_LONGstatic com.google.common.collect.Range<Long>rangeStartingWithZero
-
Constructor Summary
Constructors Constructor Description RangeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods 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, java.util.function.BiFunction<? super I,? super V,? extends O> op)Apply a binary operator (e.g.static <C extends Comparable<C>>
intcompareToLowerBound(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>>
intcompareToUpperBound(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<T> lower, Endpoint<T> upper)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 toRange.range(Comparable, BoundType, Comparable, BoundType)with the difference thatnullcan 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 intintLength(com.google.common.collect.Range<Long> range)static booleanisDiscrete(com.google.common.collect.RangeSet<?> rangeSet)True iff all ranges are singletonsstatic booleanisDiscrete(Collection<? extends com.google.common.collect.Range<?>> ranges)static booleanisSingleton(com.google.common.collect.Range<?> range)static booleanisSingleton(com.google.common.collect.RangeSet<?> rangeSet)static booleanisSingleton(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, java.util.function.BiFunction<C,Long,C> addition)Convert a range relative within another one to an absolute rangestatic <I extends Comparable<I>,O extends Comparable<O>>
com.google.common.collect.Range<O>map(com.google.common.collect.Range<I> range, java.util.function.Function<? super I,? extends O> mapper)Return a new range with each concrete endpoint of the input range passed through a transformation functionstatic com.google.common.collect.Range<Long>multiplyByPageSize(com.google.common.collect.Range<Long> range, long pageSize)static doublepickDouble(com.google.common.collect.Range<Double> range, Random random)static longpickLong(com.google.common.collect.Range<Long> range, Random random)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.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, java.util.function.BiFunction<C,Long,C> addition)static com.google.common.collect.Range<Long>shiftLong(com.google.common.collect.Range<Long> rawRange, long distance)static longsizeLong(com.google.common.collect.Range<Long> range)static com.google.common.collect.Range<Long>startFromZero(com.google.common.collect.Range<Long> range)static java.util.stream.Stream<Long>streamEnclosingRanges(NavigableMap<Long,Long> offsetToEndpoint, long start, long end)Streams all enclosing ranges (if any) ordered by decreasing offset based on offsetToKeystatic <T> List<T>subList(List<T> list, com.google.common.collect.Range<Integer> subRange)static CountInfotoCountInfo(com.google.common.collect.Range<? extends Number> range)static <T extends Comparable<T>>
Optional<T>tryGetSingleton(com.google.common.collect.Range<T> range)
-
-
-
Method Detail
-
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)
-
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, java.util.function.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, java.util.function.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, java.util.function.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, java.util.function.Function<? super I,? extends O> mapper)
Return a new range with each concrete endpoint of the input range passed through a transformation function
-
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:
offsetToKey-keyToMaxOffset- // If there are multiple candidates with the same offset then only the one with the highest max offset should be chosendemandGaps-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.
-
streamEnclosingRanges
public static java.util.stream.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:
offsetToKey-keyToMaxOffset-start-end-- 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 toRange.range(Comparable, BoundType, Comparable, BoundType)with the difference thatnullcan 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<T> lower, Endpoint<T> upper)
-
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
-
-