List of usage examples for com.google.common.collect Range upperEndpoint
public C upperEndpoint()
From source file:net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.databases.HMDBGateway.java
public String[] findCompounds(double mass, MZTolerance mzTolerance, int numOfResults, ParameterSet parameters) throws IOException { Range<Double> toleranceRange = mzTolerance.getToleranceRange(mass); String queryAddress = hmdbSeachAddress + "&query_from=" + toleranceRange.lowerEndpoint() + "&query_to=" + toleranceRange.upperEndpoint(); URL queryURL = new URL(queryAddress); // Submit the query 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("metabolites/(HMDB[0-9]{5})"); Matcher matcher = pat.matcher(queryResult); while (matcher.find()) { String hmdbID = matcher.group(1); results.add(hmdbID);//from ww w . j ava2 s .c o m } // 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 HDMB 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]); }
From source file:com.rockhoppertech.music.series.time.TimeEvent.java
public boolean overlaps(TimeEvent te) { // boolean b = this.getRange().overlaps(te.getRange()); boolean b = false; Range<Double> range1 = this.getOpenRange(); Range<Double> range2 = te.getOpenRange(); if (range1.contains(range2.lowerEndpoint()) || range1.contains(range2.upperEndpoint())) { b = true;/*from w ww. j a v a 2 s . c o m*/ } logger.debug(String.format("overlaps %b %s %s", b, this.getOpenRange(), te.getOpenRange())); return b; }
From source file:io.github.msdk.rawdata.filters.ResampleFilterAlgorithm.java
/** {@inheritDoc} */ @Override//from w w w. ja va2s. c om public MsScan performFilter(@Nonnull MsScan scan) { // Load data points mzBuffer = scan.getMzValues(mzBuffer); intensityBuffer = scan.getIntensityValues(intensityBuffer); numOfDataPoints = scan.getNumberOfDataPoints(); newNumOfDataPoints = 0; Range<Double> mzRange = scan.getMzRange(); if (mzRange == null) { MsScan result = MsScanUtil.clone(store, scan, true); return result; } if (binSize > mzRange.upperEndpoint()) { this.binSize = (int) Math.round(mzRange.upperEndpoint()); } int numberOfBins = (int) Math.round((mzRange.upperEndpoint() - mzRange.lowerEndpoint()) / binSize); if (numberOfBins <= 0) { numberOfBins++; } // Create the array with the intensity values for each bin Float[] newY = new Float[numberOfBins]; int intVal = 0; for (int i = 0; i < numberOfBins; i++) { newY[i] = 0.0f; int pointsInTheBin = 0; for (int j = 0; j < binSize; j++) { if (intVal < numOfDataPoints) { newY[i] += intensityBuffer[intVal++]; pointsInTheBin++; } } newY[i] /= pointsInTheBin; } // Set the new m/z value in the middle of the bin double newX = mzRange.lowerEndpoint() + binSize / 2.0; // Creates new DataPoints for (Float newIntensity : newY) { mzBuffer[newNumOfDataPoints] = newX; intensityBuffer[newNumOfDataPoints] = newIntensity; newNumOfDataPoints++; newX += binSize; } // Return a new scan with the new data points MsScan result = MsScanUtil.clone(store, scan, false); result.setDataPoints(mzBuffer, intensityBuffer, newNumOfDataPoints); return result; }
From source file:org.pascani.dsl.dbmapper.databases.ElasticSearch.java
private Map<String, String> handle(ChangeEvent e) { 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(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(e, taggedValue.value(), taggedValue.tags()); } else {/*from w w w. j a v a 2 s . c o 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:li.klass.fhem.activities.graph.YAxis.java
public YAxis(Context context, GPlotAxis axis, String label) { this.context = context; this.label = label; Range<Double> range = axis.getRange().or(Range.range(-1d, BoundType.OPEN, 1d, BoundType.OPEN)); if (range.hasLowerBound()) { minimumY = range.lowerEndpoint(); }//from www. jav a 2 s.co m if (range.hasUpperBound()) { maximumY = range.upperEndpoint(); } }
From source file:org.apache.brooklyn.location.jclouds.networking.SharedLocationSecurityGroupCustomizer.java
private Function<Range<Integer>, IpPermission> portRangeToPermission( final JcloudsLocationSecurityGroupCustomizer instance, final IpProtocol protocol) { return new Function<Range<Integer>, IpPermission>() { @Nullable/*from w ww .java 2s . c om*/ @Override public IpPermission apply(@Nullable Range<Integer> integerRange) { IpPermission extraPermission = IpPermission.builder().fromPort(integerRange.lowerEndpoint()) .toPort(integerRange.upperEndpoint()).ipProtocol(protocol) .cidrBlock(instance.getBrooklynCidrBlock()).build(); return extraPermission; } }; }
From source file:org.robotframework.red.nattable.painter.RedTableTextPainter.java
private Stream<Range<Integer>> splitRangesForWrappedLabel(final int[] map, final String text, final Range<Integer> range) { final int lower = range.lowerEndpoint(); final int upper = range.upperEndpoint() - 1; final int lowerEndpoint = map[lower] == -1 ? map[lower + 1] : map[lower]; final int upperEndpoint = map[upper] == -1 ? map[upper - 1] : map[upper]; final List<Range<Integer>> transformedRanges = new ArrayList<>(); if (lowerEndpoint <= upperEndpoint) { final Matcher matcher = NEW_LINE_PATTERN.matcher(text.substring(lowerEndpoint, upperEndpoint + 1)); int lastLower = lowerEndpoint; while (matcher.find()) { transformedRanges.add(Range.closedOpen(lastLower, matcher.start() + lowerEndpoint)); lastLower = matcher.end() + lowerEndpoint; }//from w w w .ja va2s .c o m transformedRanges.add(Range.closedOpen(lastLower, upperEndpoint + 1)); } return transformedRanges.stream(); }
From source file:com.yahoo.gondola.container.client.ZookeeperShardManagerClient.java
@Override public void rollbackBuckets(Range<Integer> splitRange) throws ShardManagerException, InterruptedException { sendActionToAll(MIGRATE_ROLLBACK, splitRange.lowerEndpoint(), splitRange.upperEndpoint()); if (!waitCondition(null, ZookeeperStat::isNormalOperational, 3000)) { throw new ShardManagerException(FAILED_BUCKET_ROLLBACK, "timed out"); }// w ww.j a v a 2s . co m sendActionToAll(NOOP); }
From source file:edu.cmu.lti.oaqa.framework.eval.passage.PassageMAPEvalAggregator.java
private float getAvgPsgMAP(List<Passage> docs, List<Passage> gs) { if (gs.size() == 0) { return 0; }/*from ww w . j av a 2s . co m*/ int totalChars = 0; int overlapLength = 0; float sumPrecision = 0; int count = 0; Set<Passage> foundGoldTriplets = Sets.newHashSet(); for (Passage doc : docs) { Range<Integer> docRange = Range.closedOpen(doc.getBegin(), doc.getEnd()); totalChars += docRange.upperEndpoint() - docRange.lowerEndpoint(); for (Passage g : gs) { if (!g.getUri().equals(doc.getUri())) continue; Range<Integer> gRange = Range.closedOpen(g.getBegin(), g.getEnd()); if (!docRange.isConnected(gRange)) { continue; } Range<Integer> overlap = docRange.intersection(gRange); if (overlap.isEmpty()) { continue; } overlapLength += overlap.upperEndpoint() - overlap.lowerEndpoint(); sumPrecision += (float) overlapLength / (float) totalChars; count++; foundGoldTriplets.add(g); break; } } int numZeros = Sets.difference(Sets.newHashSet(gs), foundGoldTriplets).size(); return (float) sumPrecision / (float) (count + numZeros); }
From source file:com.basistech.tclre.RuntimeColorMap.java
private void computeBmp(RangeMap<Integer, Short> fullMap) { for (Map.Entry<Range<Integer>, Short> me : fullMap.asMapOfRanges().entrySet()) { Range<Integer> range = me.getKey(); int min = range.lowerEndpoint(); if (range.lowerBoundType() == BoundType.OPEN) { min++;//from w ww .j av a 2 s . c o m } if (min < Character.MAX_VALUE) { int rmax = range.upperEndpoint(); if (range.upperBoundType() == BoundType.OPEN) { rmax--; } int max = Math.min(Character.MAX_VALUE, rmax); for (int x = min; x <= max; x++) { this.bmpMap[x] = me.getValue(); } } } }