List of usage examples for com.google.common.collect Range upperBoundType
public BoundType upperBoundType()
From source file:org.mskcc.shenkers.view.GeneViewBuilder.java
public RangeSet<Integer> asClosed(RangeSet<Integer> s) { RangeSet<Integer> exons = TreeRangeSet.create(); for (Range<Integer> r : s.asRanges()) { exons.add(Range.closed(r.lowerBoundType() == BoundType.OPEN ? r.lowerEndpoint() + 1 : r.lowerEndpoint(), r.upperBoundType() == BoundType.OPEN ? r.upperEndpoint() - 1 : r.upperEndpoint())); }/* w ww. j a v a 2s. com*/ return exons; }
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++;// w w w. java2 s. c om } 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(); } } } }
From source file:com.techshroom.wood.ModuleDependency.java
@Override public String toString() { StringBuilder builder = new StringBuilder(getId()).append(':'); Range<SemVer> r = getVersionRange(); if (r.hasLowerBound()) { builder.append(r.lowerBoundType() == BoundType.OPEN ? '(' : '[').append(r.lowerEndpoint()); } else {// ww w . j av a 2s. c o m builder.append('('); } builder.append(','); if (r.hasUpperBound()) { builder.append(r.upperEndpoint()).append(r.upperBoundType() == BoundType.OPEN ? ')' : ']'); } else { builder.append(')'); } return builder.toString(); }
From source file:org.eclipse.fx.ui.controls.styledtext.internal.LineHelper.java
private com.google.common.collect.Range<Integer> mapToLocal(int index, com.google.common.collect.Range<Integer> global) { return com.google.common.collect.Range.range( Integer.valueOf(global.lowerEndpoint().intValue() - getOffset(index)), global.lowerBoundType(), Integer.valueOf(global.upperEndpoint().intValue() - getOffset(index)), global.upperBoundType()); }
From source file:com.google.android.apps.forscience.whistlepunk.sensordb.SensorDatabaseImpl.java
/** * Gets the selection string and selectionArgs based on the tag, range and resolution tier. * * @return a pair where the first element is the selection string and the second element is the * array of selectionArgs./* w w w.ja va 2 s.co m*/ */ private Pair<String, String[]> getSelectionAndArgs(String sensorTag, TimeRange range, int resolutionTier) { List<String> clauses = new ArrayList<>(); List<String> values = new ArrayList<>(); clauses.add(ScalarSensorsTable.Column.TAG + " = ?"); values.add(sensorTag); if (resolutionTier >= 0) { clauses.add(ScalarSensorsTable.Column.RESOLUTION_TIER + " = ?"); values.add(String.valueOf(resolutionTier)); } Range<Long> times = range.getTimes(); Range<Long> canonicalTimes = times.canonical(DiscreteDomain.longs()); if (canonicalTimes.hasLowerBound()) { String comparator = (canonicalTimes.lowerBoundType() == BoundType.CLOSED) ? " >= ?" : " > ?"; clauses.add(ScalarSensorsTable.Column.TIMESTAMP_MILLIS + comparator); values.add(String.valueOf(canonicalTimes.lowerEndpoint())); } if (canonicalTimes.hasUpperBound()) { String comparator = (canonicalTimes.upperBoundType() == BoundType.CLOSED) ? " =< ?" : " < ?"; clauses.add(ScalarSensorsTable.Column.TIMESTAMP_MILLIS + comparator); values.add(String.valueOf(canonicalTimes.upperEndpoint())); } return new Pair<>(Joiner.on(" AND ").join(clauses), values.toArray(new String[values.size()])); }
From source file:com.wealdtech.collect.TreeRangedMap.java
/** * Validate a range prior to insertion/*from ww w . j a v a 2s . c o m*/ * @param range the range to validate */ private void validateRange(final Range<K> range) { if (!range.hasLowerBound()) { throw new IllegalArgumentException("RangedMap only supports ranges with defined lower bound"); } if (!range.lowerBoundType().equals(BoundType.CLOSED)) { throw new IllegalArgumentException("RangedMap must use ranges with closed lower bound"); } if (!range.hasUpperBound()) { throw new IllegalArgumentException("RangedMap must use ranges with defined upper bound"); } if (!range.upperBoundType().equals(BoundType.OPEN)) { throw new IllegalArgumentException("RangedMap must use ranges with open upper bound"); } if (range.isEmpty()) { throw new IllegalArgumentException("RangedMap must use ranges with non-zero size"); } }
From source file:edu.mit.streamjit.impl.compiler2.DescendingShareAllocationStrategy.java
@Override public void allocateGroup(ActorGroup group, Range<Integer> iterations, List<Core> cores, Configuration config) { List<Float> shares = new ArrayList<>(cores.size()); for (int core = 0; core < cores.size(); ++core) { String name = String.format("node%dcore%diter", group.id(), core); Configuration.FloatParameter parameter = config.getParameter(name, Configuration.FloatParameter.class); if (parameter == null) shares.add(0f);/*from w ww. j a va 2 s . co m*/ else shares.add(parameter.getValue()); } assert iterations.lowerBoundType() == BoundType.CLOSED && iterations.upperBoundType() == BoundType.OPEN; int totalAvailable = iterations.upperEndpoint() - iterations.lowerEndpoint(); while (!iterations.isEmpty()) { int max = CollectionUtils.maxIndex(shares); float share = shares.get(max); if (share == 0) break; int amount = DoubleMath.roundToInt(share * totalAvailable, RoundingMode.HALF_EVEN); int done = iterations.lowerEndpoint(); Range<Integer> allocation = group.isStateful() ? iterations : iterations.intersection(Range.closedOpen(done, done + amount)); cores.get(max).allocate(group, allocation); iterations = Range.closedOpen(allocation.upperEndpoint(), iterations.upperEndpoint()); shares.set(max, 0f); //don't allocate to this core again } //If we have iterations left over not assigned to a core, spread them //evenly over all cores. if (!iterations.isEmpty()) { int perCore = IntMath.divide(iterations.upperEndpoint() - iterations.lowerEndpoint(), cores.size(), RoundingMode.CEILING); for (int i = 0; i < cores.size() && !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()); } } assert iterations.isEmpty(); }
From source file:org.openmhealth.dsu.repository.MongoDataPointRepositoryImpl.java
void addCreationTimestampCriteria(Query query, Range<OffsetDateTime> timestampRange) { if (timestampRange.hasLowerBound() || timestampRange.hasUpperBound()) { Criteria timestampCriteria = where("header.creation_date_time"); if (timestampRange.hasLowerBound()) { if (timestampRange.lowerBoundType() == CLOSED) { timestampCriteria = timestampCriteria.gte(timestampRange.lowerEndpoint()); } else { timestampCriteria = timestampCriteria.gt(timestampRange.lowerEndpoint()); }//from w ww. j a v a2s.com } if (timestampRange.hasUpperBound()) { if (timestampRange.upperBoundType() == CLOSED) { timestampCriteria = timestampCriteria.lte(timestampRange.upperEndpoint()); } else { timestampCriteria = timestampCriteria.lt(timestampRange.upperEndpoint()); } } query.addCriteria(timestampCriteria); } }
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. *//*from w w w. j a v a 2 s .c om*/ 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); } }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog.java
private long getNumberOfEntries(Range<PositionImpl> range, NavigableMap<Long, MLDataFormats.ManagedLedgerInfo.LedgerInfo> ledgers) { PositionImpl fromPosition = range.lowerEndpoint(); boolean fromIncluded = range.lowerBoundType() == BoundType.CLOSED; PositionImpl toPosition = range.upperEndpoint(); boolean toIncluded = range.upperBoundType() == BoundType.CLOSED; if (fromPosition.getLedgerId() == toPosition.getLedgerId()) { // If the 2 positions are in the same ledger long count = toPosition.getEntryId() - fromPosition.getEntryId() - 1; count += fromIncluded ? 1 : 0;//from www . j a v a 2 s . c om count += toIncluded ? 1 : 0; return count; } else { long count = 0; // If the from & to are pointing to different ledgers, then we need to : // 1. Add the entries in the ledger pointed by toPosition count += toPosition.getEntryId(); count += toIncluded ? 1 : 0; // 2. Add the entries in the ledger pointed by fromPosition MLDataFormats.ManagedLedgerInfo.LedgerInfo li = ledgers.get(fromPosition.getLedgerId()); if (li != null) { count += li.getEntries() - (fromPosition.getEntryId() + 1); count += fromIncluded ? 1 : 0; } // 3. Add the whole ledgers entries in between for (MLDataFormats.ManagedLedgerInfo.LedgerInfo ls : ledgers .subMap(fromPosition.getLedgerId(), false, toPosition.getLedgerId(), false).values()) { count += ls.getEntries(); } return count; } }