Java Code Examples for com.google.common.collect.Range#upperEndpoint()
The following examples show how to use
com.google.common.collect.Range#upperEndpoint() .
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: SimpleScan.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
/** * @return Returns scan datapoints within a given range */ public @Nonnull DataPoint[] getDataPointsByMass(@Nonnull Range<Double> mzRange) { int startIndex, endIndex; for (startIndex = 0; startIndex < dataPoints.length; startIndex++) { if (dataPoints[startIndex].getMZ() >= mzRange.lowerEndpoint()) break; } for (endIndex = startIndex; endIndex < dataPoints.length; endIndex++) { if (dataPoints[endIndex].getMZ() > mzRange.upperEndpoint()) break; } DataPoint pointsWithinRange[] = new DataPoint[endIndex - startIndex]; // Copy the relevant points System.arraycopy(dataPoints, startIndex, pointsWithinRange, 0, endIndex - startIndex); return pointsWithinRange; }
Example 2
Source File: HistogramPlotDataset.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
public HistogramPlotDataset(PeakList peakList, RawDataFile[] rawDataFiles, int numOfBins, HistogramDataType dataType, Range<Double> range) { this.list = new Vector<HashMap<?, ?>>(); this.type = HistogramType.FREQUENCY; this.dataType = dataType; this.peakList = peakList; this.numOfBins = numOfBins; this.rawDataFiles = rawDataFiles; minimum = range.lowerEndpoint(); maximum = range.upperEndpoint(); updateHistogramDataset(); }
Example 3
Source File: ModuloDatabaseShardingAlgorithm.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 5 votes |
@Override public Collection<String> doBetweenSharding(final Collection<String> dataSourceNames, final ShardingValue<Integer> shardingValue) { Collection<String> result = new LinkedHashSet<>(dataSourceNames.size()); Range<Integer> range = shardingValue.getValueRange(); for (Integer value = range.lowerEndpoint(); value <= range.upperEndpoint(); value++) { for (String each : dataSourceNames) { if (each.endsWith(value % 2 + "")) { result.add(each); } } } return result; }
Example 4
Source File: FoldSourceFile.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Convert unfolded char regions to folded LOCs */ static ArrayList<Integer> getFoldedLines(final File sourceFile, final ArrayList<Range<Integer>> unfoldedFolds, final ArrayList<Range<Integer>> allFolds) { // Read file to string final String fileString = CodeUtils.readFileString(sourceFile); // Convert regions to unfold into lines to fold final ArrayList<Integer> foldedLines = new ArrayList<>(); for (final Range<Integer> fold : allFolds) { if (!unfoldedFolds.contains(fold)) { // If folded // Get start line +1 (first line of char range isn't folded) int startLine = fileString.substring(0, fold.lowerEndpoint()) .split("\n").length; // unless fold is the whole file if (fold.lowerEndpoint() != 0 || fold.upperEndpoint() != fileString.length()) startLine += 1; // Get end line final int endLine = fileString.substring(0, fold.upperEndpoint()).split("\n").length; // Add folded LOCs for (int line = startLine; line <= endLine; line++) foldedLines.add(line); } } return foldedLines; }
Example 5
Source File: Ranges.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Return an english phrase describing the given {@link Range} e.g. * * Range.all() -> "unbounded" * Range.singleton(3) -> "3" * Range.atLeast(3) -> "at least 3" * Range.closedOpen(3, 7) -> "at least 3 and less than 7" * Range.closed(3, 7) -> "between 3 and 7" */ public static String describe(Range<?> range) { if(range.hasLowerBound() && range.hasUpperBound() && range.lowerBoundType() == BoundType.CLOSED && range.upperBoundType() == BoundType.CLOSED) { if(range.lowerEndpoint().equals(range.upperEndpoint())) { // singleton return range.lowerEndpoint().toString(); } else { // closed-closed return "between " + range.lowerEndpoint() + " and " + range.upperEndpoint(); } } final List<String> parts = new ArrayList<>(2); if(range.hasLowerBound()) { parts.add((range.lowerBoundType() == BoundType.CLOSED ? "at least " : "more than ") + range.lowerEndpoint()); } if(range.hasUpperBound()) { parts.add((range.upperBoundType() == BoundType.CLOSED ? "at most " : "less than ") + range.upperEndpoint()); } switch(parts.size()) { case 0: return "unbounded"; case 1: return parts.get(0); default: return parts.get(0) + " and " + parts.get(1); } }
Example 6
Source File: RangeUtils.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Returns a range that is contained in between the both ranges. * * @param r1 * @param r2 * @return The connected range. Null if there is no connected range. */ public static @Nullable Range<Double> getConnected(@Nonnull Range<Double> r1, @Nonnull Range<Double> r2){ if(!r1.isConnected(r2)) return null; double lower = (r1.lowerEndpoint() > r2.lowerEndpoint()) ? r1.lowerEndpoint() : r2.lowerEndpoint(); double upper = (r1.upperEndpoint() > r2.upperEndpoint()) ? r2.upperEndpoint() : r1.upperEndpoint(); return Range.closed(lower, upper); }
Example 7
Source File: ModuloDatabaseShardingAlgorithm.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 5 votes |
@Override public Collection<String> doBetweenSharding(final Collection<String> dataSourceNames, final ShardingValue<Integer> shardingValue) { Collection<String> result = new LinkedHashSet<>(dataSourceNames.size()); Range<Integer> range = shardingValue.getValueRange(); for (Integer i = range.lowerEndpoint(); i <= range.upperEndpoint(); i++) { for (String each : dataSourceNames) { if (each.endsWith(i % 2 + "")) { result.add(each); } } } return result; }
Example 8
Source File: PeakUtils.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Integrates over a given m/z and rt range within a raw data file. * * @param dataFile * @param rtRange * @param mzRange * @return The result of the integration. */ public static double integrateOverMzRtRange(RawDataFile dataFile, Range<Double> rtRange, Range<Double> mzRange) { ManualPeak newPeak = new ManualPeak(dataFile); boolean dataPointFound = false; int[] scanNumbers = dataFile.getScanNumbers(1, rtRange); for (int scanNumber : scanNumbers) { // Get next scan Scan scan = dataFile.getScan(scanNumber); // Find most intense m/z peak DataPoint basePeak = ScanUtils.findBasePeak(scan, mzRange); if (basePeak != null) { if (basePeak.getIntensity() > 0) dataPointFound = true; newPeak.addDatapoint(scan.getScanNumber(), basePeak); } else { final double mzCenter = (mzRange.lowerEndpoint() + mzRange.upperEndpoint()) / 2.0; DataPoint fakeDataPoint = new SimpleDataPoint(mzCenter, 0); newPeak.addDatapoint(scan.getScanNumber(), fakeDataPoint); } } if (dataPointFound) { newPeak.finalizePeak(); return newPeak.getArea(); } else { return 0.0; } }
Example 9
Source File: FeatureOverviewWindow.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
private JSplitPane addTicPlot(PeakListRow row) { JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); // labels for TIC visualizer Map<Feature, String> labelsMap = new HashMap<Feature, String>(0); // scan selection ScanSelection scanSelection = new ScanSelection(rawFiles[0].getDataRTRange(1), 1); // mz range Range<Double> mzRange = null; mzRange = feature.getRawDataPointsMZRange(); // optimize output by extending the range double upper = mzRange.upperEndpoint(); double lower = mzRange.lowerEndpoint(); double fiveppm = (upper * 5E-6); mzRange = Range.closed(lower - fiveppm, upper + fiveppm); // labels labelsMap.put(feature, feature.toString()); TICVisualizerWindow window = new TICVisualizerWindow(rawFiles, // raw TICPlotType.BASEPEAK, // plot type scanSelection, // scan selection mzRange, // mz range row.getPeaks(), // selected features labelsMap); // labels pane.add(window.getTICPlot()); pane.add(window.getToolBar()); pane.setResizeWeight(1); pane.setDividerSize(1); pane.setBorder(BorderFactory.createLineBorder(Color.black)); return pane; }
Example 10
Source File: CharSequenceInputBuffer.java From grappa with Apache License 2.0 | 5 votes |
@Override public String extractLine(final int lineNumber) { Preconditions.checkArgument(lineNumber > 0, "line number is negative"); final LineCounter counter = Futures.getUnchecked(lineCounter); final Range<Integer> range = counter.getLineRange(lineNumber); final int start = range.lowerEndpoint(); int end = range.upperEndpoint(); if (charAt(end - 1) == '\n') end--; if (charAt(end - 1) == '\r') end--; return extract(start, end); }
Example 11
Source File: SafeRangeOperationUtils.java From shardingsphere with Apache License 2.0 | 5 votes |
/** * Execute contains method by safe mode. * * @param range range * @param endpoint endpoint * @return whether the endpoint is included in the range */ public static boolean safeContains(final Range<Comparable<?>> range, final Comparable<?> endpoint) { try { return range.contains(endpoint); } catch (final ClassCastException ex) { Comparable<?> rangeUpperEndpoint = range.hasUpperBound() ? range.upperEndpoint() : null; Comparable<?> rangeLowerEndpoint = range.hasLowerBound() ? range.lowerEndpoint() : null; Class<?> clazz = getTargetNumericType(Lists.newArrayList(rangeLowerEndpoint, rangeUpperEndpoint, endpoint)); if (clazz == null) { throw ex; } Range<Comparable<?>> newRange = createTargetNumericTypeRange(range, clazz); return newRange.contains(parseNumberByClazz(endpoint.toString(), clazz)); } }
Example 12
Source File: ModuloTableShardingAlgorithm.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 5 votes |
@Override public Collection<String> doBetweenSharding(final Collection<String> tableNames, final ShardingValue<Integer> shardingValue) { Collection<String> result = new LinkedHashSet<>(tableNames.size()); Range<Integer> range = shardingValue.getValueRange(); for (Integer value = range.lowerEndpoint(); value <= range.upperEndpoint(); value++) { for (String each : tableNames) { if (each.endsWith(value % 2 + "")) { result.add(each); } } } return result; }
Example 13
Source File: JavaOutput.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Expand a token range to start and end on acceptable boundaries for re-formatting. * * @param iRange the {@link Range} of tokens * @return the expanded token range */ private Range<Integer> expandToBreakableRegions(Range<Integer> iRange) { // The original line range. int loTok = iRange.lowerEndpoint(); int hiTok = iRange.upperEndpoint() - 1; // Expand the token indices to formattable boundaries (e.g. edges of statements). if (!partialFormatRanges.contains(loTok) || !partialFormatRanges.contains(hiTok)) { return EMPTY_RANGE; } loTok = partialFormatRanges.rangeContaining(loTok).lowerEndpoint(); hiTok = partialFormatRanges.rangeContaining(hiTok).upperEndpoint(); return Range.closedOpen(loTok, hiTok + 1); }
Example 14
Source File: ActiveThreadsFilter.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static @NonNull Set<Long> getOnCpuThreads(@NonNull List<Range<Long>> cpuRanges, TmfTimeRange winRange, @NonNull ITmfTrace trace) { ThreadStatusDataProvider threadStatusProvider = DataProviderManager.getInstance().getDataProvider(trace, ThreadStatusDataProvider.ID, ThreadStatusDataProvider.class); if (threadStatusProvider == null) { return Collections.emptySet(); } long beginTS = winRange.getStartTime().getValue(); long endTS = winRange.getEndTime().getValue(); @NonNull Set<@NonNull Long> cpus = new HashSet<>(); for (Range<Long> range : cpuRanges) { for (long cpu = range.lowerEndpoint(); cpu <= range.upperEndpoint(); cpu ++) { cpus.add(cpu); } } SelectionTimeQueryFilter filter = new SelectionTimeQueryFilter(beginTS, endTS, 2, cpus); Map<@NonNull String, @NonNull Object> parameters = FetchParametersUtils.selectionTimeQueryToMap(filter); parameters.put(ThreadStatusDataProvider.ACTIVE_THREAD_FILTER_KEY, true); TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> response = threadStatusProvider.fetchTree(parameters, null); TmfTreeModel<@NonNull TimeGraphEntryModel> model = response.getModel(); if (model == null) { return Collections.emptySet(); } HashSet<Long> onCpuThreads = Sets.newHashSet(Iterables.transform(model.getEntries(), TimeGraphEntryModel::getId)); return onCpuThreads == null ? Collections.emptySet() : onCpuThreads; }
Example 15
Source File: ModuloDatabaseShardingAlgorithm.java From javabase with Apache License 2.0 | 5 votes |
@Override public Collection<String> doBetweenSharding(final Collection<String> dataSourceNames, final ShardingValue<Integer> shardingValue) { Collection<String> result = new LinkedHashSet<>(dataSourceNames.size()); Range<Integer> range = shardingValue.getValueRange(); for (Integer i = range.lowerEndpoint(); i <= range.upperEndpoint(); i++) { for (String each : dataSourceNames) { if (each.endsWith(i % 2 + "")) { result.add(each); } } } return result; }
Example 16
Source File: TwoDDataSet.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
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 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; }
Example 17
Source File: TwoDDataSet.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
double upperEndpointIntensity(Range<Double> rtRange, Range<Double> mzRange, PlotMode plotMode) { double maxIntensity = 0; double searchRetentionTimes[] = retentionTimes; if (processedScans < totalScans) { searchRetentionTimes = new double[processedScans]; System.arraycopy(retentionTimes, 0, searchRetentionTimes, 0, searchRetentionTimes.length); } int startScanIndex = Arrays.binarySearch(searchRetentionTimes, rtRange.lowerEndpoint()); if (startScanIndex < 0) startScanIndex = (startScanIndex * -1) - 1; if (startScanIndex >= searchRetentionTimes.length) { return 0; } if (searchRetentionTimes[startScanIndex] > rtRange.upperEndpoint()) { if (startScanIndex == 0) return 0; if (startScanIndex == searchRetentionTimes.length - 1) return upperEndpointIntensity(startScanIndex - 1, mzRange, plotMode); // find which scan point is closer double diffNext = searchRetentionTimes[startScanIndex] - rtRange.upperEndpoint(); double diffPrev = rtRange.lowerEndpoint() - searchRetentionTimes[startScanIndex - 1]; if (diffPrev < diffNext) return upperEndpointIntensity(startScanIndex - 1, mzRange, plotMode); else return upperEndpointIntensity(startScanIndex, mzRange, plotMode); } for (int scanIndex = startScanIndex; ((scanIndex < searchRetentionTimes.length) && (searchRetentionTimes[scanIndex] <= rtRange.upperEndpoint())); scanIndex++) { // ignore scans where all peaks are smaller than current max if (basePeaks[scanIndex] < maxIntensity) continue; double scanMax = upperEndpointIntensity(scanIndex, mzRange, plotMode); if (scanMax > maxIntensity) maxIntensity = scanMax; } return maxIntensity; }
Example 18
Source File: RangeUtil.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
/** * remove from self the elements that exist in other * @return */ public static <C extends Comparable<?>> List<Range<C>> remove(Range<C> self, Range<C> other) { // mimic the following logic in guava 18: // RangeSet<C> rangeSet = TreeRangeSet.create(); // rangeSet.add(self); // rangeSet.remove(other); // return Lists.newArrayList(rangeSet.asRanges()); if (other == null || !self.isConnected(other)) { return Collections.singletonList(self); } Range<C> share = self.intersection(other); if (share.isEmpty()) { return Collections.singletonList(self); } List<Range<C>> ret = Lists.newArrayList(); //see left part if (!self.hasLowerBound()) { if (share.hasLowerBound()) { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.lessThan(share.lowerEndpoint())); } else { ret.add(Range.atMost(share.lowerEndpoint())); } } } else { if (self.lowerEndpoint() != share.lowerEndpoint()) { if (self.lowerBoundType() == BoundType.CLOSED) { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.closedOpen(self.lowerEndpoint(), share.lowerEndpoint())); } else { ret.add(Range.closed(self.lowerEndpoint(), share.lowerEndpoint())); } } else { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.open(self.lowerEndpoint(), share.lowerEndpoint())); } else { ret.add(Range.openClosed(self.lowerEndpoint(), share.lowerEndpoint())); } } } else { if (self.lowerBoundType() == BoundType.CLOSED && share.lowerBoundType() == BoundType.OPEN) { ret.add(Range.closed(self.lowerEndpoint(), share.lowerEndpoint())); } } } //see right part if (!self.hasUpperBound()) { if (share.hasUpperBound()) { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.greaterThan(share.upperEndpoint())); } else { ret.add(Range.atLeast(share.upperEndpoint())); } } } else { if (self.upperEndpoint() != share.upperEndpoint()) { if (self.upperBoundType() == BoundType.CLOSED) { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.openClosed(share.upperEndpoint(), self.upperEndpoint())); } else { ret.add(Range.closed(share.upperEndpoint(), self.upperEndpoint())); } } else { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.open(share.upperEndpoint(), self.upperEndpoint())); } else { ret.add(Range.closedOpen(share.upperEndpoint(), self.upperEndpoint())); } } } else { if (self.upperBoundType() == BoundType.CLOSED && share.upperBoundType() == BoundType.OPEN) { ret.add(Range.closed(self.upperEndpoint(), share.upperEndpoint())); } } } return ret; }
Example 19
Source File: PhoneEntryOperator.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
/** * Sets the range for the phone numbers generated by the operator. * * @param i the range within which the phone numbers are randomly generated. */ public void setPhoneRange(Range<Integer> phoneRange) { this.rangeLowerEndpoint = phoneRange.lowerEndpoint(); this.rangeUpperEndpoint = phoneRange.upperEndpoint(); }
Example 20
Source File: GVCFBlockCombiner.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
static VCFHeaderLine rangeToVCFHeaderLine(Range<Integer> genotypeQualityBand) { // Need to uniquify the key for the header line using the min/max GQ, since // VCFHeader does not allow lines with duplicate keys. final String key = String.format(GVCF_BLOCK+"%d-%d", genotypeQualityBand.lowerEndpoint(), genotypeQualityBand.upperEndpoint()); return new VCFHeaderLine(key, "minGQ=" + genotypeQualityBand.lowerEndpoint() + "(inclusive),maxGQ=" + genotypeQualityBand.upperEndpoint() + "(exclusive)"); }