List of usage examples for com.google.common.collect Range upperEndpoint
public C upperEndpoint()
From source file:org.apache.drill.exec.record.RecordIterator.java
public void reset() { if (!enableMarkAndReset) { throw new UnsupportedOperationException("mark and reset disabled for this RecordIterator"); }//w ww . j av a 2 s.co m if (markedOuterPosition >= 0) { // Move to rbd for markedOuterPosition. final RecordBatchData rbdNew = batches.get(markedOuterPosition); final RecordBatchData rbdOld = batches.get(startBatchPosition); assert rbdOld != null; assert rbdNew != null; if (rbdNew != rbdOld) { container.transferOut(rbdOld.getContainer()); container.transferIn(rbdNew.getContainer()); } innerPosition = markedInnerPosition; outerPosition = markedOuterPosition; final Range<Long> markedBatchRange = batches.getEntry(outerPosition).getKey(); startBatchPosition = markedBatchRange.lowerEndpoint(); innerRecordCount = (int) (markedBatchRange.upperEndpoint() - startBatchPosition); markedInnerPosition = -1; markedOuterPosition = -1; } }
From source file:net.sf.mzmine.modules.visualization.tic.TICVisualizerWindow.java
/** *///from w ww . j ava 2 s . c o m public void setRTRange(Range<Double> rtRange) { ticPlot.getXYPlot().getDomainAxis().setRange(rtRange.lowerEndpoint(), rtRange.upperEndpoint()); }
From source file:org.sonatype.nexus.repository.partial.PartialFetchHandler.java
/** * Mutate the response into one that returns part of the payload. *///ww w .ja v a2 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:com.b2international.snowowl.snomed.core.ecl.SnomedEclRefinementEvaluator.java
static Function<Collection<Property>, Collection<Property>> filterByCardinality( final boolean grouped, final Range<Long> groupCardinality, final Range<Long> cardinality, final Function<Property, Object> idProvider) { return matchingProperties -> { final Multimap<Object, Property> propertiesByMatchingIds = Multimaps.index(matchingProperties, idProvider);/* w w w .j a v a 2 s . c o m*/ final Collection<Property> properties = newHashSet(); final Range<Long> allowedRelationshipCardinality; if (grouped) { final long minRelationships = groupCardinality.lowerEndpoint() == 0 ? cardinality.lowerEndpoint() : groupCardinality.lowerEndpoint() * cardinality.lowerEndpoint(); final long maxRelationships; if (groupCardinality.hasUpperBound() && cardinality.hasUpperBound()) { if (groupCardinality.upperEndpoint() == Long.MAX_VALUE || cardinality.upperEndpoint() == Long.MAX_VALUE) { maxRelationships = Long.MAX_VALUE; } else { maxRelationships = groupCardinality.upperEndpoint() * cardinality.upperEndpoint(); } } else { // group and relationship cardinalities are unbounded maxRelationships = Long.MAX_VALUE; } allowedRelationshipCardinality = Range.closed(minRelationships, maxRelationships); } else { allowedRelationshipCardinality = cardinality; } for (Object matchingConceptId : propertiesByMatchingIds.keySet()) { final Collection<Property> propertiesOfConcept = propertiesByMatchingIds.get(matchingConceptId); if (allowedRelationshipCardinality.contains((long) propertiesOfConcept.size())) { if (grouped) { final Multimap<Integer, Property> indexedByGroup = FluentIterable.from(propertiesOfConcept) .index(Property::getGroup); // if groups should be considered as well, then check group numbers in the matching sets // check that the concept has at least the right amount of groups final Multimap<Integer, Property> validGroups = ArrayListMultimap.create(); for (Integer group : indexedByGroup.keySet()) { final Collection<Property> groupedRelationships = indexedByGroup.get(group); if (cardinality.contains((long) groupedRelationships.size())) { validGroups.putAll(group, groupedRelationships); } } if (groupCardinality.contains((long) validGroups.keySet().size())) { properties.addAll(validGroups.values()); } } else { properties.addAll(propertiesOfConcept); } } } return properties; }; }
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);// w ww . j a va2s .c om } 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: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 v a2 s . co 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:com.google.android.apps.forscience.whistlepunk.GraphPopulator.java
private Range<Long> getEffectiveAddedRange(TimeRange requested, Range<Long> returned) { if (returned == null) { return requested.getTimes().canonical(DiscreteDomain.longs()); }//w ww.ja v a 2s.co m switch (requested.getOrder()) { case NEWEST_FIRST: return Range.closed(returned.lowerEndpoint(), requested.getTimes().upperEndpoint()); case OLDEST_FIRST: return Range.closed(requested.getTimes().lowerEndpoint(), returned.upperEndpoint()); default: throw new IllegalArgumentException("Unexpected value for enum: " + requested.getOrder()); } }
From source file:com.giaybac.traprange.extractor.PDFTableExtractor.java
/** * * Remove all texts in excepted lines/* www . j a v a2 s. c o m*/ * * TexPositions are sorted by .getY() ASC * * @param lineRanges * @param textPositions * @return */ private List<TextPosition> getTextsByLineRanges(List<Range<Integer>> lineRanges, List<TextPosition> textPositions) { List<TextPosition> retVal = new ArrayList<>(); int idx = 0; int lineIdx = 0; while (idx < textPositions.size() && lineIdx < lineRanges.size()) { TextPosition textPosition = textPositions.get(idx); Range<Integer> textRange = Range.closed((int) textPosition.getY(), (int) (textPosition.getY() + textPosition.getHeight())); Range<Integer> lineRange = lineRanges.get(lineIdx); if (lineRange.encloses(textRange)) { retVal.add(textPosition); idx++; } else if (lineRange.upperEndpoint() < textRange.lowerEndpoint()) { lineIdx++; } else { idx++; } } //return return retVal; }
From source file:com.comphenix.protocol.RangeParser.java
/** * Parse ranges from an array of elements. * @param args - array of elements./*from ww w. j a v a2 s . c o m*/ * @param offset - beginning offset. * @param lastIndex - the last index of the array to read. * @param legalRange - range of legal values. * @return The parsed ranges. */ public static List<Range<Integer>> getRanges(Deque<String> input, Range<Integer> legalRange) { List<String> tokens = tokenizeInput(input); List<Range<Integer>> ranges = new ArrayList<Range<Integer>>(); for (int i = 0; i < tokens.size(); i++) { Range<Integer> range; String current = tokens.get(i); String next = i + 1 < tokens.size() ? tokens.get(i + 1) : null; // Yoda equality is done for null-safety if ("-".equals(current)) { throw new IllegalArgumentException("A hyphen must appear between two numbers."); } else if ("-".equals(next)) { if (i + 2 >= tokens.size()) throw new IllegalArgumentException("Cannot form a range without a upper limit."); // This is a proper range range = Range.closed(Integer.parseInt(current), Integer.parseInt(tokens.get(i + 2))); ranges.add(range); // Skip the two next tokens i += 2; } else { // Just a single number range = Range.singleton(Integer.parseInt(current)); ranges.add(range); } // Validate ranges if (!legalRange.encloses(range)) { throw new IllegalArgumentException(range + " is not in the range " + range.toString()); } } return simplify(ranges, legalRange.upperEndpoint()); }
From source file:com.github.msdevkit.datamodel.impl.SpectrumImpl.java
@Override @Nonnull// w w w . j a v a2s. c om public DataPoint[] getDataPointsByMass(@Nonnull Range<Double> mzRange) { final 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; }