List of usage examples for com.google.common.collect Range closed
public static <C extends Comparable<?>> Range<C> closed(C lower, C upper)
From source file:com.giaybac.traprange.extractor.PDFTableExtractor.java
/** * * Remove all texts in excepted lines/*from w w w . j a v a2s . 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:edu.mit.streamjit.impl.compiler2.Storage.java
/** * Returns a range spanning the indices read from this storage during an * execution of the given schedule. (Note that, as a span, not every * contained index will be read.) The returned range will be * {@link Range#canonical(com.google.common.collect.DiscreteDomain) canonical}. * The range is not cached so as to be responsive to changes in input index * functions./*from ww w. java2s. co m*/ * @param externalSchedule the schedule * @return a range spanning the indices read during the given schedule under * the current index functions * @see #readIndices(java.util.Map) */ public Range<Integer> readIndexSpan(Map<ActorGroup, Integer> externalSchedule) { int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE; for (Actor a : downstream()) { int maxIteration = a.group().schedule().get(a) * externalSchedule.get(a.group()) - 1; if (maxIteration >= 0) for (int input = 0; input < a.inputs().size(); ++input) if (a.inputs().get(input).equals(this) && (a.peek(input).max() > 0 || a.pop(input).max() > 0)) { min = Math.min(min, a.translateInputIndex(input, a.peeks(input, 0).first())); max = Math.max(max, a.translateInputIndex(input, a.peeks(input, maxIteration).last())); } } Range<Integer> range = (min != Integer.MAX_VALUE ? Range.closed(min, max) : Range.closedOpen(0, 0)); return range.canonical(DiscreteDomain.integers()); }
From source file:com.giaybac.traprange.extractor.PDFTableExtractor.java
/** * @param texts// w w w. jav a 2 s.c om * @return */ private List<Range<Integer>> getColumnRanges(Collection<TextPosition> texts) { TrapRangeBuilder rangesBuilder = new TrapRangeBuilder(); for (TextPosition text : texts) { Range<Integer> range = Range.closed((int) text.getX(), (int) (text.getX() + text.getWidth())); rangesBuilder.addRange(range); } return rangesBuilder.build(); }
From source file:org.onosproject.driver.optical.power.OplinkPowerConfigUtil.java
/** * Returns the input port power range./*from w w w . ja v a2 s . co m*/ * * @param portNum the port number * @return power range */ private Range<Long> getInputPortPowerRange(PortNumber portNum) { OpenFlowSwitch ofs = getOpenFlowDevice(); if (ofs == null) { return null; } PortDescType portType = getPortDescType((OpenFlowOpticalSwitch) ofs, portNum); Type devType = ofs.deviceType(); // FIXME // Short time hard code. // The port type and power range will be obtained from physical device in the future. switch (devType) { case OPTICAL_AMPLIFIER: if (portType == PortDescType.PA_LINE_IN) { return Range.closed(EDFA_POWER_IN_WEST_LOW_THRES, EDFA_POWER_IN_WEST_HIGH_THRES); } else if (portType == PortDescType.BA_LINE_IN) { return Range.closed(EDFA_POWER_IN_EAST_LOW_THRES, EDFA_POWER_IN_EAST_HIGH_THRES); } break; case ROADM: if (portType == PortDescType.PA_LINE_IN) { return Range.closed(ROADM_POWER_LINE_IN_LOW_THRES, ROADM_POWER_LINE_IN_HIGH_THRES); } else if (portType == PortDescType.EXP_IN || portType == PortDescType.AUX_IN) { return Range.closed(ROADM_POWER_OTHER_IN_LOW_THRES, ROADM_POWER_OTHER_IN_HIGH_THRES); } break; case FIBER_SWITCH: return Range.closed(SWITCH_POWER_LOW_THRES, SWITCH_POWER_HIGH_THRES); default: log.warn("Unexpected device type: {}", devType); break; } // Unexpected port or device type. Do not need warning here for port polling. return null; }
From source file:com.giaybac.traprange.extractor.PDFTableExtractor.java
private List<Range<Integer>> getLineRanges(int pageId, List<TextPosition> pageContent) { TrapRangeBuilder lineTrapRangeBuilder = new TrapRangeBuilder(); for (TextPosition textPosition : pageContent) { Range<Integer> lineRange = Range.closed((int) textPosition.getY(), (int) (textPosition.getY() + textPosition.getHeight())); //add to builder lineTrapRangeBuilder.addRange(lineRange); }// ww w . j a va2 s . co m List<Range<Integer>> lineTrapRanges = lineTrapRangeBuilder.build(); List<Range<Integer>> retVal = removeExceptedLines(pageId, lineTrapRanges); return retVal; }
From source file:org.onosproject.driver.optical.power.OplinkRoadmPowerConfig.java
private Range<Long> getTargetPortPowerRange(PortNumber port) { Range<Long> range = null; long num = port.toLong(); if (num == LINE_OUT) { range = Range.closed(100L, 2040L); } else if (num >= AUX_OUT_1 && num <= EXPRESS_OUT_7) { range = Range.closed(-680L, 1530L); }/*from w ww . j a va 2 s . c om*/ return range; }
From source file:org.opentestsystem.authoring.testauth.validation.AbstractDomainValidator.java
protected Range<Float> buildFloatRange(final String min, final String max) { Range<Float> floatRange = null; if (StringUtils.isNotEmpty(min) && StringUtils.isNotEmpty(max)) { // has both ends of a range floatRange = Range.closed(Float.valueOf(min), Float.valueOf(max)); } else if (StringUtils.isNotEmpty(min) && StringUtils.isEmpty(max)) { // only has a minimum floatRange = Range.atLeast(Float.valueOf(min)); } else if (StringUtils.isEmpty(min) && StringUtils.isNotEmpty(max)) { // only has a maximum floatRange = Range.atMost(Float.valueOf(max)); }/*from w w w . j av a2s . c o m*/ return floatRange; }
From source file:org.waveprotocol.box.server.persistence.blocks.impl.SegmentImpl.java
private void addFragment(final Fragment fragment) { ReadableRangeValue lower = RangeValue.of(fragment.getStartVersion()); ReadableRangeValue upper = fragment.getEndRangeValue(); fragments.put(Range.closed(lower, upper), new SoftReference<>(fragment)); fragment.setSegment(this); }
From source file:org.opentestsystem.authoring.testauth.validation.AbstractDomainValidator.java
protected Range<Long> buildLongRange(final String min, final String max) { Range<Long> longRange = null; if (StringUtils.isNotEmpty(min) && StringUtils.isNotEmpty(max)) { // has both ends of a range longRange = Range.closed(Long.valueOf(min), Long.valueOf(max)); } else if (StringUtils.isNotEmpty(min) && StringUtils.isEmpty(max)) { // only has a minimum longRange = Range.atLeast(Long.valueOf(min)); } else if (StringUtils.isEmpty(min) && StringUtils.isNotEmpty(max)) { // only has a maximum longRange = Range.atMost(Long.valueOf(max)); }//from w w w. ja va2 s. c o m return longRange; }
From source file:org.onosproject.driver.optical.power.OplinkRoadmPowerConfig.java
private Range<Long> getChannelAttenuationRange(PortNumber port) { Range<Long> range = null; long num = port.toLong(); // Only connections from AuxIn to LineOut or ExpressIn to LineOut support // attenuation. if (num == LINE_OUT || num >= AUX_IN_1 && num <= EXPRESS_IN_7) { range = Range.closed(0L, 2550L); }/* www . j av a2 s. c o m*/ return range; }