List of usage examples for com.google.common.collect BoundType OPEN
BoundType OPEN
To view the source code for com.google.common.collect BoundType OPEN.
Click Source Link
From source file:org.dishevelled.bio.range.rtree.RangeGeometries.java
/** * Create and return a new rectangle geometry from the specified range. * * @param <N> value type//from w ww . jav a 2s . co m * @param range range, must not be null, must not be empty, and must have lower and upper bounds * @return a new rectangle geometry from the specified range */ public static <N extends Number & Comparable<? super N>> Rectangle range(final Range<N> range) { checkNotNull(range); if (range.isEmpty()) { throw new IllegalArgumentException("range must not be empty"); } if (!range.hasLowerBound() || !range.hasUpperBound()) { throw new IllegalArgumentException("range must have lower and upper bounds"); } Number lowerEndpoint = range.lowerEndpoint(); BoundType lowerBoundType = range.lowerBoundType(); Number upperEndpoint = range.upperEndpoint(); BoundType upperBoundType = range.upperBoundType(); /* Since we are representing genomic coordinate systems, the expectation is that endpoints are instance of Integer, Long, or BigInteger; thus for open lower and upper bounds we can safely add or subtract 1.0 respectively. Then by convention a rectangle with y1 0.0 and height of 1.0 is used. closed(10, 20) --> (10.0, 0.0, 20.0, 1.0) closedOpen(10, 20) --> (10.0, 0.0, 19.0, 1.0) openClosed(10, 20) --> (11.0, 0.0, 20.0, 1.0) open(10, 20) --> (11.0, 0.0, 19.0, 1.0); closed(10, 11) --> (10.0, 0.0, 11.0, 1.0) closedOpen(10, 11) --> (10.0, 0.0, 10.0, 1.0) openClosed(10, 11) --> (11.0, 0.0, 11.0, 1.0) open(10, 11) --> empty, throw exception closed(10, 10) --> (10.0, 0.0, 10.0, 1.0) closedOpen(10, 10) --> empty, throw exception openClosed(10, 10) --> empty, throw exception open(10, 10) --> empty, throw exception */ double x1 = lowerBoundType == BoundType.OPEN ? lowerEndpoint.doubleValue() + 1.0d : lowerEndpoint.doubleValue(); double y1 = 0.0d; double x2 = upperBoundType == BoundType.OPEN ? upperEndpoint.doubleValue() - 1.0d : upperEndpoint.doubleValue(); double y2 = 1.0d; return Geometries.rectangle(x1, y1, x2, y2); }
From source file:org.apache.cassandra.cql3.restrictions.TokenFilter.java
/** * Converts the specified slice into a range set. * * @param slice the slice to convert//from ww w. j a v a 2s . c om * @param options the query option * @return the range set corresponding to the specified slice * @throws InvalidRequestException if the request is invalid */ private static RangeSet<Token> toRangeSet(TokenRestriction slice, QueryOptions options) throws InvalidRequestException { if (slice.hasBound(START)) { Token start = deserializeToken(slice.bounds(START, options).get(0)); BoundType startBoundType = toBoundType(slice.isInclusive(START)); if (slice.hasBound(END)) { BoundType endBoundType = toBoundType(slice.isInclusive(END)); Token end = deserializeToken(slice.bounds(END, options).get(0)); if (start.equals(end) && (BoundType.OPEN == startBoundType || BoundType.OPEN == endBoundType)) return ImmutableRangeSet.of(); if (start.compareTo(end) <= 0) return ImmutableRangeSet.of(Range.range(start, startBoundType, end, endBoundType)); return ImmutableRangeSet.<Token>builder().add(Range.upTo(end, endBoundType)) .add(Range.downTo(start, startBoundType)).build(); } return ImmutableRangeSet.of(Range.downTo(start, startBoundType)); } Token end = deserializeToken(slice.bounds(END, options).get(0)); return ImmutableRangeSet.of(Range.upTo(end, toBoundType(slice.isInclusive(END)))); }
From source file:org.nmdp.ngs.fca.Interval.java
private BoundType reverse(final BoundType type) { return this.range.upperBoundType() == BoundType.OPEN ? BoundType.CLOSED : BoundType.OPEN; }
From source file:org.apache.mahout.math.neighborhood.ProjectionSearch.java
/** * Searches for the query vector returning the closest limit referenceVectors. * * @param query the vector to search for. * @param limit the number of results to return. * @return a list of Vectors wrapped in WeightedThings where the "thing"'s weight is the * distance./* www.j ava2 s. c om*/ */ @Override public List<WeightedThing<Vector>> search(Vector query, int limit) { Set<Vector> candidates = Sets.newHashSet(); Iterator<? extends Vector> projections = basisMatrix.iterator(); for (TreeMultiset<WeightedThing<Vector>> v : scalarProjections) { Vector basisVector = projections.next(); WeightedThing<Vector> projectedQuery = new WeightedThing<Vector>(query, query.dot(basisVector)); for (WeightedThing<Vector> candidate : Iterables.concat( Iterables.limit(v.tailMultiset(projectedQuery, BoundType.CLOSED), searchSize), Iterables.limit( v.headMultiset(projectedQuery, BoundType.OPEN).descendingMultiset(), searchSize))) { candidates.add(candidate.getValue()); } } // If searchSize * scalarProjections.size() is small enough not to cause much memory pressure, // this is probably just as fast as a priority queue here. List<WeightedThing<Vector>> top = Lists.newArrayList(); for (Vector candidate : candidates) { top.add(new WeightedThing<Vector>(candidate, distanceMeasure.distance(query, candidate))); } Collections.sort(top); return top.subList(0, Math.min(limit, top.size())); }
From source file:org.kitesdk.data.spi.ConstraintsSerialization.java
/** * Deserializes an {@link Range} from the specified {@code in} stream. *//*from www.j a v a2s . 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:org.eclipse.elk.alg.layered.intermediate.greedyswitch.InLayerEdgeAllCrossingsCounter.java
private int numberOfPortsInBetweenEndsOf(final LEdge edge, final SortedMultiset<Integer> set) { int lowerBound = Math.min(positionOf(edge.getTarget()), positionOf(edge.getSource())); int upperBound = Math.max(positionOf(edge.getTarget()), positionOf(edge.getSource())); return set.subMultiset(lowerBound, BoundType.OPEN, upperBound, BoundType.OPEN).size(); }
From source file:org.apache.cassandra.cql3.restrictions.TokenFilter.java
private static BoundType toBoundType(boolean inclusive) { return inclusive ? BoundType.CLOSED : BoundType.OPEN; }
From source file:dollar.api.types.DollarRange.java
@NotNull @Override/*from w w w. j a va 2 s .c om*/ public Value $get(@NotNull Value key) { if (key.integer()) { long keyL; if (key.toLong() < 0) { keyL = size() + key.toLong(); } else { keyL = key.toLong(); } Value upper = range.upperEndpoint(); assert upper != null; Value lower = range.lowerEndpoint(); assert lower != null; // (1..3) 2,2 [1..3] 1,3 if (reversed && !range.hasUpperBound()) { throw new DollarException( "Attempted to get an element from an unbounded range offset from the upper bound " + "(reversed)"); } if (!reversed && !range.hasLowerBound()) { throw new DollarException( "Attempted to get an element from an unbounded range offset from the lower bound " + "(not reversed)"); } if (range.upperBoundType().equals(BoundType.OPEN)) { upper = upper.$dec(); } if (range.lowerBoundType().equals(BoundType.OPEN)) { lower = lower.$inc(); } if (upper.compareTo(lower) < 0) { throw new DollarException("Elements not available in an empty range"); } if (upper.integer()) { if ((upper.toLong() == lower.toLong()) && (keyL == 0)) { return DollarFactory.fromValue(lower); } final long result = reversed ? (upper.toLong() - keyL) : (lower.toLong() + keyL); return DollarFactory.fromValue(result); } if (upper.decimal()) { if ((upper.toDouble() == lower.toDouble()) && (keyL == 0)) { return DollarFactory.fromValue(lower); } final double diff = reversed ? (upper.toDouble() - keyL) : (lower.toDouble() + keyL); return DollarFactory.fromValue(diff + Math.signum(diff)); } if (upper.equals(lower) && (keyL == 0)) { return DollarFactory.fromValue(lower); } if (!reversed) { Value start = lower; for (long i = 0; i < keyL; i++) { start = start.$inc(); } return start; } else { Value finish = upper; for (long i = 0; i < keyL; i++) { finish = finish.$dec(); } return finish; } } throw new DollarFailureException(ErrorType.INVALID_RANGE_OPERATION); }
From source file:org.cinchapi.concourse.server.model.Ranges.java
/** * Return the ranges that include the points that are in {@code a} or the * {@code b} one and not in their intersection. The return set will include * between 0 and 2 ranges that together include all the points that meet * this criteria.// ww w . ja va2s. c o m * <p> * <strong>NOTE:</strong> If the two ranges do not intersect, then a * collection containing both of them is returned (since they already form * their xor). * </p> * * @param a * @param b * @return the set or ranges that make uValue the symmetric difference * between this range and the {@code other} one */ public static Iterable<Range<Value>> xor(Range<Value> a, Range<Value> b) { List<Range<Value>> ranges = Lists.newArrayList(); try { Range<Value> intersection = a.intersection(b); boolean aStart = compareToLower(a, b) < 0; boolean aEnd = compareToUpper(a, b) > 0; boolean lower = getLowerBoundType(aStart ? a : b) == BoundType.CLOSED; boolean upper = getUpperBoundType(aEnd ? a : b) == BoundType.CLOSED; boolean interLower = getLowerBoundType(intersection) == BoundType.OPEN; boolean interUpper = getUpperBoundType(intersection) == BoundType.OPEN; Range<Value> first; if (lower && interLower) { first = Range.closed(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection)); } else if (!lower && interLower) { first = Range.openClosed(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection)); } else if (lower && !interLower) { first = Range.closedOpen(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection)); } else { first = Range.open(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection)); } Range<Value> second; if (interUpper && upper) { second = Range.closed(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b)); } else if (!interUpper && upper) { second = Range.openClosed(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b)); } else if (interUpper && !interUpper) { second = Range.closedOpen(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b)); } else { second = Range.open(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b)); } if (!first.isEmpty()) { ranges.add(first); } if (!second.isEmpty()) { ranges.add(second); } } catch (IllegalArgumentException e) { // ranges dont intersect ranges.add(a); ranges.add(b); } return ranges; }
From source file:org.apache.mahout.math.neighborhood.ProjectionSearch.java
/** * Returns the closest vector to the query. * When only one the nearest vector is needed, use this method, NOT search(query, limit) because * it's faster (less overhead).//from w w w . j a va2 s . co m * * @param query the vector to search for * @param differentThanQuery if true, returns the closest vector different than the query (this * only matters if the query is among the searched vectors), otherwise, * returns the closest vector to the query (even the same vector). * @return the weighted vector closest to the query */ @Override public WeightedThing<Vector> searchFirst(Vector query, boolean differentThanQuery) { double bestDistance = Double.POSITIVE_INFINITY; Vector bestVector = null; Iterator<? extends Vector> projections = basisMatrix.iterator(); for (TreeMultiset<WeightedThing<Vector>> v : scalarProjections) { Vector basisVector = projections.next(); WeightedThing<Vector> projectedQuery = new WeightedThing<Vector>(query, query.dot(basisVector)); for (WeightedThing<Vector> candidate : Iterables.concat( Iterables.limit(v.tailMultiset(projectedQuery, BoundType.CLOSED), searchSize), Iterables.limit( v.headMultiset(projectedQuery, BoundType.OPEN).descendingMultiset(), searchSize))) { double distance = distanceMeasure.distance(query, candidate.getValue()); if (distance < bestDistance && (!differentThanQuery || !candidate.getValue().equals(query))) { bestDistance = distance; bestVector = candidate.getValue(); } } } return new WeightedThing<Vector>(bestVector, bestDistance); }