List of usage examples for com.google.common.collect Range hasUpperBound
public boolean hasUpperBound()
From source file:org.nmdp.ngs.range.rtree.RangeGeometries.java
/** * Create and return a new rectangle geometry from the specified range. * * @param range range, must not be null, must not be empty, and must have lower and upper bounds * @return a new rectangle geometry from the specified range *//* w w w .j a v a 2s . co m*/ public static <N extends Number & Comparable<? super N>> Rectangle range(final Range<N> range) { checkNotNull(range); if (range.isEmpty()) { throw new IllegalArgumentException("range must not be empty"); } if (!range.hasLowerBound() || !range.hasUpperBound()) { throw new IllegalArgumentException("range must have lower and upper bounds"); } Number lowerEndpoint = range.lowerEndpoint(); BoundType lowerBoundType = range.lowerBoundType(); Number upperEndpoint = range.upperEndpoint(); BoundType upperBoundType = range.upperBoundType(); /* Since we are representing genomic coordinate systems, the expectation is that endpoints are instance of Integer, Long, or BigInteger; thus for open lower and upper bounds we can safely add or substract 1.0 respectively. Then by convention a rectangle with y1 0.0 and height of 1.0 is used. closed(10, 20) --> (10.0, 0.0, 20.0, 1.0) closedOpen(10, 20) --> (10.0, 0.0, 19.0, 1.0) openClosed(10, 20) --> (11.0, 0.0, 20.0, 1.0) open(10, 20) --> (11.0, 0.0, 19.0, 1.0); closed(10, 11) --> (10.0, 0.0, 11.0, 1.0) closedOpen(10, 11) --> (10.0, 0.0, 10.0, 1.0) openClosed(10, 11) --> (11.0, 0.0, 11.0, 1.0) open(10, 11) --> empty, throw exception closed(10, 10) --> (10.0, 0.0, 10.0, 1.0) closedOpen(10, 10) --> empty, throw exception openClosed(10, 10) --> empty, throw exception open(10, 10) --> empty, throw exception */ double x1 = lowerBoundType == BoundType.OPEN ? lowerEndpoint.doubleValue() + 1.0d : lowerEndpoint.doubleValue(); double y1 = 0.0d; double x2 = upperBoundType == BoundType.OPEN ? upperEndpoint.doubleValue() - 1.0d : upperEndpoint.doubleValue(); double y2 = 1.0d; return Geometries.rectangle(x1, y1, x2, y2); }
From source file:org.dishevelled.bio.range.rtree.RangeGeometries.java
/** * Create and return a new rectangle geometry from the specified range. * * @param <N> value type//from w w w . j av a 2 s . c o m * @param range range, must not be null, must not be empty, and must have lower and upper bounds * @return a new rectangle geometry from the specified range */ public static <N extends Number & Comparable<? super N>> Rectangle range(final Range<N> range) { checkNotNull(range); if (range.isEmpty()) { throw new IllegalArgumentException("range must not be empty"); } if (!range.hasLowerBound() || !range.hasUpperBound()) { throw new IllegalArgumentException("range must have lower and upper bounds"); } Number lowerEndpoint = range.lowerEndpoint(); BoundType lowerBoundType = range.lowerBoundType(); Number upperEndpoint = range.upperEndpoint(); BoundType upperBoundType = range.upperBoundType(); /* Since we are representing genomic coordinate systems, the expectation is that endpoints are instance of Integer, Long, or BigInteger; thus for open lower and upper bounds we can safely add or subtract 1.0 respectively. Then by convention a rectangle with y1 0.0 and height of 1.0 is used. closed(10, 20) --> (10.0, 0.0, 20.0, 1.0) closedOpen(10, 20) --> (10.0, 0.0, 19.0, 1.0) openClosed(10, 20) --> (11.0, 0.0, 20.0, 1.0) open(10, 20) --> (11.0, 0.0, 19.0, 1.0); closed(10, 11) --> (10.0, 0.0, 11.0, 1.0) closedOpen(10, 11) --> (10.0, 0.0, 10.0, 1.0) openClosed(10, 11) --> (11.0, 0.0, 11.0, 1.0) open(10, 11) --> empty, throw exception closed(10, 10) --> (10.0, 0.0, 10.0, 1.0) closedOpen(10, 10) --> empty, throw exception openClosed(10, 10) --> empty, throw exception open(10, 10) --> empty, throw exception */ double x1 = lowerBoundType == BoundType.OPEN ? lowerEndpoint.doubleValue() + 1.0d : lowerEndpoint.doubleValue(); double y1 = 0.0d; double x2 = upperBoundType == BoundType.OPEN ? upperEndpoint.doubleValue() - 1.0d : upperEndpoint.doubleValue(); double y2 = 1.0d; return Geometries.rectangle(x1, y1, x2, y2); }
From source file:org.robotframework.ide.eclipse.main.plugin.project.build.validation.KeywordCallArgumentsValidator.java
private static String getRangesInfo(final Range<Integer> range) { final int minArgs = range.lowerEndpoint(); if (!range.hasUpperBound()) { return "at least " + minArgs + " " + toPluralIfNeeded("argument", minArgs); } else if (range.lowerEndpoint().equals(range.upperEndpoint())) { return minArgs + " " + toPluralIfNeeded("argument", minArgs); } else {/* w ww.ja v a2s . c om*/ final int maxArgs = range.upperEndpoint(); return "from " + minArgs + " to " + maxArgs + " arguments"; } }
From source file:org.apache.druid.sql.calcite.filtration.CombineAndSimplifyBounds.java
/** * Simplify BoundDimFilters that are children of an OR or an AND. * * @param children the filters//ww w.j av a2s . c om * @param disjunction true for disjunction, false for conjunction * * @return simplified filters */ private static DimFilter doSimplify(final List<DimFilter> children, boolean disjunction) { // Copy children list final List<DimFilter> newChildren = Lists.newArrayList(children); // Group Bound filters by dimension, extractionFn, and comparator and compute a RangeSet for each one. final Map<BoundRefKey, List<BoundDimFilter>> bounds = Maps.newHashMap(); final Iterator<DimFilter> iterator = newChildren.iterator(); while (iterator.hasNext()) { final DimFilter child = iterator.next(); if (child.equals(Filtration.matchNothing())) { // Child matches nothing, equivalent to FALSE // OR with FALSE => ignore // AND with FALSE => always false, short circuit if (disjunction) { iterator.remove(); } else { return Filtration.matchNothing(); } } else if (child.equals(Filtration.matchEverything())) { // Child matches everything, equivalent to TRUE // OR with TRUE => always true, short circuit // AND with TRUE => ignore if (disjunction) { return Filtration.matchEverything(); } else { iterator.remove(); } } else if (child instanceof BoundDimFilter) { final BoundDimFilter bound = (BoundDimFilter) child; final BoundRefKey boundRefKey = BoundRefKey.from(bound); List<BoundDimFilter> filterList = bounds.get(boundRefKey); if (filterList == null) { filterList = Lists.newArrayList(); bounds.put(boundRefKey, filterList); } filterList.add(bound); } } // Try to simplify filters within each group. for (Map.Entry<BoundRefKey, List<BoundDimFilter>> entry : bounds.entrySet()) { final BoundRefKey boundRefKey = entry.getKey(); final List<BoundDimFilter> filterList = entry.getValue(); // Create a RangeSet for this group. final RangeSet<BoundValue> rangeSet = disjunction ? RangeSets.unionRanges(Bounds.toRanges(filterList)) : RangeSets.intersectRanges(Bounds.toRanges(filterList)); if (rangeSet.asRanges().size() < filterList.size()) { // We found a simplification. Remove the old filters and add new ones. for (final BoundDimFilter bound : filterList) { if (!newChildren.remove(bound)) { throw new ISE("WTF?! Tried to remove bound but couldn't?"); } } if (rangeSet.asRanges().isEmpty()) { // range set matches nothing, equivalent to FALSE // OR with FALSE => ignore // AND with FALSE => always false, short circuit if (disjunction) { newChildren.add(Filtration.matchNothing()); } else { return Filtration.matchNothing(); } } for (final Range<BoundValue> range : rangeSet.asRanges()) { if (!range.hasLowerBound() && !range.hasUpperBound()) { // range matches all, equivalent to TRUE // AND with TRUE => ignore // OR with TRUE => always true; short circuit if (disjunction) { return Filtration.matchEverything(); } else { newChildren.add(Filtration.matchEverything()); } } else { newChildren.add(Bounds.toFilter(boundRefKey, range)); } } } } Preconditions.checkState(newChildren.size() > 0, "newChildren.size > 0"); if (newChildren.size() == 1) { return newChildren.get(0); } else { return disjunction ? new OrDimFilter(newChildren) : new AndDimFilter(newChildren); } }
From source file:org.apache.kylin.common.util.RangeUtil.java
/** * for NavigableMap sorted by C, given a range of C, return the sub map whose key falls in the range *///from w w w . j a v a2 s .c o m public static <C extends Comparable<?>, V> NavigableMap<C, V> filter(NavigableMap<C, V> values, Range<C> filterRange) { if (filterRange == null || filterRange.isEmpty()) { return Maps.newTreeMap(); } else if (filterRange.equals(Range.all())) { return values; } if (filterRange.hasUpperBound() && !filterRange.hasLowerBound()) { return values.headMap(filterRange.upperEndpoint(), upperBoundInclusive(filterRange)); } else if (filterRange.hasLowerBound() && !filterRange.hasUpperBound()) { return values.tailMap(filterRange.lowerEndpoint(), lowerBoundInclusive(filterRange)); } else { return values.subMap(filterRange.lowerEndpoint(), lowerBoundInclusive(filterRange), // filterRange.upperEndpoint(), upperBoundInclusive(filterRange)); } }
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.druid.DruidIntervalUtils.java
protected static List<Interval> toInterval(List<Range> ranges) { List<Interval> intervals = Lists.transform(ranges, new Function<Range, Interval>() { @Override/*w w w . j ava 2 s.c o m*/ public Interval apply(Range range) { if (!range.hasLowerBound() && !range.hasUpperBound()) { return DruidTable.DEFAULT_INTERVAL; } long start = range.hasLowerBound() ? toLong(range.lowerEndpoint()) : DruidTable.DEFAULT_INTERVAL.getStartMillis(); long end = range.hasUpperBound() ? toLong(range.upperEndpoint()) : DruidTable.DEFAULT_INTERVAL.getEndMillis(); if (range.hasLowerBound() && range.lowerBoundType() == BoundType.OPEN) { start++; } if (range.hasUpperBound() && range.upperBoundType() == BoundType.CLOSED) { end++; } return new Interval(start, end); } }); LOG.info("Converted time ranges " + ranges + " to interval " + intervals); return intervals; }
From source file:org.learningu.scheduling.util.bst.GeneralRange.java
/** * Converts a Range to a GeneralRange./* w ww . j a v a 2s. com*/ */ @SuppressWarnings("rawtypes") static <T extends Comparable> GeneralRange<T> from(Range<T> range) { @Nullable T lowerEndpoint = range.hasLowerBound() ? range.lowerEndpoint() : null; BoundType lowerBoundType = range.hasLowerBound() ? range.lowerBoundType() : OPEN; @Nullable T upperEndpoint = range.hasUpperBound() ? range.upperEndpoint() : null; BoundType upperBoundType = range.hasUpperBound() ? range.upperBoundType() : OPEN; return new GeneralRange<T>(Ordering.natural(), range.hasLowerBound(), lowerEndpoint, lowerBoundType, range.hasUpperBound(), upperEndpoint, upperBoundType); }
From source file:io.druid.sql.calcite.filtration.RangeSets.java
public static List<Interval> toIntervals(final RangeSet<Long> rangeSet) { final List<Interval> retVal = Lists.newArrayList(); for (Range<Long> range : rangeSet.asRanges()) { final long start; final long end; if (range.hasLowerBound()) { final long millis = range.lowerEndpoint(); start = millis + (range.lowerBoundType() == BoundType.OPEN ? 1 : 0); } else {/*from w ww .j a v a2s . co m*/ start = Filtration.eternity().getStartMillis(); } if (range.hasUpperBound()) { final long millis = range.upperEndpoint(); end = millis + (range.upperBoundType() == BoundType.OPEN ? 0 : 1); } else { end = Filtration.eternity().getEndMillis(); } retVal.add(Intervals.utc(start, end)); } return retVal; }
From source file:ec.util.grid.swing.ext.TableGridCommand.java
private static Table<?> copy2(GridModel model, Range<Integer> r, Range<Integer> c, boolean rowHeader, boolean columnHeader) { if (model.getRowCount() == 0 || model.getColumnCount() == 0) { return new Table<>(0, 0); }//from w w w. ja v a 2 s .c o m int firstRow = r.hasLowerBound() ? (r.lowerBoundType().equals(BoundType.CLOSED) ? r.lowerEndpoint() : (r.lowerEndpoint() + 1)) : 0; int lastRow = r.hasUpperBound() ? (r.upperBoundType().equals(BoundType.CLOSED) ? r.upperEndpoint() : (r.upperEndpoint() - 1)) : (model.getRowCount() - 1); int firstColumn = c.hasLowerBound() ? (c.lowerBoundType().equals(BoundType.CLOSED) ? c.lowerEndpoint() : (c.lowerEndpoint() + 1)) : 0; int lastColumn = c.hasUpperBound() ? (c.upperBoundType().equals(BoundType.CLOSED) ? c.upperEndpoint() : (c.upperEndpoint() - 1)) : (model.getColumnCount() - 1); return copy(model, firstRow, firstColumn, lastRow, lastColumn, rowHeader, columnHeader); }
From source file:org.kitesdk.data.spi.ConstraintsSerialization.java
/** * Serializes an {@link Range} into the specified {@code out} stream. */// w ww. j a v a 2s. c o m private static void writeRangePredicate(Schema fieldSchema, Range range, ObjectOutputStream out) throws IOException { if (range.hasLowerBound()) { //write out that there is a lower endpoint and the value. out.writeBoolean(true); out.writeBoolean(range.isLowerBoundOpen()); writeValue(fieldSchema, range.lowerEndpoint(), out); } else { //Write that there is no lower bound out.writeBoolean(false); } if (range.hasUpperBound()) { out.writeBoolean(true); out.writeBoolean(range.isUpperBoundOpen()); //write out that there is a lower endpoint and the value. writeValue(fieldSchema, range.upperEndpoint(), out); } else { //write out that there is not an upper bound out.writeBoolean(false); } }