List of usage examples for com.google.common.collect Range lowerEndpoint
public C lowerEndpoint()
From source file:radsoft.syntaxhighlighter.view.SyntaxHighlighterPane.java
/** * Apply the list of style to the script text pane. See * {@link syntaxhighlighter.parser.Parser#parse(syntaxhighlighter.brush.Brush, boolean, char[], int, int)}. *//*from ww w . jav a2s .c o m*/ protected void applyStyle() { if (theme == null || styleList == null) { return; } DefaultStyledDocument document = (DefaultStyledDocument) getDocument(); // clear all the existing style document.setCharacterAttributes(0, document.getLength(), theme.getPlain().getAttributeSet(), true); // apply style according to the style list for (String key : styleList.keySet()) { List<Range<Integer>> posList = styleList.get(key); SimpleAttributeSet attributeSet = theme.getStyle(key).getAttributeSet(); for (Range<Integer> pos : posList) { int start = pos.lowerEndpoint(); int end = pos.upperEndpoint(); document.setCharacterAttributes(start, end - start, attributeSet, true); } } repaint(); }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog.java
private long getNumberOfEntries(Range<PositionImpl> range, NavigableMap<Long, MLDataFormats.ManagedLedgerInfo.LedgerInfo> ledgers) { PositionImpl fromPosition = range.lowerEndpoint(); boolean fromIncluded = range.lowerBoundType() == BoundType.CLOSED; PositionImpl toPosition = range.upperEndpoint(); boolean toIncluded = range.upperBoundType() == BoundType.CLOSED; if (fromPosition.getLedgerId() == toPosition.getLedgerId()) { // If the 2 positions are in the same ledger long count = toPosition.getEntryId() - fromPosition.getEntryId() - 1; count += fromIncluded ? 1 : 0;/*from ww w .j a v a2 s .com*/ count += toIncluded ? 1 : 0; return count; } else { long count = 0; // If the from & to are pointing to different ledgers, then we need to : // 1. Add the entries in the ledger pointed by toPosition count += toPosition.getEntryId(); count += toIncluded ? 1 : 0; // 2. Add the entries in the ledger pointed by fromPosition MLDataFormats.ManagedLedgerInfo.LedgerInfo li = ledgers.get(fromPosition.getLedgerId()); if (li != null) { count += li.getEntries() - (fromPosition.getEntryId() + 1); count += fromIncluded ? 1 : 0; } // 3. Add the whole ledgers entries in between for (MLDataFormats.ManagedLedgerInfo.LedgerInfo ls : ledgers .subMap(fromPosition.getLedgerId(), false, toPosition.getLedgerId(), false).values()) { count += ls.getEntries(); } return count; } }
From source file:net.sf.mzmine.modules.visualization.scatterplot.ScatterPlotBottomPanel.java
public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals("DATA_CHANGE")) { ScatterPlotAxisSelection optionX = (ScatterPlotAxisSelection) comboX.getSelectedItem(); ScatterPlotAxisSelection optionY = (ScatterPlotAxisSelection) comboY.getSelectedItem(); if ((optionX == null) || (optionY == null)) return; String foldText = foldXvalues[comboFold.getSelectedIndex()]; int foldValue = Integer.parseInt(foldText); if (foldValue <= 0) foldValue = 2;/*from www.j a v a 2 s. c o m*/ chart.setDisplayedAxes(optionX, optionY, foldValue); return; } if (command.equals("LABEL_ITEMS")) { chart.setItemLabels(labeledItems.isSelected()); } if (command.equals("SEARCH")) { SearchDefinitionType searchType = (SearchDefinitionType) comboSearchDataType.getSelectedItem(); String searchRegex = txtSearchField.getText(); Number minValue = ((Number) minSearchField.getValue()); if (minValue == null) minValue = 0; Number maxValue = ((Number) maxSearchField.getValue()); if (maxValue == null) maxValue = 0; Range<Double> searchRange = Range.closed(minValue.doubleValue(), maxValue.doubleValue()); try { SearchDefinition newSearch = new SearchDefinition(searchType, searchRegex, searchRange); chart.updateSearchDefinition(newSearch); } catch (PatternSyntaxException pe) { MZmineCore.getDesktop().displayErrorMessage(window, "The regular expression's syntax is invalid: " + pe); } return; } if (command.equals("SEARCH_DATA_TYPE")) { SearchDefinitionType searchType = (SearchDefinitionType) comboSearchDataType.getSelectedItem(); switch (searchType) { case MASS: minSearchField.setVisible(true); maxSearchField.setVisible(true); labelRange.setVisible(true); txtSearchField.setVisible(false); NumberFormat mzFormatter = MZmineCore.getConfiguration().getMZFormat(); Range<Double> mzRange = peakList.getRowsMZRange(); DefaultFormatterFactory mzFormatFac = new DefaultFormatterFactory(new NumberFormatter(mzFormatter)); minSearchField.setFormatterFactory(mzFormatFac); minSearchField.setValue(mzRange.lowerEndpoint()); maxSearchField.setFormatterFactory(mzFormatFac); maxSearchField.setValue(mzRange.upperEndpoint()); break; case RT: minSearchField.setVisible(true); maxSearchField.setVisible(true); labelRange.setVisible(true); txtSearchField.setVisible(false); NumberFormat rtFormatter = MZmineCore.getConfiguration().getRTFormat(); Range<Double> rtRange = peakList.getRowsRTRange(); DefaultFormatterFactory rtFormatFac = new DefaultFormatterFactory(new NumberFormatter(rtFormatter)); minSearchField.setFormatterFactory(rtFormatFac); minSearchField.setValue(rtRange.lowerEndpoint()); maxSearchField.setFormatterFactory(rtFormatFac); maxSearchField.setValue(rtRange.upperEndpoint()); break; case NAME: minSearchField.setVisible(false); maxSearchField.setVisible(false); labelRange.setVisible(false); txtSearchField.setVisible(true); break; } return; } }
From source file:org.gbif.occurrence.download.service.HiveQueryVisitor.java
/** * Converts date range into a conjunction predicate with the form: field >= range.lower AND field <= range.upper. * * *//*from ww w . j a v a 2s . c om*/ private CompoundPredicate toDateRangePredicate(Range<Date> range, OccurrenceSearchParameter key) { ImmutableList<Predicate> predicates = new ImmutableList.Builder<Predicate>() .add(new GreaterThanOrEqualsPredicate(key, IsoDateFormat.FULL.getDateFormat().format(range.lowerEndpoint().getTime()))) .add(new LessThanOrEqualsPredicate(key, IsoDateFormat.FULL.getDateFormat().format(range.upperEndpoint()))) .build(); return new ConjunctionPredicate(predicates); }
From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java
/** * Returns the physical indices written to the given storage during the * given group iteration.//from w w w . j av a 2 s.c o m * @param s the storage being written to * @param iterations the group iterations * @return the physical indices written */ public ImmutableSortedSet<Integer> writes(Storage s, Range<Integer> iterations) { ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (Actor a : actors()) builder.addAll(a.writes(s, Range.closedOpen(iterations.lowerEndpoint() * schedule.get(a), iterations.upperEndpoint() * schedule.get(a)))); return builder.build(); }
From source file:com.google.eclipse.protobuf.validation.ProtobufJavaValidator.java
@Check public void checkIndexRangeBounds(IndexRange indexRange) { Range<Long> range; try {//from www .j a va2 s . co m range = indexRanges.toLongRange(indexRange); } catch (BackwardsRangeException e) { error(indexRangeEndLessThanStart, indexRange, null); return; } if (range.lowerEndpoint() <= 0) { error(indexRangeNonPositive, indexRange, ProtobufPackage.Literals.INDEX_RANGE__FROM); } }
From source file:net.sf.mzmine.project.impl.StorableScan.java
/** * @return Returns scan datapoints within a given range *///from w ww .j a v a2 s .c om public @Nonnull DataPoint[] getDataPointsByMass(@Nonnull Range<Double> mzRange) { DataPoint dataPoints[] = getDataPoints(); 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; }
From source file:com.nimbits.server.io.BlobStoreImpl.java
@Override public List<ValueBlobStore> createBlobStoreEntity(final Entity entity, final ValueDayHolder holder) throws IOException { PersistenceManager pm = persistenceManagerFactory.getPersistenceManager(); PrintWriter out = null;/*from ww w .j av a2 s . co m*/ try { logger.info("Creating Blobstore for " + holder.getValues().size()); final String json = gson.toJson(holder.getValues()); String fn = entity.getName().getValue() + "_" + UUID.randomUUID().toString(); out = new PrintWriter(getFolder() + fn); out.println(json); out.close(); Range<Date> range = holder.getTimeRange(); final Date mostRecentTimeForDay = range.upperEndpoint(); final Date earliestForDay = range.lowerEndpoint(); final ValueBlobStoreEntity currentStoreEntity = new ValueBlobStoreEntity(entity.getKey(), holder.getStartOfDay(), mostRecentTimeForDay, earliestForDay, fn, json.length(), BlobStore.storageVersion, entity.getUUID() ); currentStoreEntity.validate(); pm.makePersistent(currentStoreEntity); pm.flush(); return ValueBlobStoreFactory.createValueBlobStore(currentStoreEntity); } finally { if (out != null) { out.close(); } pm.close(); } }
From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java
/** * Returns the physical indices read from the given storage during the given * group iterations./*from w w w .j a va2 s . co m*/ * @param s the storage being read from * @param iterations the group iterations * @return the physical indices read */ public ImmutableSortedSet<Integer> reads(Storage s, Range<Integer> iterations) { iterations = iterations.canonical(DiscreteDomain.integers()); ImmutableSortedSet.Builder<Integer> builder = ImmutableSortedSet.naturalOrder(); for (Actor a : actors()) builder.addAll(a.reads(s, Range.closedOpen(iterations.lowerEndpoint() * schedule.get(a), iterations.upperEndpoint() * schedule.get(a)))); return builder.build(); }
From source file:net.sf.mzmine.modules.visualization.twod.TwoDDataSet.java
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); }//from w w w . ja va 2s .c om 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; }