Example usage for com.google.common.collect BoundType OPEN

List of usage examples for com.google.common.collect BoundType OPEN

Introduction

In this page you can find the example usage for com.google.common.collect BoundType OPEN.

Prototype

BoundType OPEN

To view the source code for com.google.common.collect BoundType OPEN.

Click Source Link

Document

The endpoint value is not considered part of the set ("exclusive").

Usage

From source file:net.bican.iplib.IPAddresses.java

static Range<IPAddress> canonical(final Range<IPAddress> range, final LongDiscreteDomain<IPAddress> domain) {
    if (range.isEmpty()) {
        return null;
    }/*from  w ww  .  j  a v  a2 s.c om*/
    final boolean l = range.lowerBoundType() == BoundType.OPEN;
    final boolean u = range.upperBoundType() == BoundType.OPEN;
    final IPAddress s = range.lowerEndpoint();
    final IPAddress e = range.upperEndpoint();
    if (l && u) {
        Range.closed(domain.next(s), domain.previous(e));
    } else if (l) {
        return Range.closed(domain.next(s), e);
    } else if (u) {
        return Range.closed(s, domain.previous(e));
    }
    return range;
}

From source file:org.mskcc.shenkers.data.interval.RangeTools.java

public static Range<Integer> asClosed(Range<Integer> r) {
    return Range.closed(r.lowerBoundType() == BoundType.OPEN ? r.lowerEndpoint() + 1 : r.lowerEndpoint(),
            r.upperBoundType() == BoundType.OPEN ? r.upperEndpoint() - 1 : r.upperEndpoint());
}

From source file:org.apache.pulsar.broker.loadbalance.LoadBalancerTestingUtils.java

public static NamespaceBundle[] makeBundles(final NamespaceBundleFactory nsFactory, final String property,
        final String cluster, final String namespace, final int numBundles) {
    final NamespaceBundle[] result = new NamespaceBundle[numBundles];
    final NamespaceName namespaceName = new NamespaceName(property, cluster, namespace);
    for (int i = 0; i < numBundles - 1; ++i) {
        final long lower = NamespaceBundles.FULL_UPPER_BOUND * i / numBundles;
        final long upper = NamespaceBundles.FULL_UPPER_BOUND * (i + 1) / numBundles;
        result[i] = nsFactory.getBundle(namespaceName,
                Range.range(lower, BoundType.CLOSED, upper, BoundType.OPEN));
    }//from  ww w .ja v  a2s  . co m
    result[numBundles - 1] = nsFactory.getBundle(namespaceName,
            Range.range(NamespaceBundles.FULL_UPPER_BOUND * (numBundles - 1) / numBundles, BoundType.CLOSED,
                    NamespaceBundles.FULL_UPPER_BOUND, BoundType.CLOSED));
    return result;
}

From source file:net.bican.iplib.AddressIterable.java

/**
 * @param range//  w ww .  j a  va 2s. c om
 *          the address range
 * @param domain
 *          addressing domain
 */
public AddressIterable(final Range<IPAddress> range) {
    this();
    this.range = range;
    this.domain = (LongDiscreteDomain<IPAddress>) range.lowerEndpoint().getDomain();
    this.current = range.lowerEndpoint();
    if (range.lowerBoundType() == BoundType.OPEN) {
        this.current = this.domain.next(this.current);
    }
}

From source file:com.google.googlejavaformat.intellij.FormatterUtil.java

private static TextRange toTextRange(Range<Integer> range) {
    checkState(/* w  ww.  j a v a  2  s .c o  m*/
            range.lowerBoundType().equals(BoundType.CLOSED) && range.upperBoundType().equals(BoundType.OPEN));
    return new TextRange(range.lowerEndpoint(), range.upperEndpoint());
}

From source file:io.horizondb.model.core.util.SerializationUtils.java

/**
 * Deserializes a <code>BoundType</code> from the specified reader.
 * //w  w  w .  j  a  v a 2 s. c om
 * @param reader the reader to read from
 * @return the deserialized <code>BoundType</code>
 * @throws IOException if an I/O problem occurs
 */
public static BoundType parseBoundTypeFrom(ByteReader reader) throws IOException {

    byte b = reader.readByte();

    if (b == 0) {
        return BoundType.CLOSED;
    }

    return BoundType.OPEN;
}

From source file:org.dishevelled.bio.align.Alignments.java

/**
 * Confirm that the specified range is [closed, open).
 *
 * @param range range to check, must not be null
 *//*w ww . j  av a  2  s.c o m*/
static void checkClosedOpen(final Range<Long> range) {
    checkNotNull(range);
    checkArgument(BoundType.CLOSED == range.lowerBoundType(),
            "range must be [closed, open), lower bound type was open");
    checkArgument(BoundType.OPEN == range.upperBoundType(),
            "range must be [closed, open), upper bound type was closed");
}

From source file:org.apache.lens.cube.parse.CandidateUtil.java

/**
 * Returns true is the Candidates cover the entire time range.
 * @param candidates/* ww w . j  av  a 2  s.  c  om*/
 * @param startTime
 * @param endTime
 * @return
 */
static boolean isTimeRangeCovered(Collection<Candidate> candidates, Date startTime, Date endTime) {
    RangeSet<Date> set = TreeRangeSet.create();
    for (Candidate candidate : candidates) {
        set.add(Range.range(candidate.getStartTime(), BoundType.CLOSED, candidate.getEndTime(),
                BoundType.OPEN));
    }
    return set.encloses(Range.range(startTime, BoundType.CLOSED, endTime, BoundType.OPEN));
}

From source file:org.apache.druid.sql.calcite.filtration.Bounds.java

public static Range<BoundValue> toRange(final BoundDimFilter bound) {
    final BoundValue upper = bound.getUpper() != null ? new BoundValue(bound.getUpper(), bound.getOrdering())
            : null;//  w w  w  . ja  v a 2  s.  c o m
    final BoundValue lower = bound.getLower() != null ? new BoundValue(bound.getLower(), bound.getOrdering())
            : null;

    if (lower == null) {
        return bound.isUpperStrict() ? Range.lessThan(upper) : Range.atMost(upper);
    } else if (upper == null) {
        return bound.isLowerStrict() ? Range.greaterThan(lower) : Range.atLeast(lower);
    } else {
        return Range.range(lower, bound.isLowerStrict() ? BoundType.OPEN : BoundType.CLOSED, upper,
                bound.isUpperStrict() ? BoundType.OPEN : BoundType.CLOSED);
    }
}

From source file:org.kitesdk.data.spi.Range.java

@VisibleForTesting
static <C extends Comparable<C>> com.google.common.collect.Range<C> asGuavaRange(Range<C> range) {
    if (range.hasLowerBound()) {
        if (range.hasUpperBound()) {
            return com.google.common.collect.Ranges.range(range.lower.endpoint(),
                    range.isLowerBoundOpen() ? BoundType.OPEN : BoundType.CLOSED, range.upper.endpoint(),
                    range.isUpperBoundOpen() ? BoundType.OPEN : BoundType.CLOSED);
        } else {//w  w  w . j a v a2  s .c o m
            return com.google.common.collect.Ranges.downTo(range.lower.endpoint(),
                    range.isLowerBoundOpen() ? BoundType.OPEN : BoundType.CLOSED);
        }
    } else if (range.hasUpperBound()) {
        return com.google.common.collect.Ranges.upTo(range.upper.endpoint(),
                range.isUpperBoundOpen() ? BoundType.OPEN : BoundType.CLOSED);
    } else {
        return com.google.common.collect.Ranges.all();
    }
}