Java Code Examples for com.google.common.collect.Range#atLeast()

The following examples show how to use com.google.common.collect.Range#atLeast() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RexSimplify.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static <C extends Comparable<C>> Range<C> range(SqlKind comparison,
    C c) {
  switch (comparison) {
  case EQUALS:
    return Range.singleton(c);
  case LESS_THAN:
    return Range.lessThan(c);
  case LESS_THAN_OR_EQUAL:
    return Range.atMost(c);
  case GREATER_THAN:
    return Range.greaterThan(c);
  case GREATER_THAN_OR_EQUAL:
    return Range.atLeast(c);
  default:
    throw new AssertionError();
  }
}
 
Example 2
Source File: RexSimplify.java    From Bats with Apache License 2.0 6 votes vote down vote up
private static <C extends Comparable<C>> Range<C> range(SqlKind comparison, C c) {
    switch (comparison) {
    case EQUALS:
        return Range.singleton(c);
    case LESS_THAN:
        return Range.lessThan(c);
    case LESS_THAN_OR_EQUAL:
        return Range.atMost(c);
    case GREATER_THAN:
        return Range.greaterThan(c);
    case GREATER_THAN_OR_EQUAL:
        return Range.atLeast(c);
    default:
        throw new AssertionError();
    }
}
 
Example 3
Source File: QueryCardinalityUtil.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public Range<Long> visitAggregation(AggregationNode node, Void context)
{
    if (node.hasEmptyGroupingSet() && node.getGroupingSetCount() == 1) {
        // only single default aggregation which will produce exactly single row
        return Range.singleton(1L);
    }

    Range<Long> sourceCardinalityRange = node.getSource().accept(this, null);

    long lower;
    if (node.hasDefaultOutput() || sourceCardinalityRange.lowerEndpoint() > 0) {
        lower = 1;
    }
    else {
        lower = 0;
    }

    if (sourceCardinalityRange.hasUpperBound()) {
        long upper = Math.max(lower, sourceCardinalityRange.upperEndpoint());
        return Range.closed(lower, upper);
    }

    return Range.atLeast(lower);
}
 
Example 4
Source File: GaussPeak.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see net.sf.mzmine.modules.masslistmethods.shoulderpeaksfilter.peakpicking.twostep.peakmodel.PeakModel#getBasePeakWidth()
 */
public Range<Double> getWidth(double partialIntensity) {

  // The height value must be bigger than zero.
  if (partialIntensity <= 0)
    return Range.atLeast(0.0);

  // Using the Gaussian function we calculate the peak width at intensity
  // given (partialIntensity)

  double portion = partialIntensity / intensityMain;
  double ln = -1 * (double) Math.log(portion);

  double sideRange = (double) (Math.sqrt(part2C2 * ln));

  // This range represents the width of our peak in m/z
  Range<Double> rangePeak = Range.closed(mzMain - sideRange, mzMain + sideRange);

  return rangePeak;
}
 
Example 5
Source File: KeyRangeUtils.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
public static Range makeRange(ByteString startKey, ByteString endKey) {
  if (startKey.isEmpty() && endKey.isEmpty()) {
    return Range.all();
  }
  if (startKey.isEmpty()) {
    return Range.lessThan(Comparables.wrap(endKey));
  } else if (endKey.isEmpty()) {
    return Range.atLeast(Comparables.wrap(startKey));
  }
  return Range.closedOpen(Comparables.wrap(startKey), Comparables.wrap(endKey));
}
 
Example 6
Source File: FilterDefinitionParser.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@MethodParser("kill-streak")
public KillStreakFilter parseKillStreak(Element el) throws InvalidXMLException {
    boolean repeat = XMLUtils.parseBoolean(el.getAttribute("repeat"), false);
    boolean persistent = XMLUtils.parseBoolean(el.getAttribute("persistent"), false);
    Integer count = XMLUtils.parseNumber(el.getAttribute("count"), Integer.class, (Integer) null);
    Integer min = XMLUtils.parseNumber(el.getAttribute("min"), Integer.class, (Integer) null);
    Integer max = XMLUtils.parseNumber(el.getAttribute("max"), Integer.class, (Integer) null);
    Range<Integer> range;

    if(count != null) {
        range = Range.singleton(count);
    } else if(min == null) {
        if(max == null) {
            throw new InvalidXMLException("kill-streak filter must have a count, min, or max", el);
        } else {
            range = Range.atMost(max);
        }
    } else {
        if(max == null) {
            range = Range.atLeast(min);
        } else {
            range = Range.closed(min, max);
        }
    }

    if(repeat && !range.hasUpperBound()) {
        throw new InvalidXMLException("repeating kill-streak filter must have a count or max", el);
    }

    return new KillStreakFilter(range, repeat, persistent);
}
 
Example 7
Source File: MarkerTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test the SplitMarker and WeightedMarker constructors and method addMarker
 */
@Test
public void testAddSubMarker() {
    PeriodicMarker marker = new PeriodicMarker("name", "label", "id", "referenceid", "color", 1.0, "ms", Range.atLeast(0L), 0L, ImmutableRangeSet.of(Range.all()));
    SubMarker subMarkerA = new SplitMarker("A", "a", "a", "color", Range.atLeast(0L), ImmutableRangeSet.of(Range.all()));
    marker.addSubMarker(subMarkerA);
    SubMarker subMarkerB = new WeightedMarker("B");
    marker.addSubMarker(subMarkerB);
    assertEquals(Arrays.asList(subMarkerA, subMarkerB), marker.getSubMarkers());
}
 
Example 8
Source File: RangeHeader.java    From notification with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param builder
 */
private RangeHeader(final Builder builder) {

  this.field = builder.field;

  if (builder.fromId != null && builder.toId != null) {
    if (builder.fromInclusive && builder.toInclusive) {
      range = Range.closed(builder.fromId, builder.toId);
    } else if (builder.fromInclusive && !builder.toInclusive) {
      range = Range.closedOpen(builder.fromId, builder.toId);
    } else if (!builder.fromInclusive && builder.toInclusive) {
      range = Range.openClosed(builder.fromId, builder.toId);
    } else {
      range = Range.open(builder.fromId, builder.toId);
    }
  } else if (builder.fromId != null && builder.toId == null) {
    if (builder.fromInclusive) {
      range = Range.atLeast(builder.fromId);
    } else {
      range = Range.greaterThan(builder.fromId);
    }
  } else if (builder.fromId == null && builder.toId != null) {
    if (builder.toInclusive) {
      range = Range.atMost(builder.toId);
    } else {
      range = Range.lessThan(builder.toId);
    }
  } else {
    range = Range.all();
  }

  this.max = builder.max;
}
 
Example 9
Source File: SpectraVisualizerWindow.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void loadIsotopes(IsotopePattern newPattern) {
  // We need to find a normalization factor for the new isotope
  // pattern, to show meaningful intensity range
  double mz = newPattern.getHighestDataPoint().getMZ();
  Range<Double> searchMZRange = Range.closed(mz - 0.5, mz + 0.5);
  ScanDataSet scanDataSet = spectrumPlot.getMainScanDataSet();
  double normalizationFactor = scanDataSet.getHighestIntensity(searchMZRange);

  // If normalization factor is 0, it means there were no data points
  // in given m/z range. In such case we use the max intensity of
  // whole scan as normalization factor.
  if (normalizationFactor == 0) {
    searchMZRange = Range.atLeast(0.0);
    normalizationFactor = scanDataSet.getHighestIntensity(searchMZRange);
  }

  IsotopePattern normalizedPattern =
      IsotopePatternCalculator.normalizeIsotopePattern(newPattern, normalizationFactor);
  Color newColor;
  if (newPattern.getStatus() == IsotopePatternStatus.DETECTED)
    newColor = detectedIsotopesColor;
  else
    newColor = predictedIsotopesColor;
  IsotopesDataSet newDataSet = new IsotopesDataSet(normalizedPattern);
  spectrumPlot.addDataSet(newDataSet, newColor, true);

}
 
Example 10
Source File: ExtendedLorentzianPeak.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see io.github.mzmine.modules.masslistmethods.shoulderpeaksfilter.peakpicking.twostep.peakmodel.PeakModel#getBasePeakWidth()
 */
public Range<Double> getWidth(double partialIntensity) {

  // The height value must be bigger than zero.
  if (partialIntensity <= 0)
    return Range.atLeast(0.0);

  if (partialIntensity < shoulderIntensity)
    return shoulderPeak.getWidth(partialIntensity);
  else
    return mainPeak.getWidth(partialIntensity);

}
 
Example 11
Source File: ExtendedLorentzianPeak.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see net.sf.mzmine.modules.masslistmethods.shoulderpeaksfilter.peakpicking.twostep.peakmodel.PeakModel#getBasePeakWidth()
 */
public Range<Double> getWidth(double partialIntensity) {

  // The height value must be bigger than zero.
  if (partialIntensity <= 0)
    return Range.atLeast(0.0);

  if (partialIntensity < shoulderIntensity)
    return shoulderPeak.getWidth(partialIntensity);
  else
    return mainPeak.getWidth(partialIntensity);

}
 
Example 12
Source File: SpectraVisualizerWindow.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public void loadIsotopes(IsotopePattern newPattern) {
  // We need to find a normalization factor for the new isotope
  // pattern, to show meaningful intensity range
  double mz = newPattern.getHighestDataPoint().getMZ();
  Range<Double> searchMZRange = Range.closed(mz - 0.5, mz + 0.5);
  ScanDataSet scanDataSet = spectrumPlot.getMainScanDataSet();
  double normalizationFactor = scanDataSet.getHighestIntensity(searchMZRange);

  // If normalization factor is 0, it means there were no data points
  // in given m/z range. In such case we use the max intensity of
  // whole scan as normalization factor.
  if (normalizationFactor == 0) {
    searchMZRange = Range.atLeast(0.0);
    normalizationFactor = scanDataSet.getHighestIntensity(searchMZRange);
  }

  IsotopePattern normalizedPattern =
      IsotopePatternCalculator.normalizeIsotopePattern(newPattern, normalizationFactor);
  Color newColor;
  if (newPattern.getStatus() == IsotopePatternStatus.DETECTED)
    newColor = detectedIsotopesColor;
  else
    newColor = predictedIsotopesColor;
  IsotopesDataSet newDataSet = new IsotopesDataSet(normalizedPattern);
  spectrumPlot.addDataSet(newDataSet, newColor, true);

}
 
Example 13
Source File: TimeRangeShardLocator.java    From das with Apache License 2.0 4 votes vote down vote up
TimeRangeShardLocator(TimeRangeStrategy.TIME_PATTERN timePattern) {
    switch (timePattern){
        case WEEK_OF_YEAR:
            field = Calendar.WEEK_OF_YEAR;
            range = Range.atLeast(1);
            period = DAY * 366L;
            break;
        case WEEK_OF_MONTH:
            field = Calendar.WEEK_OF_MONTH;
            range = Range.atLeast(1);
            period = DAY * 31L;
            break;
        case DAY_OF_MONTH:
            field = Calendar.DAY_OF_MONTH;
            range = Range.atLeast(1);
            period = DAY * 31L;
            break;
        case DAY_OF_YEAR:
            field = Calendar.DAY_OF_YEAR;
            range = Range.atLeast(1);
            period = DAY * 366L;
            break;
        case DAY_OF_WEEK:
            field = Calendar.DAY_OF_WEEK;
            range = Range.closed(1, 7);
            period = DAY * 7;
            break;
        case HOUR_OF_DAY:
            field = Calendar.HOUR_OF_DAY;
            range = Range.closed(0, 23);
            period = DAY;
            break;
        case MINUTE_OF_HOUR:
            field = Calendar.MINUTE;
            range = Range.closed(0, 59);
            period = HOUR;
            break;
        case SECOND_OF_MINUTE:
            field = Calendar.SECOND;
            range = Range.closed(0, 59);
            period = MINUTE;
            break;
    }
}
 
Example 14
Source File: RangeParser.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns a list of {@link Range}s, each indicating a range of byte indices (inclusive).
 *
 * Range: bytes=0-10 (from byte 0 to byte 10)
 * Range: bytes=500-999 (from byte 500 to byte 999)
 * Range: bytes=500- (from byte 500 to the end)
 * Range: bytes=-500 (the last 500 bytes, per the RFC)
 *
 * @return {@code null} if the requested range cannot be satisfied given the size of the content, or an empty list in
 * the case of parsing errors
 */
public List<Range<Long>> parseRangeSpec(final String rangeHeader, long size) {
  Range<Long> content = Range.closed(0L, size - 1L);

  // TODO: Current limitation: only one Range of bytes supported in forms of "-X", "X-Y" (where X<Y) and "X-".
  if (!Strings.isNullOrEmpty(rangeHeader)) {
    try {
      if (rangeHeader.startsWith("bytes=") && rangeHeader.length() > 6 && !rangeHeader.contains(",")) {
        final String rangeSpec = rangeHeader.substring(6, rangeHeader.length());
        if (rangeSpec.startsWith("-")) {
          final long byteCount = Long.parseLong(rangeSpec.substring(1));
          if (byteCount > size) {
            return UNSATISFIABLE;
          }
          final Range<Long> suffix = Range.atLeast(size - byteCount);
          return ensureSatisfiable(suffix, content);
        }
        else if (rangeSpec.endsWith("-")) {
          final Range<Long> requested = Range.atLeast(Long.parseLong(rangeSpec.substring(0, rangeSpec.length() - 1)));
          return ensureSatisfiable(requested, content);
        }
        else if (rangeSpec.contains("-")) {
          final String[] parts = rangeSpec.split("-");
          return ensureSatisfiable(Range.closed(Long.parseLong(parts[0]), Long.parseLong(parts[1])), content);
        }
        else {
          log.warn("Malformed HTTP Range value: {}, ignoring it", rangeHeader);
        }
      }
      else {
        log.warn("Unsupported non-byte or multiple HTTP Ranges: {}; sending complete content", rangeHeader);
      }
    }
    catch (Exception e) {
      if (log.isDebugEnabled()) {
        log.debug("Problem parsing Range value: {}, ignoring", rangeHeader, e);
      }
      else {
        log.warn("Problem parsing Range value: {}, ignoring: {}", rangeHeader, e.toString());
      }
    }
  }

  return WHOLE_RANGE;
}
 
Example 15
Source File: DataPointSearchCriteriaBuilder.java    From omh-dsu-ri with Apache License 2.0 4 votes vote down vote up
public DataPointSearchCriteriaBuilder setCreationTimestampLowerEndpoint(OffsetDateTime lowerEndpoint) {
    this.creationTimestampLowerEndpoint = lowerEndpoint != null ? Range.atLeast(lowerEndpoint) : Range.all();
    return this;
}
 
Example 16
Source File: Version.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
public static Range<Version> createRangeOf(final Version from, final Version to) {
    if (from == null || Version.NULL.equals(from)) {
        return to == null || Version.NULL.equals(to) ? Range.all() : Range.atMost(to);
    }
    return to == null || Version.NULL.equals(to) ? Range.atLeast(from) : Range.closed(from, to);
}
 
Example 17
Source File: IntegerValidator.java    From yfiton with Apache License 2.0 4 votes vote down vote up
public IntegerValidator(int minValue) {
    this.range = Range.atLeast(minValue);
}
 
Example 18
Source File: RepeatMatcherMatchTest.java    From grappa with Apache License 2.0 4 votes vote down vote up
@DataProvider
public Iterator<Object[]> getInput1MatchData()
{
    final List<Object[]> list = Lists.newArrayList();

    Range<Integer> range;
    int index;
    boolean match;

    range = Range.singleton(3);
    index = 6;
    match = true;
    list.add(new Object[] { range, index, match });

    range = Range.singleton(6);
    index = 10;
    match = false;
    list.add(new Object[] { range, index, match });

    range = Range.atMost(4);
    index = 8;
    match = true;
    list.add(new Object[] { range, index, match });

    range = Range.atLeast(2);
    index = 10;
    match = true;
    list.add(new Object[] { range, index, match });

    range = Range.closed(2, 9);
    index = 10;
    match = true;
    list.add(new Object[] { range, index, match });

    range = Range.closed(2, 4);
    index = 8;
    match = true;
    list.add(new Object[] { range, index, match });

    return list.iterator();
}
 
Example 19
Source File: TsConditionExtractor.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
private static Range<Long> extractTsConditionInternal(TupleFilter filter, TblColRef colRef) {
    if (filter == null) {
        return Range.all();
    }

    if (filter instanceof LogicalTupleFilter) {
        if (filter.getOperator() == TupleFilter.FilterOperatorEnum.AND) {
            Range<Long> ret = Range.all();
            for (TupleFilter child : filter.getChildren()) {
                Range childRange = extractTsConditionInternal(child, colRef);
                if (childRange != null) {
                    if (ret.isConnected(childRange) && !ret.intersection(childRange).isEmpty()) {
                        ret = ret.intersection(childRange);
                    } else {
                        return null;
                    }
                } else {
                    return null;
                }
            }
            return ret.isEmpty() ? null : ret;
        } else {
            //for conditions like date > DATE'2000-11-11' OR date < DATE '1999-01-01'
            //we will use Ranges.all() rather than two ranges to represent them
            return Range.all();
        }
    }

    if (filter instanceof CompareTupleFilter) {
        CompareTupleFilter compareTupleFilter = (CompareTupleFilter) filter;
        if (compareTupleFilter.getColumn() == null)// column will be null at filters like " 1<>1"
            return Range.all();

        if (compareTupleFilter.getColumn().equals(colRef)) {
            Object firstValue = compareTupleFilter.getFirstValue();
            long t;
            switch (compareTupleFilter.getOperator()) {
            case EQ:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.closed(t, t);
            case LT:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.lessThan(t);
            case LTE:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.atMost(t);
            case GT:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.greaterThan(t);
            case GTE:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.atLeast(t);
            case NEQ:
            case IN://not handled for now
                break;
            default:
            }
        }
    }
    return Range.all();
}
 
Example 20
Source File: ScreenDensitySelector.java    From bundletool with Apache License 2.0 4 votes vote down vote up
/**
 * For a given range of devices dpi served by a split, returns the range of resources that are
 * reachable from this split.
 *
 * <p>The reachable resources can cover a be different dpi range than that of the devices since a
 * resource with dpi smaller than the lowest dpi device can be still preferred by that device.
 *
 * @param deviceDpiRange range of device dpis to serve by a given split
 * @param values {@link ConfigValue} objects of a resource under consideration
 * @return range of resource config values that can be matched by any device served by the split
 */
@CheckReturnValue
private ImmutableList<ConfigValue> getReachableConfigValues(
    Range<Integer> deviceDpiRange, ImmutableList<ConfigValue> values, Version bundleVersion) {
  // We are calculating the lowest and highest dpi of the resource that could be matched by the
  // devices from the given deviceDpiRange.
  // We take the lowest eligible dpi device and find the best matching resource for it, similarly
  // at the other end of the servedDpiRange. Because the best matching is monotonic, all resource
  // configs between those extremes and no others could be matched by any device that falls into
  // that dpi range.

  Optional<Integer> lowestResourceDpi = Optional.empty();
  Optional<Integer> highestResourceDpi = Optional.empty();
  if (deviceDpiRange.hasLowerBound()) {
    lowestResourceDpi =
        Optional.of(
            selectBestConfigValue(values, deviceDpiRange.lowerEndpoint(), bundleVersion)
                .getConfig()
                .getDensity());
  }
  if (deviceDpiRange.hasUpperBound()) {
    highestResourceDpi =
        Optional.of(
            selectBestConfigValue(values, deviceDpiRange.upperEndpoint(), bundleVersion)
                .getConfig()
                .getDensity());
  }

  Range<Integer> effectiveDpiRange;

  if (deviceDpiRange.equals(Range.all())) {
    effectiveDpiRange = Range.all();
  } else if (!lowestResourceDpi.isPresent()) {
    effectiveDpiRange = Range.atMost(highestResourceDpi.get());
  } else if (!highestResourceDpi.isPresent()) {
    effectiveDpiRange = Range.atLeast(lowestResourceDpi.get());
  } else {
    effectiveDpiRange = Range.closed(lowestResourceDpi.get(), highestResourceDpi.get());
  }

  return values.stream()
      .filter(configValue -> effectiveDpiRange.contains(configValue.getConfig().getDensity()))
      .collect(toImmutableList());
}