com.google.common.collect.Range#lowerEndpoint ( )源码实例Demo

下面列出了com.google.common.collect.Range#lowerEndpoint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: grappa   文件: LineCounter.java
public Position toPosition(@Tainted final int index)
{
    if (index < 0)
        throw new IllegalStateException();

    final Range<Integer> range;

    // Edge case: unfortunately, we can get an illegal index
    if (index >= len) {
        range = lines.get(nrLines - 1);
        return new Position(nrLines, len - range.lowerEndpoint() + 1);
    }

    final int lineNr = binarySearch(index);

    range = lines.get(lineNr);
    return new Position(lineNr + 1, index - range.lowerEndpoint() + 1);
}
 
源代码2 项目: mzmine3   文件: HistogramPlotDataset.java
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();

}
 
源代码3 项目: mzmine2   文件: XICManualPickerDialog.java
private void setMassRange() {
  Range<Double> r = mzRangeComp.getValue();
  if (r == null || r.upperEndpoint() < r.lowerEndpoint()) {
    MZmineCore.getDesktop().displayErrorMessage(null, "Manual integration",
        "Mass range invalid.");
    return;
  }

  parameters.getParameter(XICManualPickerParameters.mzRange).setValue(r);

  ScanSelection sel = new ScanSelection(rawDataFile.getDataRTRange(), 1);
  Scan[] scans = sel.getMatchingScans(rawDataFile);
  TICDataSet ds = new TICDataSet(dataSet.getDataFile(), scans, r, null, TICPlotType.TIC);

  getTicPlot().removeAllTICDataSets();
  getTicPlot().addTICDataset(ds);
}
 
private static String determineRangeType(Range<?> range) {
    Object anyEndpoint = range.hasLowerBound() ? range.lowerEndpoint() :
                         range.hasUpperBound() ? range.upperEndpoint() : null;

    if (anyEndpoint == null) {
        throw new IllegalArgumentException("The range " + range + " doesn't have any upper or lower bound!");
    }

    Class<?> clazz = anyEndpoint.getClass();

    if (clazz.equals(Integer.class)) {
        return "int4range";
    } else if (clazz.equals(Long.class)) {
        return "int8range";
    } else if (clazz.equals(BigDecimal.class)) {
        return "numrange";
    }

    throw new IllegalStateException("The class [" + clazz.getName() + "] is not supported!");
}
 
源代码5 项目: mzmine2   文件: YMDBGateway.java
public String[] findCompounds(double mass, MZTolerance mzTolerance, int numOfResults,
    ParameterSet parameters) throws IOException {

  Range<Double> toleranceRange = mzTolerance.getToleranceRange(mass);

  String queryAddress = ymdbSearchAddress + "query_from=" + toleranceRange.lowerEndpoint()
      + "&query_to=" + toleranceRange.upperEndpoint();

  URL queryURL = new URL(queryAddress);

  // Submit the query
  logger.finest("Querying YMDB URL " + queryURL);
  String queryResult = InetUtils.retrieveData(queryURL);

  // Organize the IDs as a TreeSet to keep them sorted
  TreeSet<String> results = new TreeSet<String>();

  // Find IDs in the HTML data
  Pattern pat = Pattern.compile("/compounds/(YMDB[0-9]{5})");
  Matcher matcher = pat.matcher(queryResult);
  while (matcher.find()) {
    String ymdbID = matcher.group(1);
    results.add(ymdbID);
  }

  // Remove all except first numOfResults IDs. The reason why we first
  // retrieve all results and then remove those above numOfResults is to
  // keep the lowest YDMB IDs - these may be the most interesting ones.
  while (results.size() > numOfResults) {
    String lastItem = results.last();
    results.remove(lastItem);
  }

  return results.toArray(new String[0]);

}
 
源代码6 项目: javaide   文件: JavaOutput.java
/**
 * 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);
}
 
@Override
public Collection<String> doBetweenSharding(final Collection<String> availableTargetNames, final ShardingValue<Integer> shardingValue) {
    Collection<String> result = new LinkedHashSet<>(availableTargetNames.size());
    Range<Integer> range = shardingValue.getValueRange();
    for (Integer i = range.lowerEndpoint(); i <= range.upperEndpoint(); i++) {
        for (String each : availableTargetNames) {
            if (each.endsWith(i % 4 + "")) {
                result.add(each);
            }
        }
    }
    return result;
}
 
@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;
}
 
@Override
public Collection<String> doBetweenSharding(final Collection<String> availableTargetNames, final ShardingValue<Integer> shardingValue) {
    Collection<String> result = new LinkedHashSet<>(availableTargetNames.size());
    Range<Integer> range = shardingValue.getValueRange();
    for (Integer value = range.lowerEndpoint(); value <= range.upperEndpoint(); value++) {
        for (String each : availableTargetNames) {
            if (each.endsWith(value % 2 + "")) {
                result.add(each);
            }
        }
    }
    return result;
}
 
源代码10 项目: google-java-format   文件: JavaOutput.java
/**
 * 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);
}
 
@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;
}
 
源代码12 项目: biojava   文件: ChromosomeMappingTools.java
/**
 * Converts the genetic coordinate to the position of the nucleotide on the mRNA sequence for a gene
 * living on the forward DNA strand.
 *
 * @param chromPos The genetic coordinate on a chromosome
 * @param exonStarts The list holding the genetic coordinates pointing to the start positions of the exons (including UTR regions)
 * @param exonEnds The list holding the genetic coordinates pointing to the end positions of the exons (including UTR regions)
 * @param cdsStart The start position of a coding region
 * @param cdsEnd The end position of a coding region
 *
 * @return the position of the nucleotide base on the mRNA sequence corresponding to the input genetic coordinate (base 1)
 *
 * @author Yana Valasatava
 */
public static int getCDSPosForward(int chromPos, List<Integer> exonStarts, List<Integer> exonEnds,
		int cdsStart, int cdsEnd) {

	// the genetic coordinate is not in a coding region
	if ( (chromPos < (cdsStart+base) ) || ( chromPos > (cdsEnd+base) ) ) {
		logger.debug("The "+format(chromPos)+" position is not in a coding region");
		return -1;
	}

	logger.debug("looking for CDS position for " +format(chromPos));

	// map the genetic coordinates of coding region on a stretch of a reverse strand
	List<Range<Integer>> cdsRegions = getCDSRegions(exonStarts, exonEnds, cdsStart, cdsEnd);

	int codingLength = 0;
	int lengthExon = 0;
	for (Range<Integer> range : cdsRegions) {

		int start = range.lowerEndpoint();
		int end = range.upperEndpoint();

		lengthExon = end - start;

		if (start+base <= chromPos && end >= chromPos ) {
			return codingLength + (chromPos-start);
		}
		else {
			codingLength += lengthExon;
		}
	}
	return -1;
}
 
源代码13 项目: mzmine2   文件: RangeUtils.java
/**
 * 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);
}
 
源代码14 项目: attic-apex-malhar   文件: PhoneEntryOperator.java
/**
 * 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();
}
 
源代码15 项目: mzmine3   文件: RangeUtils.java
public static double rangeLength(Range<Double> range) {
  return range.upperEndpoint() - range.lowerEndpoint();
}
 
源代码16 项目: javaide   文件: JavaOutput.java
@Override
public void append(String text, Range<Integer> range) {
    if (!range.isEmpty()) {
        boolean sawNewlines = false;
        // Skip over input line we've passed.
        int iN = javaInput.getLineCount();
        while (iLine < iN
                && (javaInput.getRange1s(iLine).isEmpty()
                || javaInput.getRange1s(iLine).upperEndpoint() <= range.lowerEndpoint())) {
            if (javaInput.getRanges(iLine).isEmpty()) {
                // Skipped over a blank line.
                sawNewlines = true;
            }
            ++iLine;
        }
  /*
   * Output blank line if we've called {@link OpsBuilder#blankLine}{@code (true)} here, or if
   * there's a blank line here and it's a comment.
   */
        BlankLineWanted wanted = firstNonNull(blankLines.get(lastK), BlankLineWanted.NO);
        if (isComment(text) ? sawNewlines : wanted.wanted().or(sawNewlines)) {
            ++newlinesPending;
        }
    }
    if (Newlines.isNewline(text)) {
  /*
   * Don't update range information, and swallow extra newlines. The case below for '\n' is for
   * block comments.
   */
        if (newlinesPending == 0) {
            ++newlinesPending;
        }
        spacesPending = 0;
    } else {
        boolean range0sSet = false;
        boolean rangesSet = false;
        int textN = text.length();
        for (int i = 0; i < textN; i++) {
            char c = text.charAt(i);
            switch (c) {
                case ' ':
                    ++spacesPending;
                    break;
                case '\r':
                    if (i + 1 < text.length() && text.charAt(i + 1) == '\n') {
                        i++;
                    }
                    // falls through
                case '\n':
                    spacesPending = 0;
                    ++newlinesPending;
                    break;
                default:
                    while (newlinesPending > 0) {
                        // drop leading blank lines
                        if (!mutableLines.isEmpty() || lineBuilder.length() > 0) {
                            mutableLines.add(lineBuilder.toString());
                        }
                        lineBuilder = new StringBuilder();
                        rangesSet = false;
                        --newlinesPending;
                    }
                    while (spacesPending > 0) {
                        lineBuilder.append(' ');
                        --spacesPending;
                    }
                    lineBuilder.append(c);
                    if (!range.isEmpty()) {
                        if (!range0sSet) {
                            if (!range.isEmpty()) {
                                while (range0s.size() <= mutableLines.size()) {
                                    range0s.add(Formatter.EMPTY_RANGE);
                                }
                                range0s.set(mutableLines.size(), union(range0s.get(mutableLines.size()), range));
                                range0sSet = true;
                            }
                        }
                        if (!rangesSet) {
                            while (ranges.size() <= mutableLines.size()) {
                                ranges.add(Formatter.EMPTY_RANGE);
                            }
                            ranges.set(mutableLines.size(), union(ranges.get(mutableLines.size()), range));
                            rangesSet = true;
                        }
                    }
            }
        }
        // TODO(jdd): Move others down here. Use common method for these.
        if (!range.isEmpty()) {
            while (range1s.size() <= mutableLines.size()) {
                range1s.add(Formatter.EMPTY_RANGE);
            }
            range1s.set(mutableLines.size(), union(range1s.get(mutableLines.size()), range));
        }
    }
    if (!range.isEmpty()) {
        lastK = range.upperEndpoint();
    }
}
 
源代码17 项目: mzmine3   文件: RangeUtils.java
public static double rangeCenter(Range<Double> range) {
  return (range.upperEndpoint() + range.lowerEndpoint()) / 2.0;
}
 
源代码18 项目: mzmine3   文件: XYBlockPixelSizePaintScales.java
public static Paint[] getPaintColors(String zAxisScaleType, Range<Double> zScaleRange,
    String paintScaleStyle) {
  Paint[] scale = null;
  // lower and upper bound
  if (zAxisScaleType.contains("percentile") && zScaleRange.lowerEndpoint() != 0
      && zScaleRange.upperEndpoint() != 100) {
    if (paintScaleStyle.contains("Rainbow")) {
      scale = getFullRainBowScaleLowerUpperBound();
    } else if (paintScaleStyle.contains("red")) {
      scale = getRedScaleLowerUpperBound();
    } else if (paintScaleStyle.contains("green")) {
      scale = getGreenScaleLowerUpperBound();
    } else if (paintScaleStyle.contains("yellow")) {
      scale = getYellowScaleLowerUpperBound();
    } else if (paintScaleStyle.contains("cyan")) {
      scale = getCyanScaleLowerUpperBound();
    }

  }
  // lower bound
  else if (zAxisScaleType.contains("percentile") && zScaleRange.lowerEndpoint() != 0
      && zScaleRange.upperEndpoint() == 100) {
    if (paintScaleStyle.contains("Rainbow")) {
      scale = getFullRainBowScaleLowerBound();
    } else if (paintScaleStyle.contains("red")) {
      scale = getRedScaleLowerBound();
    } else if (paintScaleStyle.contains("green")) {
      scale = getGreenScaleLowerBound();
    } else if (paintScaleStyle.contains("yellow")) {
      scale = getYellowScaleLowerBound();
    } else if (paintScaleStyle.contains("cyan")) {
      scale = getCyanScaleLowerBound();
    }
  }
  // upper bound
  else if (zAxisScaleType.contains("percentile") && zScaleRange.lowerEndpoint() == 0
      && zScaleRange.upperEndpoint() != 100) {
    if (paintScaleStyle.contains("Rainbow")) {
      scale = getFullRainBowScaleUpperBound();
    } else if (paintScaleStyle.contains("red")) {
      scale = getRedScaleUpperBound();
    } else if (paintScaleStyle.contains("green")) {
      scale = getGreenScaleUpperBound();
    } else if (paintScaleStyle.contains("yellow")) {
      scale = getYellowScaleUpperBound();
    } else if (paintScaleStyle.contains("cyan")) {
      scale = getCyanScaleUpperBound();
    }
  }
  // no bound
  else {
    if (paintScaleStyle.contains("Rainbow")) {
      scale = getFullRainBowScale();
    } else if (paintScaleStyle.contains("red")) {
      scale = getRedScale();
    } else if (paintScaleStyle.contains("green")) {
      scale = getGreenScale();
    } else if (paintScaleStyle.contains("yellow")) {
      scale = getYellowScale();
    } else if (paintScaleStyle.contains("cyan")) {
      scale = getCyanScale();
    }
  }
  return scale;
}
 
源代码19 项目: pulsar   文件: ConcurrentOpenLongPairRangeSet.java
public void remove(Range<LongPair> range) {
    LongPair lowerEndpoint = range.hasLowerBound() ? range.lowerEndpoint() : LongPair.earliest;
    LongPair upperEndpoint = range.hasUpperBound() ? range.upperEndpoint() : LongPair.latest;

    long lower = (range.hasLowerBound() && range.lowerBoundType().equals(BoundType.CLOSED))
            ? getSafeEntry(lowerEndpoint)
            : getSafeEntry(lowerEndpoint) + 1;
    long upper = (range.hasUpperBound() && range.upperBoundType().equals(BoundType.CLOSED))
            ? getSafeEntry(upperEndpoint)
            : getSafeEntry(upperEndpoint) - 1;

    // if lower-bound is not set then remove all the keys less than given upper-bound range
    if (lowerEndpoint.equals(LongPair.earliest)) {
        // remove all keys with
        rangeBitSetMap.forEach((key, set) -> {
            if (key < upperEndpoint.getKey()) {
                rangeBitSetMap.remove(key);
            }
        });
    }

    // if upper-bound is not set then remove all the keys greater than given lower-bound range
    if (upperEndpoint.equals(LongPair.latest)) {
        // remove all keys with
        rangeBitSetMap.forEach((key, set) -> {
            if (key > lowerEndpoint.getKey()) {
                rangeBitSetMap.remove(key);
            }
        });
    }

    // remove all the keys between two endpoint keys
    rangeBitSetMap.forEach((key, set) -> {
        if (lowerEndpoint.getKey() == upperEndpoint.getKey()) {
            set.clear((int) lower, (int) upper + 1);
        } else {
            // eg: remove-range: [(3,5) - (5,5)] -> Delete all items from 3,6->3,N,4.*,5,0->5,5
            if (key == lowerEndpoint.getKey()) {
                // remove all entries from given position to last position
                set.clear((int) lower, set.previousSetBit(set.size()));
            } else if (key == upperEndpoint.getKey()) {
                // remove all entries from 0 to given position
                set.clear(0, (int) upper + 1);
            } else if (key > lowerEndpoint.getKey() && key < upperEndpoint.getKey()) {
                rangeBitSetMap.remove(key);
            }
        }
        // remove bit-set if set is empty
        if (set.isEmpty()) {
            rangeBitSetMap.remove(key);
        }
    });

    updatedAfterCachedForSize = true;
    updatedAfterCachedForToString = true;
}
 
源代码20 项目: mzmine2   文件: TwoDDataSet.java
ArrayList getCentroidedDataPointsInRTMZRange(Range<Double> rtRange, Range<Double> mzRange) {
  ArrayList<DataPoint> dataPointsInRanges = new ArrayList<DataPoint>();
  ArrayList rtInRange = new ArrayList();

  curMaxIntensity = 0.0;

  double searchRetentionTimes[] = retentionTimes;

  if (processedScans < totalScans) {
    searchRetentionTimes = new double[processedScans];
    System.arraycopy(retentionTimes, 0, searchRetentionTimes, 0, searchRetentionTimes.length);
  }

  // Find the rt of the scan at the bottom of our rtRange
  int startScanIndex = Arrays.binarySearch(searchRetentionTimes, rtRange.lowerEndpoint());


  // a couple of checks
  if (startScanIndex < 0) {
    startScanIndex = (startScanIndex * -1) - 1;
  }

  if (startScanIndex >= searchRetentionTimes.length) {
    startScanIndex = 0;
  }



  // With this we can grab the data points from the scans we want using dataPointMatrix

  for (int scanIndex = startScanIndex; ((scanIndex < searchRetentionTimes.length)
      && (searchRetentionTimes[scanIndex] <= rtRange.upperEndpoint())); scanIndex++) {
    // get the list of data points
    DataPoint dataPoints[] = dataPointMatrix[scanIndex].get();
    // Binary search for the mz values in the range you want

    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)
      startMZIndex = 0;

    for (int mzIndex = startMZIndex; ((mzIndex < dataPoints.length)
        && (dataPoints[mzIndex].getMZ() <= mzRange.upperEndpoint())); mzIndex++) {

      DataPoint curFoundDataPoint;
      curFoundDataPoint = dataPoints[mzIndex];

      // System.out.println("curFoundDataPoint.getMZ()");
      // System.out.println(curFoundDataPoint.getMZ());

      dataPointsInRanges.add(curFoundDataPoint);
      Double toAddRt = new Double(searchRetentionTimes[scanIndex]);
      rtInRange.add(toAddRt);

      double curIntensity = curFoundDataPoint.getIntensity();


      if (curIntensity > curMaxIntensity)
        curMaxIntensity = curIntensity;


    }

  }
  rtValuesInUserRange = rtInRange;

  return dataPointsInRanges;
}