List of usage examples for com.google.common.collect Range upperEndpoint
public C upperEndpoint()
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// ww w .j a va 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:io.github.mzmine.parameters.parametertypes.ranges.MZRangeEditor.java
@Override public void setValue(Range<Double> value) { if (value == null) return;//from w w w . j av a 2s .c o m String minValue; String maxValue; NumberFormat numberFormat = MZmineCore.getConfiguration().getMZFormat(); minValue = numberFormat.format(value.lowerEndpoint()); maxValue = numberFormat.format(value.upperEndpoint()); minTxtField.setText(minValue); maxTxtField.setText(maxValue); }
From source file:io.github.mzmine.parameters.parametertypes.ranges.DoubleRangeEditor.java
@SuppressWarnings("null") @Override/*w w w . j a v a 2s. com*/ public void setValue(Range<Double> value) { if (value == null) return; String minValue; String maxValue; if (numberFormat != null) { minValue = String.valueOf(numberFormat.format(value.lowerEndpoint())); maxValue = String.valueOf(numberFormat.format(value.upperEndpoint())); } else { minValue = String.valueOf(value.lowerEndpoint()); maxValue = String.valueOf(value.upperEndpoint()); } minTxtField.setText(minValue); maxTxtField.setText(maxValue); }
From source file:com.wealdtech.collect.TreeRangedMultimap.java
@Override public boolean put(final Range<K> key, final V value) { List<V> startArray = startMap.get(key.lowerEndpoint()); if (startArray == null) { startArray = new ArrayList<>(); startMap.put(key.lowerEndpoint(), startArray); }/* ww w . ja v a 2 s . com*/ startArray.add(value); List<V> endArray = endMap.get(key.upperEndpoint()); if (endArray == null) { endArray = new ArrayList<>(); endMap.put(key.upperEndpoint(), endArray); } endArray.add(value); size++; return true; }
From source file:org.openehealth.ipf.commons.ihe.fhir.LazyBundleProvider.java
@Override public List<IBaseResource> getResources(int fromIndex, int toIndex) { if (!cacheResults) { return getPartialResult(fromIndex, toIndex); }/*from www. j a v a 2 s. c o m*/ LOG.debug("Cached results contain the following ranges: {}. Requesting resources from index {} to {}", resultRanges, fromIndex, toIndex); Range<Integer> wanted = Range.closedOpen(fromIndex, toIndex); RangeSet<Integer> needed = resultRanges.required(wanted); LOG.debug("Requiring the following ranges {}", needed); for (Range<Integer> requiredRange : needed.asDescendingSetOfRanges()) { LOG.debug("Now requesting the following range {}", requiredRange); List<IBaseResource> results = getPartialResult(requiredRange.lowerEndpoint(), requiredRange.upperEndpoint()); LOG.debug("Got back a list of size {}", results.size()); if (!results.isEmpty()) { cacheAll(requiredRange.lowerEndpoint(), results); // Take care, potentially less elements than requested have been retrieved resultRanges.add(Range.closedOpen(requiredRange.lowerEndpoint(), requiredRange.lowerEndpoint() + results.size())); } } LOG.debug("Cached results now contain the following ranges: {}", resultRanges); // Everything went OK, return whatever we got return cachedResults.subList(fromIndex, Math.min(cachedResults.size(), Math.min(cachedResults.size(), toIndex))); }
From source file:org.apache.pulsar.common.naming.NamespaceBundleFactory.java
/** * Fetches {@link NamespaceBundles} from cache for a given namespace. finds target bundle, split into numBundles and * returns new {@link NamespaceBundles} with newly split bundles into it. * * @param targetBundle/*from w ww. java 2 s .co m*/ * {@link NamespaceBundle} needs to be split * @param numBundles * split into numBundles * @return List of split {@link NamespaceBundle} and {@link NamespaceBundles} that contains final bundles including * split bundles for a given namespace * @throws Exception */ public Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles(NamespaceBundle targetBundle, int numBundles) throws Exception { checkNotNull(targetBundle, "can't split null bundle"); checkNotNull(targetBundle.getNamespaceObject(), "namespace must be present"); NamespaceName nsname = targetBundle.getNamespaceObject(); NamespaceBundles sourceBundle = bundlesCache.synchronous().get(nsname); final int lastIndex = sourceBundle.partitions.length - 1; final long[] partitions = new long[sourceBundle.partitions.length + (numBundles - 1)]; int pos = 0; int splitPartition = -1; for (int i = 0; i < lastIndex; i++) { final Range<Long> range = targetBundle.getKeyRange(); if (sourceBundle.partitions[i] == range.lowerEndpoint() && (range.upperEndpoint() == sourceBundle.partitions[i + 1])) { splitPartition = i; Long maxVal = sourceBundle.partitions[i + 1]; Long minVal = sourceBundle.partitions[i]; Long segSize = (maxVal - minVal) / numBundles; partitions[pos++] = minVal; Long curPartition = minVal + segSize; for (int j = 0; j < numBundles - 1; j++) { partitions[pos++] = curPartition; curPartition += segSize; } } else { partitions[pos++] = sourceBundle.partitions[i]; } } partitions[pos] = sourceBundle.partitions[lastIndex]; if (splitPartition != -1) { NamespaceBundles splittedNsBundles = new NamespaceBundles(nsname, partitions, this); List<NamespaceBundle> splittedBundles = splittedNsBundles.getBundles().subList(splitPartition, (splitPartition + numBundles)); return new ImmutablePair<NamespaceBundles, List<NamespaceBundle>>(splittedNsBundles, splittedBundles); } return null; }
From source file:org.robotframework.ide.eclipse.main.plugin.assist.ProposalMatch.java
Optional<ProposalMatch> mapAndShiftToFragment(final int startIndex, final int length) { final List<Range<Integer>> rangesInDomain = new ArrayList<>(); final Range<Integer> targetDomain = Range.closedOpen(startIndex, startIndex + length); for (final Range<Integer> match : this) { if (match.encloses(targetDomain)) { rangesInDomain.add(targetDomain); } else if (targetDomain.encloses(match)) { rangesInDomain.add(match);/*from www .j av a2 s . com*/ } else if (match.lowerEndpoint().intValue() <= startIndex && startIndex <= match.upperEndpoint().intValue()) { rangesInDomain.add(Range.closedOpen(startIndex, match.upperEndpoint())); } else if (match.lowerEndpoint().intValue() <= startIndex + length && startIndex + startIndex <= match.upperEndpoint().intValue()) { rangesInDomain.add(Range.closedOpen(match.lowerEndpoint(), startIndex + length)); } } final List<Range<Integer>> newMatches = new ArrayList<>(); for (final Range<Integer> match : rangesInDomain) { newMatches .add(Range.closedOpen(match.lowerEndpoint() - startIndex, match.upperEndpoint() - startIndex)); } return newMatches.isEmpty() ? Optional.<ProposalMatch>empty() : Optional.of(new ProposalMatch(newMatches)); }
From source file:com.github.drbookings.ui.StatusLabelStringFactory.java
private String build(final boolean completePayment, final boolean netEarnings) { final StringBuilder sb = new StringBuilder(); // sb.append(BookingEntries.getMinDate(bookings.getAllBookings()).get()); // sb.append(" "); // sb.append(BookingEntries.getMaxDate(bookings.getAllBookings()).get()); // sb.append("\t"); Range<LocalDate> selectedRange = DateBeanSelectionManager.getInstance().getSelectedDateRange(); if (selectedRange == null) { return sb.toString(); }// w ww . j a v a 2 s .c om sb.append("#unique nights: "); sb.append(LocalDates.getNumberOfNights(selectedRange.lowerEndpoint(), selectedRange.upperEndpoint())); sb.append("\tEarnings:"); sb.append(DECIMAL_FORMAT.format(bookings.getAllBookings(false).stream().filter(b -> !b.isCheckOut()) .mapToDouble(b -> b.getEarnings(netEarnings)).sum())); sb.append("\tAv.Earnings/Night/Room:"); final OptionalDouble av = bookings.getAllBookings(false).stream().filter(b -> !b.isCheckOut()) .mapToDouble(b -> b.getEarnings(netEarnings)).average(); if (av.isPresent()) { sb.append(DECIMAL_FORMAT.format(av.getAsDouble())); } else { sb.append(DECIMAL_FORMAT.format(0)); } sb.append("\tOccupancyRate:"); sb.append(StatusLabelStringFactory.DECIMAL_FORMAT .format(new OccupancyRateProvider().getOccupancyRate() * 100)); // sb.append("\tMinPriceAtRate:"); // sb.append(StatusLabelStringFactory.DECIMAL_FORMAT.format(new MinimumPriceProvider().getMinimumPrice())); return sb.toString(); }
From source file:net.sf.mzmine.parameters.dialogs.ParameterSetupDialogWithChromatogramPreview.java
private void updateTitle() { NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat(); NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); Range<Double> rtRange = rtRangeBox.getValue(); Range<Double> mzRange = mzRangeBox.getValue(); String title = "m/z: " + mzFormat.format(mzRange.lowerEndpoint()) + " - " + mzFormat.format(mzRange.upperEndpoint()) + ", RT: " + rtFormat.format(rtRange.lowerEndpoint()) + " - " + rtFormat.format(rtRange.upperEndpoint()); // update plot title ticPlot.setTitle(previewDataFile.getName(), title); }
From source file:com.stackframe.collect.RangeUtilities.java
/** * Build an expression suitable for passing to JDBC as part of an SQL query from a date range. * * @param column the name of the column//from w w w.ja v a2 s . com * @param dateRange the Range * @return a String containing the expression */ public static String toSQL(String column, Range<Date> dateRange) { StringBuilder buf = new StringBuilder(); if (dateRange.hasLowerBound()) { BoundType lowerBound = dateRange.lowerBoundType(); String operator; switch (lowerBound) { case CLOSED: operator = ">="; break; case OPEN: operator = ">"; break; default: throw new AssertionError("unexpected bound type " + lowerBound); } Date lowerEndpoint = dateRange.lowerEndpoint(); java.sql.Date lowerDate = convert(lowerEndpoint); buf.append(String.format("%s %s '%s'", column, operator, lowerDate.toString())); if (dateRange.hasUpperBound()) { buf.append(" AND "); } } if (dateRange.hasUpperBound()) { BoundType upperBound = dateRange.upperBoundType(); String operator; switch (upperBound) { case CLOSED: operator = "<="; break; case OPEN: operator = "<"; break; default: throw new AssertionError("unexpected bound type " + upperBound); } Date upperEndpoint = dateRange.upperEndpoint(); java.sql.Date upperDate = convert(upperEndpoint); buf.append(String.format("%s %s '%s'", column, operator, upperDate.toString())); } return buf.toString(); }