List of usage examples for com.google.common.collect Range closedOpen
public static <C extends Comparable<?>> Range<C> closedOpen(C lower, C upper)
From source file:edu.cmu.sv.modelinference.eventtool.PredictionModel.java
public List<Range<Integer>> findThresholdViolations(double[] xs, double[] yObserved) { int maxPredictions = Math.min(xs.length, upperThreshold.size()); LinkedList<Range<Integer>> violations = new LinkedList<>(); boolean ongoingViolation = false; int violationStart = 0; for (int i = 1; i < maxPredictions; i++) { double x = xs[i]; if (!ongoingViolation && isViolation((int) x, yObserved[i])) { violationStart = (int) xs[i]; ongoingViolation = true;/* w w w. j a v a2s . c om*/ } else if (ongoingViolation && !isViolation((int) x, yObserved[i])) { violations.addLast(Range.closedOpen(violationStart, (int) x)); ongoingViolation = false; } } return violations; }
From source file:org.robotframework.red.nattable.TableCellStringData.java
private Range<Integer> getStartingRegion(final int height, final int y) { final String[] lines = drawnString.split("\\r\\n|\\n\\r|\\n|\\r"); if (lines.length < 2) { return Range.closedOpen(0, drawnString.length()); } else {// w w w.j ava 2 s .c o m final int lineHeight = height / lines.length; final int lineNo = Math.min(lines.length - 1, Math.max(0, (int) Math.ceil((double) y / (double) lineHeight) - 1)); int currentLine = 0; int startLine = 0; while (startLine < drawnString.length()) { if (currentLine == lineNo) { return Range.closedOpen(startLine, startLine + lines[lineNo].length()); } else { startLine += lines[lineNo].length(); final char endChar = drawnString.charAt(startLine); if ((endChar == '\n' || endChar == '\r') && startLine < drawnString.length() - 1 && (drawnString.charAt(startLine + 1) == '\n' || drawnString.charAt(startLine + 1) == '\r') && endChar != drawnString.charAt(startLine + 1)) { startLine += 2; } else if (endChar == '\n' || endChar == '\r') { startLine++; } currentLine++; } } return null; } }
From source file:edu.mit.streamjit.impl.compiler2.FullDataParallelAllocationStrategy.java
@Override public void allocateGroup(ActorGroup group, Range<Integer> iterations, List<Core> cores, Configuration config) { int coresSize = Math.min(cores.size(), maxNumCores); int perCore = IntMath.divide(iterations.upperEndpoint() - iterations.lowerEndpoint(), coresSize, RoundingMode.CEILING); for (int i = 0; i < coresSize && !iterations.isEmpty(); ++i) { int min = iterations.lowerEndpoint(); Range<Integer> allocation = group.isStateful() ? iterations : iterations.intersection(Range.closedOpen(min, min + perCore)); cores.get(i).allocate(group, allocation); iterations = Range.closedOpen(allocation.upperEndpoint(), iterations.upperEndpoint()); }/*w ww. j a va2s . co m*/ assert iterations.isEmpty(); }
From source file:google.registry.monitoring.metrics.MutableDistribution.java
/** Constructs an empty Distribution with the specified {@link DistributionFitter}. */ public MutableDistribution(DistributionFitter distributionFitter) { this.distributionFitter = checkNotNull(distributionFitter); ImmutableSortedSet<Double> boundaries = distributionFitter.boundaries(); checkArgument(boundaries.size() > 0); checkArgument(Ordering.natural().isOrdered(boundaries)); this.intervalCounts = TreeRangeMap.create(); double[] boundariesArray = Doubles.toArray(distributionFitter.boundaries()); // Add underflow and overflow intervals this.intervalCounts.put(Range.lessThan(boundariesArray[0]), 0L); this.intervalCounts.put(Range.atLeast(boundariesArray[boundariesArray.length - 1]), 0L); // Add finite intervals for (int i = 1; i < boundariesArray.length; i++) { this.intervalCounts.put(Range.closedOpen(boundariesArray[i - 1], boundariesArray[i]), 0L); }/* ww w. j a va2s . c o m*/ }
From source file:org.mskcc.shenkers.data.interval.DiscreteRangeMap.java
public void testGetGraphic() { RangeMap<Integer, Double> ram = TreeRangeMap.create(); // ram.put(Range.closed(0, 4), 0.); System.out.println("adding"); ram = add(ram, Range.closed(1, 3), 1.); ram.asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d))); System.out.println("adding"); ram = add(ram, Range.closed(-1, 4), 1.); ram.asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d))); System.out.println("adding"); ram = add(ram, Range.closed(3, 5), 2.); ram.asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d))); System.out.println("asReal"); ram.asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d))); toReal(ram).asMapOfRanges().forEach((r, d) -> System.out.println(String.format("%s %f", r, d))); RangeMap<Double, Double> toReal = toReal(ram); System.out.println("span " + toReal.span()); double length = length(toReal.span()); System.out.println("length " + length); int k = 7;//from ww w .j a va2s. c om double binSize = length / k; Double lb = toReal.span().lowerEndpoint(); for (int i = 0; i < k; i++) { Range<Double> closedOpen = Range.closedOpen(lb + (i * 1. / k * length), lb + ((i + 1.) / k * length)); System.out.println("bin " + i); System.out.println(closedOpen); Double max = Collections.max(toReal.subRangeMap(closedOpen).asMapOfRanges().values()); Double mean = toReal.subRangeMap(closedOpen).asMapOfRanges().values().stream() .mapToDouble(Double::doubleValue).average().orElse(0.); // StreamSupport.doubleStream(new Spliterator.OfDouble() // false); System.out.println("max " + max); System.out.println("mean " + mean); } }
From source file:it.units.malelab.ege.ge.mapper.WeightedHierarchicalMapper.java
@Override protected List<Range<Integer>> getChildrenSlices(Range<Integer> range, List<T> symbols) { if (!weightChildren) { return super.getChildrenSlices(range, symbols); }/*from w w w.ja va2s .c o m*/ List<Range<Integer>> ranges; if (symbols.size() > (range.upperEndpoint() - range.lowerEndpoint())) { ranges = new ArrayList<>(symbols.size()); for (T symbol : symbols) { ranges.add(Range.closedOpen(range.lowerEndpoint(), range.lowerEndpoint())); } } else { List<Integer> sizes = new ArrayList<>(symbols.size()); int overallWeight = 0; for (T symbol : symbols) { overallWeight = overallWeight + weightsMap.get(symbol); } for (T symbol : symbols) { sizes.add((int) Math.floor((double) weightsMap.get(symbol) / (double) overallWeight * (double) (range.upperEndpoint() - range.lowerEndpoint()))); } ranges = Utils.slices(range, sizes); } return ranges; }
From source file:net.bican.iplib.IPAddresses.java
private static Set<Range<IPAddress>> fromConnectedInterval(final Range<IPAddress> interval) { if (interval.isEmpty()) { return null; }/* w ww. j a v a2 s. c om*/ int prefix = 0; final LongDiscreteDomain<IPAddress> domain = interval.lowerEndpoint().getDomain(); while (prefix <= domain.maxPrefix()) { final Range<IPAddress> thisRange = IPAddresses.canonical(interval, domain); final Range<IPAddress> otherRange = IPAddresses.fromCIDR(new CIDR(thisRange.lowerEndpoint(), prefix)); if (thisRange.equals(otherRange)) { TreeSet<Range<IPAddress>> result = new TreeSet<>(IPAddressRangeComparator.getComparator()); result.add(otherRange); return result; } else if (thisRange.encloses(otherRange)) { final Set<Range<IPAddress>> result = new TreeSet<>(IPAddressRangeComparator.getComparator()); result.add(otherRange); Range<IPAddress> newRange1 = Range.closedOpen(thisRange.lowerEndpoint(), otherRange.lowerEndpoint()); Range<IPAddress> newRange2 = Range.openClosed(otherRange.upperEndpoint(), thisRange.upperEndpoint()); final Set<Range<IPAddress>> results1 = IPAddresses.fromConnectedInterval(newRange1); if (results1 != null) { result.addAll(results1); } final Set<Range<IPAddress>> results2 = IPAddresses.fromConnectedInterval(newRange2); if (results2 != null) { result.addAll(results2); } return result; } prefix++; } return new TreeSet<>(Collections.singleton(interval)); }
From source file:com.wealdtech.utils.WealdInterval.java
public Range<DateTime> toRange() { return Range.closedOpen(this.start, this.end); }
From source file:org.eclipse.fx.ui.controls.styledtext.internal.VerticalLineFlow.java
public RangeSet<Integer> getVisibleLines() { RangeSet<Integer> visibleLines = TreeRangeSet.create(); visibleLines.add(this.visibleLines.get()); return visibleLines .subRangeSet(Range.closedOpen(Integer.valueOf(0), Integer.valueOf(this.numberOfLines.get()))); }
From source file:org.apache.drill.exec.store.AffinityCalculator.java
/** * Builds a mapping of block locations to file byte range *//* ww w. java2 s . c o m*/ private void buildBlockMap(String fileName) { final Timer.Context context = metrics.timer(BLOCK_MAP_BUILDER_TIMER).time(); BlockLocation[] blocks; ImmutableRangeMap<Long, BlockLocation> blockMap; try { FileStatus file = fs.getFileStatus(new Path(fileName)); blocks = fs.getFileBlockLocations(file, 0, file.getLen()); } catch (IOException ioe) { throw new RuntimeException(ioe); } ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long, BlockLocation>(); for (BlockLocation block : blocks) { long start = block.getOffset(); long end = start + block.getLength(); Range<Long> range = Range.closedOpen(start, end); blockMapBuilder = blockMapBuilder.put(range, block); } blockMap = blockMapBuilder.build(); blockMapMap.put(fileName, blockMap); context.stop(); }