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

The following examples show how to use com.google.common.collect.Range#all() . 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: DataPointSearchController.java    From shimmer with Apache License 2.0 6 votes vote down vote up
public Range<OffsetDateTime> asRange(OffsetDateTime onOrAfterDateTime, OffsetDateTime beforeDateTime) {

        if (onOrAfterDateTime != null && beforeDateTime != null) {
            return Range.closedOpen(onOrAfterDateTime, beforeDateTime);
        }

        if (onOrAfterDateTime != null) {
            return Range.atLeast(onOrAfterDateTime);
        }

        else if (beforeDateTime != null) {
            return Range.lessThan(beforeDateTime);
        }

        return Range.all();
    }
 
Example 2
Source File: ScreenDensitySelector.java    From bundletool with Apache License 2.0 6 votes vote down vote up
private Range<Integer> getDpiRange(int targetDpi, ImmutableSet<Integer> alternatives) {
  if (alternatives.isEmpty()) {
    return Range.all();
  }

  Optional<Integer> lowMidPoint =
      getNearestLowerDpi(targetDpi, alternatives)
          .map(lowerDpi -> getMidPoint(lowerDpi, targetDpi))
          .map(val -> (int) Math.ceil(val));
  Optional<Integer> highMidPoint =
      getNearestHigherDpi(targetDpi, alternatives)
          .map(higherDpi -> getMidPoint(targetDpi, higherDpi))
          .map(val -> (int) Math.floor(val));

  if (!lowMidPoint.isPresent()) {
    return Range.atMost(highMidPoint.get());
  }
  if (!highMidPoint.isPresent()) {
    return Range.atLeast(lowMidPoint.get());
  }
  return Range.closed(lowMidPoint.get(), highMidPoint.get());
}
 
Example 3
Source File: RawDataFileImpl.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see io.github.mzmine.datamodel.RawDataFile#getScanNumbers(int)
 */
@Override
public @Nonnull int[] getScanNumbers(int msLevel) {
  if (scanNumbersCache.containsKey(msLevel))
    return scanNumbersCache.get(msLevel);
  Range<Double> all = Range.all();
  int scanNumbers[] = getScanNumbers(msLevel, all);
  scanNumbersCache.put(msLevel, scanNumbers);
  return scanNumbers;
}
 
Example 4
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 5
Source File: RexSimplify.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Weakens a term so that it checks only what is not implied by predicates.
 *
 * <p>The term is broken into "ref comparison constant",
 * for example "$0 &lt; 5".
 *
 * <p>Examples:
 * <ul>
 *
 * <li>{@code residue($0 < 10, [$0 < 5])} returns {@code true}
 *
 * <li>{@code residue($0 < 10, [$0 < 20, $0 > 0])} returns {@code $0 < 10}
 * </ul>
 */
private <C extends Comparable<C>> Range<C> residue(RexNode ref, Range<C> r0,
    List<RexNode> predicates, Class<C> clazz) {
  Range<C> result = r0;
  for (RexNode predicate : predicates) {
    switch (predicate.getKind()) {
    case EQUALS:
    case LESS_THAN:
    case LESS_THAN_OR_EQUAL:
    case GREATER_THAN:
    case GREATER_THAN_OR_EQUAL:
      final RexCall call = (RexCall) predicate;
      if (call.operands.get(0).equals(ref)
          && call.operands.get(1) instanceof RexLiteral) {
        final RexLiteral literal = (RexLiteral) call.operands.get(1);
        final C c1 = literal.getValueAs(clazz);
        final Range<C> r1 = range(predicate.getKind(), c1);
        if (result.encloses(r1)) {
          // Given these predicates, term is always satisfied.
          // e.g. r0 is "$0 < 10", r1 is "$0 < 5"
          result = Range.all();
          continue;
        }
        if (result.isConnected(r1)) {
          result = result.intersection(r1);
          continue;
        }
        // Ranges do not intersect. Return null meaning the empty range.
        return null;
      }
    }
  }
  return result;
}
 
Example 6
Source File: DependencyGraph.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean refresh() {
  GPCalendarCalc calendar = myDstNode.myTask.getManager().getCalendar();
  TaskDependencyConstraint.Collision nextCollision = myDep.getConstraint().getCollision();
  Date acceptableStart = nextCollision.getAcceptableStart().getTime();
  isWeak = !nextCollision.isActive() && myDep.getHardness() == Hardness.RUBBER;
  switch (nextCollision.getVariation()) {
  case TaskDependencyConstraint.Collision.START_EARLIER_VARIATION:
    if (0 == (calendar.getDayMask(acceptableStart) & DayMask.WORKING)) {
      acceptableStart = calendar.findClosest(acceptableStart, myDstNode.myTask.getDuration().getTimeUnit(),
          GPCalendarCalc.MoveDirection.BACKWARD, GPCalendar.DayType.WORKING);
    }
    myStartRange = Range.upTo(acceptableStart, BoundType.CLOSED);
    break;
  case TaskDependencyConstraint.Collision.START_LATER_VARIATION:
    if (0 == (calendar.getDayMask(acceptableStart) & DayMask.WORKING)) {
      acceptableStart = calendar.findClosest(acceptableStart, myDstNode.myTask.getDuration().getTimeUnit(),
          GPCalendarCalc.MoveDirection.FORWARD, GPCalendar.DayType.WORKING);
    }
    myStartRange = Range.downTo(acceptableStart, BoundType.CLOSED);
    break;
  case TaskDependencyConstraint.Collision.NO_VARIATION:
    myStartRange = Range.singleton(acceptableStart);
    break;
  }
  myEndRange = Range.all();
  return true;
}
 
Example 7
Source File: RangeTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void extremeCase() {
    Range r1 = Range.all();
    Range r2 = Range.all();

    Range a = Range.closedOpen(2, 5);

    Assert.assertTrue(RangeUtil.remove(r1, r2).equals(Lists.newArrayList()));
    Assert.assertTrue(RangeUtil.remove(r1, a).equals(Lists.newArrayList(Range.lessThan(2), Range.atLeast(5))));
}
 
Example 8
Source File: RangeFactory.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
public static <C extends Comparable<?>> Range<C> all()
{
    return Range.all();
}
 
Example 9
Source File: SymbolTable.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
private static ScopedRegion forModule(Module m) {
  return new AutoValue_SymbolTable_ScopedRegion(
      m.getPath().toString(), Range.all(), m.getInternalSymbolTable());
}
 
Example 10
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());
}
 
Example 11
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 12
Source File: TypedReflections.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Range<Version> load(final Method key)  {
    final TypedColumn typedColumn = key.getAnnotation(TypedColumn.class);
    return typedColumn == null ? Range.all()
            : createVersionRange(typedColumn.fromVersion(), typedColumn.untilVersion());
}
 
Example 13
Source File: SimplePeakList.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see io.github.mzmine.datamodel.PeakList#getPeaksInsideMZRange(double, double)
 */
@Override
public Feature[] getPeaksInsideMZRange(RawDataFile file, Range<Double> mzRange) {
  Range<Double> all = Range.all();
  return getPeaksInsideScanAndMZRange(file, all, mzRange);
}
 
Example 14
Source File: DataPointSearchCriteriaBuilder.java    From omh-dsu-ri with Apache License 2.0 4 votes vote down vote up
public DataPointSearchCriteriaBuilder setCreationTimestampUpperEndpoint(OffsetDateTime upperEndpoint) {
    this.creationTimestampUpperEndpoint = upperEndpoint != null ? Range.atMost(upperEndpoint) : Range.all();
    return this;
}
 
Example 15
Source File: SchedulerImpl.java    From ganttproject with GNU General Public License v3.0 4 votes vote down vote up
private void schedule(Node node) {
  Logger logger = GPLogger.getLogger(this);
  GPLogger.debug(logger, "Scheduling node %s", node);
  Range<Date> startRange = Range.all();
  Range<Date> endRange = Range.all();

  Range<Date> weakStartRange = Range.all();
  Range<Date> weakEndRange = Range.all();

  List<Date> subtaskRanges = Lists.newArrayList();
  List<DependencyEdge> incoming = node.getIncoming();
  GPLogger.debug(logger, ".. #incoming edges=%d", incoming.size());
  for (DependencyEdge edge : incoming) {
    if (!edge.refresh()) {
      continue;
    }
    if (edge instanceof ImplicitSubSuperTaskDependency) {
      subtaskRanges.add(edge.getStartRange().upperEndpoint());
      subtaskRanges.add(edge.getEndRange().lowerEndpoint());
    } else {
      if (edge.isWeak()) {
        weakStartRange = weakStartRange.intersection(edge.getStartRange());
        weakEndRange = weakEndRange.intersection(edge.getEndRange());
      } else {
        startRange = startRange.intersection(edge.getStartRange());
        endRange = endRange.intersection(edge.getEndRange());
      }
    }
    if (startRange.isEmpty() || endRange.isEmpty()) {
      GPLogger.logToLogger("both start and end ranges were calculated as empty for task=" + node.getTask() + ". Skipping it");
    }
  }
  GPLogger.debug(logger, "..Ranges: start=%s end=%s weakStart=%s weakEnd=%s", startRange, endRange, weakStartRange, weakEndRange);

  Range<Date> subtasksSpan = subtaskRanges.isEmpty() ?
      Range.closed(node.getTask().getStart().getTime(), node.getTask().getEnd().getTime()) : Range.encloseAll(subtaskRanges);
  Range<Date> subtreeStartUpwards = subtasksSpan.span(Range.downTo(node.getTask().getStart().getTime(), BoundType.CLOSED));
  Range<Date> subtreeEndDownwards = subtasksSpan.span(Range.upTo(node.getTask().getEnd().getTime(), BoundType.CLOSED));
  GPLogger.debug(logger, "..Subtasks span=%s", subtasksSpan);

  if (!startRange.equals(Range.all())) {
    startRange = startRange.intersection(weakStartRange);
  } else if (!weakStartRange.equals(Range.all())) {
    startRange = weakStartRange.intersection(subtreeStartUpwards);
  }
  if (!endRange.equals(Range.all())) {
    endRange = endRange.intersection(weakEndRange);
  } else if (!weakEndRange.equals(Range.all())) {
    endRange = weakEndRange.intersection(subtreeEndDownwards);
  }
  if (node.getTask().getThirdDateConstraint() == TaskImpl.EARLIESTBEGIN && node.getTask().getThird() != null) {
    startRange = startRange.intersection(Range.downTo(node.getTask().getThird().getTime(), BoundType.CLOSED));
    GPLogger.debug(logger, ".. applying earliest start=%s. Now start range=%s", node.getTask().getThird(), startRange);
  }
  if (!subtaskRanges.isEmpty()) {
    startRange = startRange.intersection(subtasksSpan);
    endRange = endRange.intersection(subtasksSpan);
  }
  GPLogger.debug(logger, ".. finally, start range=%s", startRange);
  if (startRange.hasLowerBound()) {
    modifyTaskStart(node.getTask(), startRange.lowerEndpoint());
  }
  if (endRange.hasUpperBound()) {
    GPCalendarCalc cal = node.getTask().getManager().getCalendar();
    Date endDate = endRange.upperEndpoint();
    TimeUnit timeUnit = node.getTask().getDuration().getTimeUnit();
    if (DayMask.WORKING == (cal.getDayMask(endDate) & DayMask.WORKING)) {
      // in case if calculated end date falls on first day after holidays (say, on Monday)
      // we'll want to modify it a little bit, so that it falls on that holidays start
      // If we don't do this, it will be done automatically the next time task activities are recalculated,
      // and thus task end date will keep changing
      Date closestWorkingEndDate = cal.findClosest(
          endDate, timeUnit, GPCalendarCalc.MoveDirection.BACKWARD, GPCalendar.DayType.WORKING);
      Date closestNonWorkingEndDate = cal.findClosest(
          endDate, timeUnit, GPCalendarCalc.MoveDirection.BACKWARD, GPCalendar.DayType.NON_WORKING, closestWorkingEndDate);
      // If there is a non-working date between current task end and closest working date
      // then we're really just after holidays
      if (closestNonWorkingEndDate != null && closestWorkingEndDate.before(closestNonWorkingEndDate)) {
        // we need to adjust-right closest working date to position to the very beginning of the holidays interval
        Date nonWorkingPeriodStart = timeUnit.adjustRight(closestWorkingEndDate);
        if (nonWorkingPeriodStart.after(node.getTask().getStart().getTime())) {
          endDate = nonWorkingPeriodStart;
        }
      }
    }
    modifyTaskEnd(node.getTask(), endDate);
  }
}
 
Example 16
Source File: SimplePeakList.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public PeakListRow[] getRowsInsideMZRange(Range<Double> mzRange) {
  Range<Double> all = Range.all();
  return getRowsInsideScanAndMZRange(all, mzRange);
}
 
Example 17
Source File: ModularFeatureList.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<ModularFeatureListRow> getRowsInsideScanRange(Range<Float> rtRange) {
  Range<Double> all = Range.all();
  return getRowsInsideScanAndMZRange(rtRange, all);
}
 
Example 18
Source File: PeptideScan.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public @Nonnull Range<Double> getScanningMZRange() {
  // TODO Auto-generated method stub
  return Range.all();
}
 
Example 19
Source File: ModularFeatureList.java    From mzmine3 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns all peaks overlapping with a retention time range
 * 
 * @param startRT Start of the retention time range
 * @param endRT End of the retention time range
 * @return
 */
@Override
public List<ModularFeature> getPeaksInsideScanRange(RawDataFile raw, Range<Float> rtRange) {
  Range<Double> all = Range.all();
  return getPeaksInsideScanAndMZRange(raw, rtRange, all);
}
 
Example 20
Source File: SimplePeakList.java    From mzmine2 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns all peaks overlapping with a retention time range
 * 
 * @param startRT Start of the retention time range
 * @param endRT End of the retention time range
 * @return
 */
@Override
public Feature[] getPeaksInsideScanRange(RawDataFile file, Range<Double> rtRange) {
  Range<Double> all = Range.all();
  return getPeaksInsideScanAndMZRange(file, rtRange, all);
}