List of usage examples for com.google.common.collect Range intersection
public Range<C> intersection(Range<C> connectedRange)
From source file:org.sonatype.nexus.repository.http.RangeParser.java
private List<Range<Long>> ensureSatisfiable(Range<Long> requested, Range<Long> content) { if (requested.isConnected(content)) { return singletonList(requested.intersection(content)); } else {/* ww w. ja va 2s . c om*/ return UNSATISFIABLE; } }
From source file:org.obiba.opal.web.gwt.app.client.magma.derive.helper.NumericalVariableDerivationHelper.java
public boolean isRangeOverlap(Range<N> range) { for (ValueMapEntry e : valueMapEntries) { Range<N> r = entryRangeMap.get(e); if (r != null && r.isConnected(range) && !r.intersection(range).isEmpty()) { // range overlap return true; }//from w w w .j a v a 2 s . c om } return false; }
From source file:org.kitesdk.data.spi.ConstraintsSerialization.java
/** * Deserializes an {@link Range} from the specified {@code in} stream. *///from w w w .j a v a 2 s .c om @SuppressWarnings("unchecked") private static Range readRangePredicate(Schema fieldSchema, ObjectInputStream in) throws IOException { Range range = null; //read in boolean indicating if there is a lower bound if (in.readBoolean()) { BoundType lowerType = in.readBoolean() ? BoundType.OPEN : BoundType.CLOSED; Comparable lowerBound = (Comparable) readValue(fieldSchema, in); if (lowerType.equals(BoundType.OPEN)) { range = Ranges.greaterThan(lowerBound); } else { range = Ranges.atLeast(lowerBound); } } //read in boolean indicating if there is an upper bound if (in.readBoolean()) { Range upperRange = null; BoundType upperType = in.readBoolean() ? BoundType.OPEN : BoundType.CLOSED; Comparable upperBound = (Comparable) readValue(fieldSchema, in); if (upperType.equals(BoundType.OPEN)) { upperRange = Ranges.lessThan(upperBound); } else { upperRange = Ranges.atMost(upperBound); } range = range == null ? upperRange : range.intersection(upperRange); } return range; }
From source file:google.registry.model.common.TimeOfYear.java
/** * Returns an {@link Iterable} of {@link DateTime}s of every recurrence of this particular * time of year within a given {@link Range} (usually one spanning many years). * * <p>WARNING: This can return a potentially very large {@link Iterable} if {@code END_OF_TIME} * is used as the upper endpoint of the range. *//* w ww . ja v a 2 s .c om*/ public Iterable<DateTime> getInstancesInRange(Range<DateTime> range) { // In registry world, all dates are within START_OF_TIME and END_OF_TIME, so restrict any // ranges without bounds to our notion of zero-to-infinity. Range<DateTime> normalizedRange = range.intersection(Range.closed(START_OF_TIME, END_OF_TIME)); Range<Integer> yearRange = Range.closed(normalizedRange.lowerEndpoint().getYear(), normalizedRange.upperEndpoint().getYear()); return FluentIterable.from(ContiguousSet.create(yearRange, integers())) .transform(new Function<Integer, DateTime>() { @Override public DateTime apply(Integer year) { return getDateTimeWithYear(year); } }).filter(normalizedRange); }
From source file:de.tuberlin.uebb.jdae.transformation.Causalisation.java
public void collectEquation(final Matching matching, IntPair eqNext, final Set<GlobalVariable> blockVars, final TIntObjectMap<Range<Integer>> blockEqns) { final int i = eqNext.x; final int j = matching.assignment[i]; final int c = eqNext.y; if (!blockEqns.containsKey(i)) blockEqns.put(i, Range.closed(c, c)); else {/* w w w .j a va 2s . c om*/ final Range<Integer> next = Range.closed(c, c); final Range<Integer> last = blockEqns.get(i); blockEqns.put(i, next.intersection(last)); } blockVars.add(new GlobalVariable(layout[j].name, j + 1, matching.sigma(i, j) + c)); }
From source file:org.corpus_tools.peppermodules.annis.Audio2ANNISMapper.java
/** * Adds a new range to the {@code virtTokenTimes} map. When a range already * exists the intersection of the old and new range is used. * * @param tokenID//from ww w . j a va 2 s .c o m * @param newRange */ private void addVirtualRange(Long tokenID, Range newRange) { Range existingRange = virtTokenTimes.get(tokenID); if (existingRange == null) { virtTokenTimes.put(tokenID, newRange); } else { virtTokenTimes.put(tokenID, existingRange.intersection(newRange)); } }
From source file:com.cinchapi.concourse.server.concurrent.RangeLockService.java
/** * Return {@code true} if an attempt to used {@code token} for a * {@code type} lock is range blocked. Range blocking occurs when there is * another READ or WRITE happening such that allowing the proposed operation * to proceed could lead to inconsistent results (i.e. I want to write X but * there is a READ trying to find all values less than Y). * /*from ww w . ja v a 2s .c o m*/ * @param type * @param token * @return {@code true} if range blocked */ protected final boolean isRangeBlocked(LockType type, RangeToken token) { Value value = token.getValues()[0]; if (type == LockType.READ) { Preconditions.checkArgument(token.getOperator() != null); switch (token.getOperator()) { case EQUALS: return info.writes(token.getKey()).contains(value); case NOT_EQUALS: return info.writes(token.getKey()).size() > 1 || (info.writes(token.getKey()).size() == 1 && !info.writes(token.getKey()).contains(value)); default: Iterator<Value> it = info.writes(token.getKey()).iterator(); while (it.hasNext()) { Iterable<Range<Value>> ranges = RangeTokens.convertToRange(token); Value current = it.next(); Range<Value> point = Range.singleton(current); for (Range<Value> range : ranges) { RangeReadWriteLock lock = null; if (range.isConnected(point) && !range.intersection(point).isEmpty() && (lock = locks.get(RangeToken.forWriting(token.getKey(), current))) != null && !lock.isWriteLockedByCurrentThread()) { return true; } } } return false; } } else { // If I want to WRITE X, I am blocked if there is a READ that // touches X (e.g. direct read for X or a range read that includes // X) return info.reads(token.getKey()).contains(value); } }
From source file:org.eclipse.fx.ui.controls.styledtext.internal.LineHelper.java
public Range<Integer> getSelection(int index) { Range<Integer> selection = getSelection(); if (selection.isEmpty()) { return null; }/*from w w w. ja v a2 s . co m*/ Range<Integer> range = getRange(index); Range<Integer> localSelection = null; if (range.isConnected(selection)) { Range<Integer> intersection = selection.intersection(range); localSelection = mapToLocal(index, intersection); } return localSelection; }
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()); }/*from ww w .j av a 2 s. com*/ assert iterations.isEmpty(); }
From source file:edu.cmu.lti.oaqa.framework.eval.passage.PassageMAPEvalAggregator.java
private float getAvgPsgMAP(List<Passage> docs, List<Passage> gs) { if (gs.size() == 0) { return 0; }/* www . j a v a2 s . c o m*/ int totalChars = 0; int overlapLength = 0; float sumPrecision = 0; int count = 0; Set<Passage> foundGoldTriplets = Sets.newHashSet(); for (Passage doc : docs) { Range<Integer> docRange = Range.closedOpen(doc.getBegin(), doc.getEnd()); totalChars += docRange.upperEndpoint() - docRange.lowerEndpoint(); for (Passage g : gs) { if (!g.getUri().equals(doc.getUri())) continue; Range<Integer> gRange = Range.closedOpen(g.getBegin(), g.getEnd()); if (!docRange.isConnected(gRange)) { continue; } Range<Integer> overlap = docRange.intersection(gRange); if (overlap.isEmpty()) { continue; } overlapLength += overlap.upperEndpoint() - overlap.lowerEndpoint(); sumPrecision += (float) overlapLength / (float) totalChars; count++; foundGoldTriplets.add(g); break; } } int numZeros = Sets.difference(Sets.newHashSet(gs), foundGoldTriplets).size(); return (float) sumPrecision / (float) (count + numZeros); }