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.learningu.scheduling.util.bst.BstMap.java
private static BoundType boundType(boolean inclusive) { return inclusive ? BoundType.CLOSED : BoundType.OPEN; }
From source file:org.apache.druid.query.filter.BoundDimFilter.java
@Override public RangeSet<String> getDimensionRangeSet(String dimension) { if (!(Objects.equals(getDimension(), dimension) && getExtractionFn() == null && ordering.equals(StringComparators.LEXICOGRAPHIC))) { return null; }// ww w.j a v a 2 s . c o m RangeSet<String> retSet = TreeRangeSet.create(); Range<String> range; if (getLower() == null) { range = isUpperStrict() ? Range.lessThan(getUpper()) : Range.atMost(getUpper()); } else if (getUpper() == null) { range = isLowerStrict() ? Range.greaterThan(getLower()) : Range.atLeast(getLower()); } else { range = Range.range(getLower(), isLowerStrict() ? BoundType.OPEN : BoundType.CLOSED, getUpper(), isUpperStrict() ? BoundType.OPEN : BoundType.CLOSED); } retSet.add(range); return retSet; }
From source file:fr.inria.eventcloud.api.generators.StringGenerator.java
/** * Creates a random string based on a variety of options, using supplied * source of randomness./*from ww w .j ava 2 s. c o m*/ * <p> * This method accepts a user-supplied {@link Random} instance to use as a * source of randomness. By seeding a single {@link Random} instance with a * fixed seed and using it for each call, the same random sequence of * strings can be generated repeatedly and predictably. * </p> * * @param length * the length of random string to create. * @param random * a source of randomness. * @param ranges * an array of ranges where each range specifies a continuous * interval of characters which can be used to generate the * random string. * * @return the random string. * * @throws IllegalArgumentException * if {@code length} < 0. */ @SafeVarargs public static String random(long length, Random random, Range<Character>... ranges) { if (length == 0) { return ""; } else if (length < 0) { throw new IllegalArgumentException("Specified length is negative: " + length); } // continuous domain size int domainSize = 0; // size of each interval in discrete domain int[] intervals = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { int lowerBound = ranges[i].lowerEndpoint(); if (ranges[i].lowerBoundType() == BoundType.OPEN) { lowerBound++; } int upperBound = ranges[i].upperEndpoint(); if (ranges[i].upperBoundType() == BoundType.OPEN) { upperBound--; } intervals[i] = upperBound - lowerBound + 1; domainSize += intervals[i]; } if (domainSize == 0) { return ""; } StringBuilder buffer = new StringBuilder(domainSize); while (length-- != 0) { int ch = random.nextInt(domainSize); int index = 0; for (int i = 0; i < intervals.length; i++) { if (ch < index + intervals[i]) { int extra = 0; if (ranges[i].lowerBoundType() == BoundType.OPEN) { extra = 1; } // maps the value from the continuous domain to one from the // original discrete domain buffer.append((char) (ranges[i].lowerEndpoint() + ch - index + extra)); break; } index += intervals[i]; } } return buffer.toString(); }
From source file:com.pingcap.tikv.predicates.ScanBuilder.java
private List<KeyRange> buildIndexScanKeyRange(TiTableInfo table, TiIndexInfo index, List<IndexRange> indexRanges) { requireNonNull(table, "Table cannot be null to encoding keyRange"); requireNonNull(index, "Index cannot be null to encoding keyRange"); requireNonNull(index, "indexRanges cannot be null to encoding keyRange"); List<KeyRange> ranges = new ArrayList<>(indexRanges.size()); for (IndexRange ir : indexRanges) { CodecDataOutput cdo = new CodecDataOutput(); List<Object> values = ir.getAccessPoints(); List<DataType> types = ir.getTypes(); for (int i = 0; i < values.size(); i++) { Object v = values.get(i); DataType t = types.get(i);//from w w w . j a va 2s . c om t.encode(cdo, DataType.EncodeType.KEY, v); } byte[] pointsData = cdo.toBytes(); cdo.reset(); Range r = ir.getRange(); byte[] lPointKey; byte[] uPointKey; byte[] lKey; byte[] uKey; if (r == null) { lPointKey = pointsData; uPointKey = KeyUtils.prefixNext(lPointKey.clone()); lKey = new byte[0]; uKey = new byte[0]; } else { lPointKey = pointsData; uPointKey = pointsData; DataType type = ir.getRangeType(); if (!r.hasLowerBound()) { // -INF type.encodeMinValue(cdo); lKey = cdo.toBytes(); } else { Object lb = r.lowerEndpoint(); type.encode(cdo, DataType.EncodeType.KEY, lb); lKey = cdo.toBytes(); if (r.lowerBoundType().equals(BoundType.OPEN)) { lKey = KeyUtils.prefixNext(lKey); } } cdo.reset(); if (!r.hasUpperBound()) { // INF type.encodeMaxValue(cdo); uKey = cdo.toBytes(); } else { Object ub = r.upperEndpoint(); type.encode(cdo, DataType.EncodeType.KEY, ub); uKey = cdo.toBytes(); if (r.upperBoundType().equals(BoundType.CLOSED)) { uKey = KeyUtils.prefixNext(lKey); } } cdo.reset(); } TableCodec.writeIndexSeekKey(cdo, table.getId(), index.getId(), lPointKey, lKey); ByteString lbsKey = ByteString.copyFrom(cdo.toBytes()); cdo.reset(); TableCodec.writeIndexSeekKey(cdo, table.getId(), index.getId(), uPointKey, uKey); ByteString ubsKey = ByteString.copyFrom(cdo.toBytes()); ranges.add(KeyRange.newBuilder().setStart(lbsKey).setEnd(ubsKey).build()); } if (ranges.isEmpty()) { ranges.add(INDEX_FULL_RANGE); } return ranges; }
From source file:org.assertj.guava.api.RangeAssert.java
/** * Verifies that the actual {@link com.google.common.collect.Range} lower bound is opened.<br> * <p>//from w w w.j a v a2 s. com * Example : * * <pre><code class='java'> Range<Integer> range = Range.open(1, 2); * * assertThat(range).hasOpenedLowerBound();</code></pre> * * @return this {@link OptionalAssert} for assertions chaining. * @throws AssertionError if the actual {@link com.google.common.collect.Range} is {@code null}. * @throws AssertionError if the actual {@link com.google.common.collect.Range} lower bound is closed. */ public RangeAssert<T> hasOpenedLowerBound() throws AssertionError { Objects.instance().assertNotNull(info, actual); if (actual.lowerBoundType() != BoundType.OPEN) { throw failures.failure(info, shouldHaveOpenedLowerBound(actual)); } return this; }
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. */// w ww.j av a 2s .c o m 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.assertj.guava.api.RangeAssert.java
/** * Verifies that the actual {@link com.google.common.collect.Range} upper bound is opened.<br> * <p>/*w w w.ja va2 s . c o m*/ * Example : * * <pre><code class='java'> Range<Integer> range = Range.open(10, 12); * * assertThat(range).hasOpenedUpperBound();</code></pre> * * @return this {@link OptionalAssert} for assertions chaining. * @throws AssertionError if the actual {@link com.google.common.collect.Range} is {@code null}. * @throws AssertionError if the actual {@link com.google.common.collect.Range} upper bound is closed. */ public RangeAssert<T> hasOpenedUpperBound() throws AssertionError { Objects.instance().assertNotNull(info, actual); if (actual.upperBoundType() != BoundType.OPEN) { throw failures.failure(info, shouldHaveOpenedUpperBound(actual)); } return this; }
From source file:com.tinspx.util.io.callbacks.FileChannelCallback.java
/** * Normalizes lower bound to a closed bound type (if exists) and the * upper bound to an open bound type (if exists). Missing bounds remain * missing. Lower bound must be non-negative and upper bound must be * positive. The range cannot be empty.//from ww w.j av a2 s .com */ static Range<Long> checkAndNormalize(Range<Long> range) { checkArgument(!range.isEmpty(), "range %s is empty", range); boolean make = false; long lower = -1; long upper = -1; if (range.hasLowerBound()) { lower = range.lowerEndpoint(); if (range.lowerBoundType() == BoundType.OPEN) { make = true; lower++; } checkArgument(lower >= 0, "closed lower bound (%s) may not be negative", lower); } if (range.hasUpperBound()) { upper = range.upperEndpoint(); if (range.upperBoundType() == BoundType.CLOSED) { make = true; upper++; } checkArgument(upper > 0, "open upper bound (%s) must be positive", upper); } if (make) { if (lower >= 0) { if (upper > 0) { range = Range.closedOpen(lower, upper); } else { range = Range.atLeast(lower); } } else { assert upper > 0 : upper; range = Range.lessThan(upper); } checkArgument(!range.isEmpty(), "normalized range %s is empty", range); } return range; }
From source file:com.ibm.common.activitystreams.actions.Parameter.java
public <O extends Comparable<? super O>> Range<O> bounds() { O mini = minInclusive();/*from w w w . ja va 2s .c o m*/ O mine = minExclusive(); O maxi = maxInclusive(); O maxe = maxExclusive(); Ordering<O> ordering = Ordering.<O>natural(); O min = ordering.nullsLast().min(mini, mine); O max = ordering.nullsFirst().max(maxi, maxe); BoundType lower = min == null ? null : min == mini ? BoundType.CLOSED : BoundType.OPEN; BoundType upper = max == null ? null : max == maxi ? BoundType.CLOSED : BoundType.OPEN; if (lower == null && upper == null) return Range.<O>all(); else if (lower != null && upper == null) return lower == BoundType.CLOSED ? Range.atLeast(min) : Range.greaterThan(min); else if (lower == null && upper != null) return upper == BoundType.CLOSED ? Range.atMost(max) : Range.lessThan(max); else { return Range.range(min, lower, max, upper); } }
From source file:com.yahoo.pulsar.broker.web.PulsarWebResource.java
protected NamespaceBundle validateNamespaceBundleRange(NamespaceName fqnn, BundlesData bundles, String bundleRange) {// www. j av a2s . c o m try { checkArgument(bundleRange.contains("_"), "Invalid bundle range"); String[] boundaries = bundleRange.split("_"); Long lowerEndpoint = Long.decode(boundaries[0]); Long upperEndpoint = Long.decode(boundaries[1]); Range<Long> hashRange = Range.range(lowerEndpoint, BoundType.CLOSED, upperEndpoint, (upperEndpoint.equals(NamespaceBundles.FULL_UPPER_BOUND)) ? BoundType.CLOSED : BoundType.OPEN); NamespaceBundle nsBundle = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundle(fqnn, hashRange); NamespaceBundles nsBundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(fqnn, bundles); nsBundles.validateBundle(nsBundle); return nsBundle; } catch (Exception e) { log.error("[{}] Failed to validate namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e); throw new RestException(e); } }