List of usage examples for com.google.common.collect Range lowerEndpoint
public C lowerEndpoint()
From source file:com.google.eclipse.protobuf.validation.ProtobufJavaValidator.java
private String rangeToString(Range<Long> range) { if (range.hasLowerBound() && range.hasUpperBound() && range.lowerEndpoint() == range.upperEndpoint()) { return String.valueOf(range.lowerEndpoint()); }//w w w . j av a 2 s . co m String upper = range.hasUpperBound() ? String.valueOf(range.upperEndpoint()) : indexRanges.getMaxKeyword(); return String.format("%d to %s", range.lowerEndpoint(), upper); }
From source file:com.helion3.prism.storage.mongodb.MongoRecords.java
/** * Recursive method of building condition documents. * * @param fieldsOrGroups List<Condition> * @return Document//from w w w . j a va2s.c o m */ private Document buildConditions(List<Condition> fieldsOrGroups) { Document conditions = new Document(); for (Condition fieldOrGroup : fieldsOrGroups) { if (fieldOrGroup instanceof ConditionGroup) { ConditionGroup group = (ConditionGroup) fieldOrGroup; Document subdoc = buildConditions(group.getConditions()); if (group.getOperator().equals(Operator.OR)) { conditions.append("$or", subdoc); } else { conditions.putAll(subdoc); } } else { FieldCondition field = (FieldCondition) fieldOrGroup; // Match an array of items if (field.getValue() instanceof List) { String matchRule = field.getMatchRule().equals(MatchRule.INCLUDES) ? "$in" : "$nin"; conditions.put(field.getFieldName().toString(), new Document(matchRule, field.getValue())); } else if (field.getMatchRule().equals(MatchRule.EQUALS)) { conditions.put(field.getFieldName().toString(), field.getValue()); } else if (field.getMatchRule().equals(MatchRule.GREATER_THAN_EQUAL)) { conditions.put(field.getFieldName().toString(), new Document("$gte", field.getValue())); } else if (field.getMatchRule().equals(MatchRule.LESS_THAN_EQUAL)) { conditions.put(field.getFieldName().toString(), new Document("$lte", field.getValue())); } else if (field.getMatchRule().equals(MatchRule.BETWEEN)) { if (!(field.getValue() instanceof Range)) { throw new IllegalArgumentException("\"Between\" match value must be a Range."); } Range<?> range = (Range<?>) field.getValue(); Document between = new Document("$gte", range.lowerEndpoint()).append("$lte", range.upperEndpoint()); conditions.put(field.getFieldName().toString(), between); } } } return conditions; }
From source file:org.sonatype.nexus.repository.partial.PartialFetchHandler.java
/** * Mutate the response into one that returns part of the payload. *//*from w ww.ja v a 2 s. c om*/ private PayloadResponse partialResponse(final PayloadResponse response, final Payload payload, final Range requestedRange) { response.setStatus(Status.success(HttpStatus.PARTIAL_CONTENT)); final Range<Long> rangeToSend = requestedRange; Payload partialPayload = new PartialPayload(payload, rangeToSend); response.setPayload(partialPayload); final Headers responseHeaders = response.getHeaders(); // ResponseSender takes care of Content-Length header, via payload.size responseHeaders.set(HttpHeaders.CONTENT_RANGE, rangeToSend.lowerEndpoint() + "-" + rangeToSend.upperEndpoint() + "/" + payload.getSize()); return response; }
From source file:li.klass.fhem.activities.graph.ChartingActivity.java
private void setRangeFor(Optional<Range<Double>> axisRange, com.github.mikephil.charting.components.YAxis axis) { if (axisRange.isPresent()) { Range<Double> range = axisRange.get(); if (range.hasLowerBound()) { axis.setAxisMinValue(range.lowerEndpoint().floatValue()); }//from w ww . jav a 2s .co m if (range.hasUpperBound()) { axis.setAxisMinValue(range.upperEndpoint().floatValue()); } } }
From source file:net.sf.mzmine.modules.visualization.tic.TICVisualizerWindow.java
/** *//*from w w w . j a v a 2s . com*/ public void setRTRange(Range<Double> rtRange) { ticPlot.getXYPlot().getDomainAxis().setRange(rtRange.lowerEndpoint(), rtRange.upperEndpoint()); }
From source file:org.mskcc.shenkers.control.track.gene.GTFGeneModelProvider.java
private void createGtfBgz(File gtf_file, File gtf_bgz_file) throws IOException { logger.info("reading {}", gtf_file.getAbsolutePath()); AbstractFeatureReader<GTFContext, LineIterator> afr = AbstractFeatureReader .getFeatureReader(gtf_file.getAbsolutePath(), codec, false); CloseableTribbleIterator<GTFContext> iterator = afr.iterator(); List<GTFContext> gtf = new ArrayList<>(); while (iterator.hasNext()) { GTFContext next = iterator.next(); gtf.add(next);//from w w w .java2 s. com } ImmutableListMultimap<String, GTFContext> transcript_id_multimap = Multimaps.index(gtf.iterator(), GTFContext::getTranscriptId); logger.info("adding transcript ranges"); gtf.addAll(transcript_id_multimap.keySet().stream().map(key -> { System.out.println(key); ImmutableList<GTFContext> contexts = transcript_id_multimap.get(key); Range<Integer> span = contexts.stream().map(c -> Range.closed(c.getStart(), c.getEnd())) .collect(new RangeSetCollector()).span(); GTFContext context = new GTFContext(contexts.get(0).getChr(), span.lowerEndpoint(), span.upperEndpoint()); context.setFeature("transcript"); context.setFrame("."); context.setName("."); context.setScore("."); context.setSource("."); context.setStrand('.'); context.setAttributes(String.format("transcript_id \"%s\";", key)); return context; }).collect(Collectors.toList())); logger.info("sorting"); Collections.sort(gtf, new CoordinateOrderComparator()); logger.info("writing to compressed output stream"); BlockCompressedOutputStream os = new BlockCompressedOutputStream(gtf_bgz_file); Writer w = new OutputStreamWriter(os); for (GTFContext feature : gtf) { w.write(codec.encodeToString(feature)); } w.close(); }
From source file:io.github.mzmine.modules.plots.msspectrum.datasets.MsSpectrumDataSet.java
public String getDescription() { StringBuilder sb = new StringBuilder(); if (spectrum instanceof MsScan) { MsScan scan = (MsScan) spectrum; String scanDesc = MsScanUtils.createFullMsScanDescription(scan); sb.append(scanDesc);/*from www . j a v a 2s . com*/ } NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); sb.append("Spectrum type: "); sb.append(spectrum.getSpectrumType()); sb.append("\n"); sb.append("Number of data points: "); sb.append(numOfDataPoints); sb.append("\n"); Range<Double> mzRange = spectrum.getMzRange(); if (mzRange != null) { sb.append("m/z range: "); sb.append(mzFormat.format(mzRange.lowerEndpoint())); sb.append(" - "); sb.append(mzFormat.format(mzRange.upperEndpoint())); sb.append(" m/z\n"); } sb.append("Base peak intensity: "); sb.append(intensityFormat.format(topIndensity)); sb.append("\n"); sb.append("SPLASH ID: "); String splash = SplashCalculationAlgorithm.calculateSplash(spectrum); sb.append(splash); return sb.toString(); }
From source file:com.google.errorprone.bugpatterns.javadoc.UnescapedEntity.java
private RangeSet<Integer> fixGenerics(RangeSet<Integer> generics, RangeSet<Integer> preTags, RangeSet<Integer> dontEmitCodeFix, VisitorState state) { RangeSet<Integer> emittedFixes = TreeRangeSet.create(); for (Range<Integer> range : generics.asRanges()) { if (emittedFixes.intersects(range) || dontEmitCodeFix.intersects(range)) { continue; }//from w w w. j ava 2 s.co m Range<Integer> regionToWrap = preTags.rangeContaining(range.lowerEndpoint()); if (regionToWrap == null) { regionToWrap = range; } emittedFixes.add(regionToWrap); state.reportMatch( buildDescription(getDiagnosticPosition(range.lowerEndpoint(), state.getPath().getLeaf())) .setMessage( "This looks like a type with type parameters. The < and > characters here will " + "be interpreted as HTML, which can be avoided by wrapping it in a " + "{@code } tag.") .addFix(wrapInCodeTag(regionToWrap)).build()); } return emittedFixes; }
From source file:io.github.msdk.rawdata.filters.ResampleFilterAlgorithm.java
/** {@inheritDoc} */ @Override/*from ww w . jav a2 s . co m*/ 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:com.basistech.tclre.ColorMap.java
/** * subrange - allocate new subcolors to this range of chars, fill in arcs. * The range will overlap existing ranges; even in the simplest case, * it will overlap the initial WHITE range. For each existing range that * it overlaps, allocate a new color, mark the range as mapping to that color, * and add an arc between the states for that color. */// ww w. j a v a 2 s. co m void subrange(int from, int to, State lp, State rp) throws RegexException { /* Avoid one call to map.get() for each character in the range. * This map will usually contain one item, but in complex cases more. * For example, if we had [a-f][g-h] and then someone asked for [f-g], there * would be two. Each of these new ranges will get a new color via subcolor. */ Map<Range<Integer>, Short> curColors = map.subRangeMap(Range.closed(from, to)).asMapOfRanges(); /* * To avoid concurrent mod problems, we need to copy the ranges we are working from. */ List<Range<Integer>> ranges = Lists.newArrayList(curColors.keySet()); for (Range<Integer> rangeToProcess : ranges) { // bound management here irritating. int start = rangeToProcess.lowerEndpoint(); if (rangeToProcess.lowerBoundType() == BoundType.OPEN) { start++; } int end = rangeToProcess.upperEndpoint(); if (rangeToProcess.upperBoundType() == BoundType.CLOSED) { end++; } // allocate a new subcolor and account it owning the entire range. short color = subcolor(start, end - start); compiler.getNfa().newarc(Compiler.PLAIN, color, lp, rp); } }