List of usage examples for com.google.common.collect Range atLeast
public static <C extends Comparable<?>> Range<C> atLeast(C endpoint)
From source file:org.nmdp.ngs.fca.Interval.java
/** * Construct an interval with specified dimension and values. * @param dimension as specified (at least zero) * @param range as specified (cannot be null) *///from www. ja va2 s . c o m public Interval(int dimension, final Range<C> range) { checkArgument(Range.atLeast(0).contains(dimension)); checkNotNull(range); this.dimension = dimension; this.range = range; }
From source file:net.hydromatic.foodbench.Main.java
private static RangeSet<Integer> parseInts(String idsProperty) { RangeSet<Integer> idSet = TreeRangeSet.create(); if (idsProperty == null) { idsProperty = ""; }// ww w.j a va 2s . c o m if (idsProperty.isEmpty() || idsProperty.startsWith("-")) { idSet.add(Range.<Integer>all()); } if (!idsProperty.isEmpty()) { for (String id : idsProperty.split(",")) { String[] split2 = id.split("-"); if (split2.length != 2) { if (id.endsWith("-")) { // 10- means "10 onwards" idSet.add(Range.atLeast(Integer.parseInt(id.substring(0, id.length() - 1)))); } else { idSet.add(Range.singleton(Integer.parseInt(id))); } } else if (split2[0].equals("")) { // -10 means "not 10" idSet.remove(Range.singleton(Integer.parseInt(split2[1]))); } else { int min = Integer.parseInt(split2[0]); int max = Integer.parseInt(split2[1]); idSet.add(Range.closed(min, max)); } } } return idSet; }
From source file:com.github.rinde.rinsim.scenario.generator.TimeSeries.java
/** * Creates a {@link TimeSeriesGenerator} using a uniform distribution for the * inter arrival times of events. The spread of the uniform distribution is * defined by the <code>maxDeviation</code> {@link StochasticSupplier}, this * means that each time a time series is generated a different max deviation * settings is used.//from w w w . j av a 2 s . co m * @param length The length of the time series, all generated times will be in * the interval [0,length). * @param numEvents The total number of events in the time series (on * average). * @param maxDeviation A supplier that is used for max deviation values. * @return A {@link TimeSeriesGenerator} based on a uniform distribution, each * time series that is generated has a different max deviation drawn * from the supplier. */ public static TimeSeriesGenerator uniform(double length, int numEvents, StochasticSupplier<Double> maxDeviation) { checkArgument(length > 0d); checkArgument(numEvents > 0); final double average = length / numEvents; return new UniformTimeSeries(length, average, StochasticSuppliers.checked(maxDeviation, Range.atLeast(0d))); }
From source file:org.apache.calcite.adapter.druid.DruidDateTimeUtils.java
protected static List<Range<Calendar>> leafToRanges(RexCall call, boolean withNot) { switch (call.getKind()) { case EQUALS:/*from www . ja v a 2 s .c o m*/ case LESS_THAN: case LESS_THAN_OR_EQUAL: case GREATER_THAN: case GREATER_THAN_OR_EQUAL: { final Calendar value; if (call.getOperands().get(0) instanceof RexInputRef && literalValue(call.getOperands().get(1)) != null) { value = literalValue(call.getOperands().get(1)); } else if (call.getOperands().get(1) instanceof RexInputRef && literalValue(call.getOperands().get(0)) != null) { value = literalValue(call.getOperands().get(0)); } else { return null; } switch (call.getKind()) { case LESS_THAN: return ImmutableList.of(withNot ? Range.atLeast(value) : Range.lessThan(value)); case LESS_THAN_OR_EQUAL: return ImmutableList.of(withNot ? Range.greaterThan(value) : Range.atMost(value)); case GREATER_THAN: return ImmutableList.of(withNot ? Range.atMost(value) : Range.greaterThan(value)); case GREATER_THAN_OR_EQUAL: return ImmutableList.of(withNot ? Range.lessThan(value) : Range.atLeast(value)); default: if (!withNot) { return ImmutableList.of(Range.closed(value, value)); } return ImmutableList.of(Range.lessThan(value), Range.greaterThan(value)); } } case BETWEEN: { final Calendar value1; final Calendar value2; if (literalValue(call.getOperands().get(2)) != null && literalValue(call.getOperands().get(3)) != null) { value1 = literalValue(call.getOperands().get(2)); value2 = literalValue(call.getOperands().get(3)); } else { return null; } boolean inverted = value1.compareTo(value2) > 0; if (!withNot) { return ImmutableList.of(inverted ? Range.closed(value2, value1) : Range.closed(value1, value2)); } return ImmutableList.of(Range.lessThan(inverted ? value2 : value1), Range.greaterThan(inverted ? value1 : value2)); } case IN: { ImmutableList.Builder<Range<Calendar>> ranges = ImmutableList.builder(); for (RexNode operand : Util.skip(call.operands)) { final Calendar element = literalValue(operand); if (element == null) { return null; } if (withNot) { ranges.add(Range.lessThan(element)); ranges.add(Range.greaterThan(element)); } else { ranges.add(Range.closed(element, element)); } } return ranges.build(); } default: return null; } }
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.druid.DruidIntervalUtils.java
protected static List<Range> leafToRanges(RelDataType type, RexCall call, boolean withNot) { switch (call.getKind()) { case EQUALS://from w ww .j a va 2s . c om case LESS_THAN: case LESS_THAN_OR_EQUAL: case GREATER_THAN: case GREATER_THAN_OR_EQUAL: { RexLiteral literal = null; if (call.getOperands().get(0) instanceof RexInputRef && call.getOperands().get(1) instanceof RexLiteral) { literal = extractLiteral(call.getOperands().get(1)); } else if (call.getOperands().get(0) instanceof RexInputRef && call.getOperands().get(1).getKind() == SqlKind.CAST) { literal = extractLiteral(call.getOperands().get(1)); } else if (call.getOperands().get(1) instanceof RexInputRef && call.getOperands().get(0) instanceof RexLiteral) { literal = extractLiteral(call.getOperands().get(0)); } else if (call.getOperands().get(1) instanceof RexInputRef && call.getOperands().get(0).getKind() == SqlKind.CAST) { literal = extractLiteral(call.getOperands().get(0)); } if (literal == null) { return null; } Comparable value = literalToType(literal, type); if (value == null) { return null; } if (call.getKind() == SqlKind.LESS_THAN) { return Arrays.<Range>asList(withNot ? Range.atLeast(value) : Range.lessThan(value)); } else if (call.getKind() == SqlKind.LESS_THAN_OR_EQUAL) { return Arrays.<Range>asList(withNot ? Range.greaterThan(value) : Range.atMost(value)); } else if (call.getKind() == SqlKind.GREATER_THAN) { return Arrays.<Range>asList(withNot ? Range.atMost(value) : Range.greaterThan(value)); } else if (call.getKind() == SqlKind.GREATER_THAN_OR_EQUAL) { return Arrays.<Range>asList(withNot ? Range.lessThan(value) : Range.atLeast(value)); } else { //EQUALS if (!withNot) { return Arrays.<Range>asList(Range.closed(value, value)); } return Arrays.<Range>asList(Range.lessThan(value), Range.greaterThan(value)); } } case BETWEEN: { RexLiteral literal1 = extractLiteral(call.getOperands().get(2)); if (literal1 == null) { return null; } RexLiteral literal2 = extractLiteral(call.getOperands().get(3)); if (literal2 == null) { return null; } Comparable value1 = literalToType(literal1, type); Comparable value2 = literalToType(literal2, type); if (value1 == null || value2 == null) { return null; } boolean inverted = value1.compareTo(value2) > 0; if (!withNot) { return Arrays.<Range>asList(inverted ? Range.closed(value2, value1) : Range.closed(value1, value2)); } return Arrays.<Range>asList(Range.lessThan(inverted ? value2 : value1), Range.greaterThan(inverted ? value1 : value2)); } case IN: { List<Range> ranges = Lists.newArrayList(); for (int i = 1; i < call.getOperands().size(); i++) { RexLiteral literal = extractLiteral(call.getOperands().get(i)); if (literal == null) { return null; } Comparable element = literalToType(literal, type); if (element == null) { return null; } if (withNot) { ranges.addAll(Arrays.<Range>asList(Range.lessThan(element), Range.greaterThan(element))); } else { ranges.add(Range.closed(element, element)); } } return ranges; } default: return null; } }
From source file:org.openmhealth.shimmer.common.controller.DataPointSearchController.java
public Range<OffsetDateTime> asRange(OffsetDateTime onOrAfterDateTime, OffsetDateTime beforeDateTime) { if (onOrAfterDateTime != null && beforeDateTime != null) { return Range.closedOpen(onOrAfterDateTime, beforeDateTime); }/*from w w w.j a v a 2 s . co m*/ if (onOrAfterDateTime != null) { return Range.atLeast(onOrAfterDateTime); } else if (beforeDateTime != null) { return Range.lessThan(beforeDateTime); } return Range.all(); }
From source file:org.openmhealth.dsu.controller.DataPointController.java
/** * Reads data points./*from w w w. j a va2 s . co m*/ * * @param schemaNamespace the namespace of the schema the data points conform to * @param schemaName the name of the schema the data points conform to * @param schemaVersion the version of the schema the data points conform to * @param createdOnOrAfter the earliest creation timestamp of the data points to return, inclusive * @param createdBefore the latest creation timestamp of the data points to return, exclusive * @param offset the number of data points to skip * @param limit the number of data points to return * @return a list of matching data points */ // TODO confirm if HEAD handling needs anything additional // only allow clients with read scope to read data points @PreAuthorize("#oauth2.clientHasRole('" + CLIENT_ROLE + "') and #oauth2.hasScope('" + DATA_POINT_READ_SCOPE + "')") // TODO look into any meaningful @PostAuthorize filtering @RequestMapping(value = "/dataPoints", method = { HEAD, GET }, produces = APPLICATION_JSON_VALUE) public @ResponseBody ResponseEntity<Iterable<DataPoint>> readDataPoints( @RequestParam(value = SCHEMA_NAMESPACE_PARAMETER) final String schemaNamespace, @RequestParam(value = SCHEMA_NAME_PARAMETER) final String schemaName, // TODO make this optional and update all associated code @RequestParam(value = SCHEMA_VERSION_PARAMETER) final String schemaVersion, // TODO replace with Optional<> in Spring MVC 4.1 @RequestParam(value = CREATED_ON_OR_AFTER_PARAMETER, required = false) final OffsetDateTime createdOnOrAfter, @RequestParam(value = CREATED_BEFORE_PARAMETER, required = false) final OffsetDateTime createdBefore, @RequestParam(value = RESULT_OFFSET_PARAMETER, defaultValue = "0") final Integer offset, @RequestParam(value = RESULT_LIMIT_PARAMETER, defaultValue = DEFAULT_RESULT_LIMIT) final Integer limit, Authentication authentication) { // TODO add validation or explicitly comment that this is handled using exception translators // determine the user associated with the access token to restrict the search accordingly String endUserId = getEndUserId(authentication); DataPointSearchCriteria searchCriteria = new DataPointSearchCriteria(endUserId, schemaNamespace, schemaName, schemaVersion); if (createdOnOrAfter != null && createdBefore != null) { searchCriteria.setCreationTimestampRange(Range.closedOpen(createdOnOrAfter, createdBefore)); } else if (createdOnOrAfter != null) { searchCriteria.setCreationTimestampRange(Range.atLeast(createdOnOrAfter)); } else if (createdBefore != null) { searchCriteria.setCreationTimestampRange(Range.lessThan(createdBefore)); } Iterable<DataPoint> dataPoints = dataPointService.findBySearchCriteria(searchCriteria, offset, limit); HttpHeaders headers = new HttpHeaders(); // FIXME add pagination headers // headers.set("Next"); // headers.set("Previous"); return new ResponseEntity<>(dataPoints, headers, OK); }
From source file:org.kiji.schema.impl.cassandra.CassandraKijiPartition.java
/** * Convert a set of (start-token, host) pairs into a set of (token-range, host) pairs. * * Package private for testing.//from www . j av a 2 s. c o m * * @param startTokens The set of start tokens with hosts. * @return The token corresponding token ranges. */ static Map<Range<Long>, InetAddress> getTokenRanges(final SortedMap<Long, InetAddress> startTokens) { ImmutableMap.Builder<Range<Long>, InetAddress> tokenRangesBldr = ImmutableMap.builder(); final PeekingIterator<Entry<Long, InetAddress>> startTokensItr = Iterators .peekingIterator(startTokens.entrySet().iterator()); // Add a range for [-, firstStartToken) owned by the final key (the wrap-around range). // For more information on Casandra VNode token ranges: // http://www.datastax.com/dev/blog/virtual-nodes-in-cassandra-1-2 tokenRangesBldr.put(Range.lessThan(startTokens.firstKey()), startTokens.get(startTokens.lastKey())); while (startTokensItr.hasNext()) { Entry<Long, InetAddress> startToken = startTokensItr.next(); if (!startTokensItr.hasNext()) { // The final start token // Add a range for [lastStartToken, ) tokenRangesBldr.put(Range.atLeast(startToken.getKey()), startToken.getValue()); } else { // Add a range for [thisStartToken, nextStartToken) tokenRangesBldr.put(Range.closedOpen(startToken.getKey(), startTokensItr.peek().getKey()), startToken.getValue()); } } final Map<Range<Long>, InetAddress> tokenRanges = tokenRangesBldr.build(); // Check that the returned ranges are coherent; most importantly that all possible tokens fall // within the returned range set. if (startTokens.size() + 1 != tokenRanges.size()) { throw new InternalKijiError( String.format("Unexpected number of token ranges. start-tokens: %s, token-ranges: %s.", startTokens.size(), tokenRanges.size())); } final RangeSet<Long> ranges = TreeRangeSet.create(); for (Range<Long> tokenRange : tokenRanges.keySet()) { ranges.add(tokenRange); } if (!ranges.encloses(Range.closed(Long.MIN_VALUE, Long.MAX_VALUE))) { throw new InternalKijiError("Token range does not include all possible tokens."); } return tokenRanges; }
From source file:com.github.fge.grappa.matchers.join.JoinMatcherBuilder.java
private static Range<Integer> toClosedRange(Range<Integer> range) { /*//from w w w . j a va2 s . co m * The canonical form will always be the same: closed on the lower bound * (if any; but here we are guaranteed that), open on the upper bound * (if any). * * All we have to do is therefore to pick the canonical representation, * pick the lower bound, and if it has an upper bound, pick it and * substract 1. */ Range<Integer> canonical = range.canonical(DiscreteDomain.integers()); int lowerBound = canonical.lowerEndpoint(); return canonical.hasUpperBound() ? Range.closed(lowerBound, canonical.upperEndpoint() - 1) : Range.atLeast(lowerBound); }
From source file:org.apache.druid.query.filter.BoundDimFilter.java
@Override public RangeSet<String> getDimensionRangeSet(String dimension) { if (!(Objects.equals(getDimension(), dimension) && getExtractionFn() == null && ordering.equals(StringComparators.LEXICOGRAPHIC))) { return null; }//from w w w . j av a 2s . com RangeSet<String> retSet = TreeRangeSet.create(); Range<String> range; if (getLower() == null) { range = isUpperStrict() ? Range.lessThan(getUpper()) : Range.atMost(getUpper()); } else if (getUpper() == null) { range = isLowerStrict() ? Range.greaterThan(getLower()) : Range.atLeast(getLower()); } else { range = Range.range(getLower(), isLowerStrict() ? BoundType.OPEN : BoundType.CLOSED, getUpper(), isUpperStrict() ? BoundType.OPEN : BoundType.CLOSED); } retSet.add(range); return retSet; }