List of usage examples for com.google.common.collect Range lowerEndpoint
public C lowerEndpoint()
From source file:org.pascani.dsl.dbmapper.databases.CSVExport.java
private Map<String, String> toData(String collection, ChangeEvent e, Serializable value, Map<String, String> tags) { for (String tag : tags.keySet()) { if (!this.columns.get(collection).contains(tag)) this.columns.get(collection).add(tag); }//from w w w. jav a 2 s .c o m Map<String, String> data = new HashMap<String, String>(); data.putAll(tags); data.put("variable", e.variable()); if (value instanceof Range<?>) { Range<?> range = (Range<?>) value; Number start = (Number) range.lowerEndpoint(); Number end = (Number) range.upperEndpoint(); data.put("start", start + ""); data.put("end", end + ""); data.put("value", (end.doubleValue() - start.doubleValue()) + ""); } else if (value instanceof Number) { data.put("value", (Number) value + ""); } else if (value instanceof Boolean) { data.put("value", (Boolean) value + ""); } else if (value instanceof String) { data.put("value", (String) value); } data.put("timestamp", e.timestamp() + ""); return data; }
From source file:com.github.fge.grappa.matchers.join.JoinMatcherBuilder.java
/** * Generic method to build a {@link JoinMatcher} * * <p>You can use this method directly; note however that the range you will * pass as an argument will be {@link Range#intersection(Range) intersected} * with {@code Range.atLeast(0)}; if the result of the intersection is an * {@link Range#isEmpty() empty range}, this is an error condition.</p> * * <p>Ranges which are {@link BoundType#OPEN open} on any end will be turned * to closed range using {@link Range#canonical(DiscreteDomain)}.</p> * * @param range the range (must not be null) * @return a rule/*w ww.j a v a 2s . c o m*/ * @throws IllegalArgumentException see description * * @see Range#canonical(DiscreteDomain) */ // TODO: check that it actually has an effect @Cached public Rule range(@Nonnull Range<Integer> range) { Objects.requireNonNull(range, "range must not be null"); /* * We always intersect with that range... */ Range<Integer> realRange = AT_LEAST_ZERO.intersection(range); /* * Empty ranges not allowed (what are we supposed to do with that * anyway?) */ Preconditions.checkArgument(!realRange.isEmpty(), "illegal range " + range + ": should not be empty after intersection with " + AT_LEAST_ZERO); /* * Given that we intersect with AT_LEAST_ZERO, which has a lower bound, * the range will always have a lower bound. We want a closed range * internally, therefore change it if it is open. */ Range<Integer> closedRange = toClosedRange(realRange); /* * We always have a lower bound */ int lowerBound = closedRange.lowerEndpoint(); /* * Handle the case where there is no upper bound */ if (!closedRange.hasUpperBound()) return new BoundedDownJoinMatcher(joined, joining, lowerBound); /* * There is an upper bound. Handle the case where it is 0 or 1. Since * the range is legal, we know that if it is 0, so is the lowerbound; * and if it is one, the lower bound is either 0 or 1. */ int upperBound = closedRange.upperEndpoint(); if (upperBound == 0) return new EmptyMatcher(); if (upperBound == 1) return lowerBound == 0 ? new OptionalMatcher(joined) : joined; /* * So, upper bound is 2 or greater; return the appropriate matcher * according to what the lower bound is. * * Also, if the lower and upper bounds are equal, return a matcher doing * a fixed number of matches. */ if (lowerBound == 0) return new BoundedUpJoinMatcher(joined, joining, upperBound); return lowerBound == upperBound ? new ExactMatchesJoinMatcher(joined, joining, lowerBound) : new BoundedBothJoinMatcher(joined, joining, lowerBound, upperBound); }
From source file:org.sonatype.nexus.repository.partial.RangeParser.java
private boolean isSatisfiable(final Range<Long> range, final long contentSize) { if (!range.hasLowerBound()) { return true; }/* w w w.j a va 2 s . c om*/ // Per RFC 2616, a requested range is satisfiable as long as its lower bound is within the content size. // Requests for ranges that extend beyond the content size are okay. return range.lowerEndpoint() < contentSize - 1; }
From source file:org.apache.drill.exec.store.schedule.BlockMapBuilder.java
/** * For a given FileWork, calculate how many bytes are available on each on drillbit endpoint * * @param work the FileWork to calculate endpoint bytes for * @throws IOException/*from w w w. j a v a 2 s . c o m*/ */ public EndpointByteMap getEndpointByteMap(FileWork work) throws IOException { Stopwatch watch = new Stopwatch(); watch.start(); Path fileName = new Path(work.getPath()); ImmutableRangeMap<Long, BlockLocation> blockMap = getBlockMap(fileName); EndpointByteMapImpl endpointByteMap = new EndpointByteMapImpl(); long start = work.getStart(); long end = start + work.getLength(); Range<Long> rowGroupRange = Range.closedOpen(start, end); // Find submap of ranges that intersect with the rowGroup ImmutableRangeMap<Long, BlockLocation> subRangeMap = blockMap.subRangeMap(rowGroupRange); // Iterate through each block in this submap and get the host for the block location for (Map.Entry<Range<Long>, BlockLocation> block : subRangeMap.asMapOfRanges().entrySet()) { String[] hosts; Range<Long> blockRange = block.getKey(); try { hosts = block.getValue().getHosts(); } catch (IOException ioe) { throw new RuntimeException("Failed to get hosts for block location", ioe); } Range<Long> intersection = rowGroupRange.intersection(blockRange); long bytes = intersection.upperEndpoint() - intersection.lowerEndpoint(); // For each host in the current block location, add the intersecting bytes to the corresponding endpoint for (String host : hosts) { DrillbitEndpoint endpoint = getDrillBitEndpoint(host); if (endpoint != null) { endpointByteMap.add(endpoint, bytes); } else { logger.info("Failure finding Drillbit running on host {}. Skipping affinity to that host.", host); } } } logger.debug("FileWork group ({},{}) max bytes {}", work.getPath(), work.getStart(), endpointByteMap.getMaxBytes()); logger.debug("Took {} ms to set endpoint bytes", watch.stop().elapsed(TimeUnit.MILLISECONDS)); return endpointByteMap; }
From source file:org.obiba.opal.web.gwt.app.client.magma.derive.helper.DerivedNumericalVariableGenerator.java
private void appendBounds(Iterable<Range<N>> ranges) { scriptBuilder.append("["); boolean first = true; Range<N> previousRange = null; N bound = null;/*from ww w. j a v a 2s . c o m*/ for (Range<N> range : ranges) { if (previousRange != null && !previousRange.isConnected(range)) { appendBound(previousRange.upperEndpoint(), first); first = false; } if (range.hasLowerBound()) { bound = range.lowerEndpoint(); appendBound(bound, first); first = false; } previousRange = range; } // close the last range if (previousRange != null && previousRange.hasUpperBound()) { appendBound(previousRange.upperEndpoint(), false); } scriptBuilder.append("]"); }
From source file:net.sf.mzmine.modules.visualization.twod.TwoDDataSet.java
private double upperEndpointIntensity(DataPoint dataPoints[], Range<Double> mzRange, PlotMode plotMode) { double maxIntensity = 0; DataPoint searchMZ = new SimpleDataPoint(mzRange.lowerEndpoint(), 0); int startMZIndex = Arrays.binarySearch(dataPoints, searchMZ, new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending)); if (startMZIndex < 0) startMZIndex = (startMZIndex * -1) - 1; if (startMZIndex >= dataPoints.length) return 0; if (dataPoints[startMZIndex].getMZ() > mzRange.upperEndpoint()) { if (plotMode != PlotMode.CENTROID) { if (startMZIndex == 0) return 0; if (startMZIndex == dataPoints.length - 1) return dataPoints[startMZIndex - 1].getIntensity(); // find which data point is closer double diffNext = dataPoints[startMZIndex].getMZ() - mzRange.upperEndpoint(); double diffPrev = mzRange.lowerEndpoint() - dataPoints[startMZIndex - 1].getMZ(); if (diffPrev < diffNext) return dataPoints[startMZIndex - 1].getIntensity(); else/*w w w .j av a 2 s . co m*/ return dataPoints[startMZIndex].getIntensity(); } else { return 0; } } for (int mzIndex = startMZIndex; ((mzIndex < dataPoints.length) && (dataPoints[mzIndex].getMZ() <= mzRange.upperEndpoint())); mzIndex++) { if (dataPoints[mzIndex].getIntensity() > maxIntensity) maxIntensity = dataPoints[mzIndex].getIntensity(); } return maxIntensity; }
From source file:org.pascani.dsl.dbmapper.databases.CSVExport.java
private Map<String, String> handle(ChangeEvent e, String collection) { Map<String, String> data = null; TaggedValue<Serializable> taggedValue = TaggedValue.instanceFrom(e.value(), Serializable.class); if (taggedValue.value() instanceof Number || taggedValue.value() instanceof Boolean || taggedValue.value() instanceof String) { data = toData(collection, e, taggedValue.value(), taggedValue.tags()); } else if (taggedValue.value() instanceof Range<?>) { Range<?> range = (Range<?>) taggedValue.value(); Class<?> clazz = range.hasLowerBound() ? range.lowerEndpoint().getClass() : range.upperEndpoint().getClass(); if (Number.class.isAssignableFrom(clazz)) { data = toData(collection, e, taggedValue.value(), taggedValue.tags()); } else {//ww w . ja v a2s . co m System.out.println("Not supported type " + clazz.getCanonicalName()); } } else { System.out.println("Not supported type " + taggedValue.value().getClass().getCanonicalName()); } return data; }
From source file:org.noroomattheinn.visibletesla.DataStore.java
protected final Range<Long> getLoadPeriod() { Range<Long> loadPeriod = Range.closed(Long.MIN_VALUE, Long.MAX_VALUE); long now = System.currentTimeMillis(); LoadPeriod period = nameToLoadPeriod.get(appContext.prefs.loadPeriod.get()); if (period == null) { period = LoadPeriod.All;/* w ww . j a va 2s .c o m*/ appContext.prefs.loadPeriod.set(nameToLoadPeriod.inverse().get(period)); } switch (period) { case None: loadPeriod = Range.closed(now + 1000, now + 1000L); // Empty Range break; case Last7: loadPeriod = Range.closed(now - (7 * 24 * 60 * 60 * 1000L), now); break; case Last14: loadPeriod = Range.closed(now - (14 * 24 * 60 * 60 * 1000L), now); break; case Last30: loadPeriod = Range.closed(now - (30 * 24 * 60 * 60 * 1000L), now); break; case ThisWeek: Range<Date> thisWeek = getThisWeek(); loadPeriod = Range.closed(thisWeek.lowerEndpoint().getTime(), thisWeek.upperEndpoint().getTime()); break; case ThisMonth: Range<Date> thisMonth = getThisMonth(); loadPeriod = Range.closed(thisMonth.lowerEndpoint().getTime(), thisMonth.upperEndpoint().getTime()); break; case All: default: break; } return loadPeriod; }
From source file:org.noroomattheinn.timeseries.CachedTimeSeries.java
private boolean useInMemoryInternal(Range<Long> period) { long firstInMemory = inMemory.firstTime(); long firstPersistent = persistent.firstTime(); if (firstInMemory <= firstPersistent) return true; if (period.hasLowerBound() && firstInMemory <= period.lowerEndpoint()) return true; return false; }
From source file:com.yahoo.gondola.container.client.ZookeeperShardManagerClient.java
@Override public void setBuckets(Range<Integer> splitRange, String fromShardId, String toShardId, boolean migrationComplete) throws ShardManagerException, InterruptedException { sendActionToAll(!migrationComplete ? MIGRATE_2 : MIGRATE_3, splitRange.lowerEndpoint(), splitRange.upperEndpoint(), fromShardId, toShardId, migrationComplete); if (!waitCondition(null, !migrationComplete ? ZookeeperStat::isMigrating2Operational : ZookeeperStat::isNormalOperational, 3000)) {//from ww w . j a va 2 s .c o m throw new ShardManagerException(FAILED_SET_BUCKETS, "timed out"); } }