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

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

Introduction

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

Prototype

BoundType CLOSED

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

Click Source Link

Document

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

Usage

From source file:com.wealdtech.jackson.modules.DateTimeRangeSerializer.java

@Override
public void serialize(final Range<DateTime> value, final JsonGenerator gen, final SerializerProvider provider)
        throws IOException {
    if (value != null) {
        final StringBuilder sb = new StringBuilder(64);
        if (value.hasLowerBound()) {
            if (value.lowerBoundType().equals(BoundType.CLOSED)) {
                sb.append('[');
            } else {
                sb.append('(');
            }/*from  w  w w .  jav  a2s  . c  o m*/
            sb.append(formatter.print(value.lowerEndpoint()));
        } else {
            sb.append('(');
            sb.append(NEGATIVE_INFINITY);
        }
        sb.append(',');

        if (value.hasUpperBound()) {
            sb.append(formatter.print(value.upperEndpoint()));
            if (value.upperBoundType().equals(BoundType.CLOSED)) {
                sb.append(']');
            } else {
                sb.append(')');
            }
        } else {
            sb.append(POSITIVE_INFINITY);
            sb.append(')');
        }

        gen.writeString(sb.toString());
    }
}

From source file:org.apache.pulsar.common.naming.NamespaceBundle.java

public NamespaceBundle(NamespaceName nsname, Range<Long> keyRange, NamespaceBundleFactory factory) {
    this.nsname = checkNotNull(nsname);
    this.keyRange = checkNotNull(keyRange);
    checkArgument(this.keyRange.lowerBoundType().equals(BoundType.CLOSED),
            "Invalid hash range. Lower Endpoint has to be inclusive");
    checkArgument(/*from   w w  w . j ava  2s. c  o m*/
            (this.keyRange.upperEndpoint().equals(NamespaceBundles.FULL_UPPER_BOUND)
                    && this.keyRange.upperBoundType().equals(BoundType.CLOSED))
                    || (!this.keyRange.upperEndpoint().equals(NamespaceBundles.FULL_UPPER_BOUND)
                            && this.keyRange.upperBoundType().equals(BoundType.OPEN)),
            "Invalid hash range. Upper Endpoint should be exclusive unless it is 0xffffffff");
    checkArgument(!this.keyRange.isEmpty(), "Cannot create bundle object for an empty key range");
    this.factory = checkNotNull(factory);
}

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 {// www .  j av a 2 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();
    }
}

From source file:org.apache.kylin.common.util.RangeUtil.java

public static <C extends Comparable<?>> boolean upperBoundInclusive(Range<C> range) {
    if (!range.hasUpperBound()) {
        throw new IllegalArgumentException(("This range does not have upper bound" + range));
    }/* w w  w.  j av  a  2  s . c  om*/
    return range.upperBoundType() == BoundType.CLOSED;
}

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

/**
 * Serializes the specified <code>BoundType</code> into the specified writer.
 * @param writer the writer to write to/*from   w  w w  . j a va2  s.  co m*/
 * @param boundType the BoundType to serialize
 * 
 * @throws IOException if an I/O problem occurs
 */
public static void writeBoundType(ByteWriter writer, BoundType boundType) throws IOException {

    if (boundType == BoundType.CLOSED) {
        writer.writeByte(0);
    } else {
        writer.writeByte(1);
    }
}

From source file:com.yahoo.pulsar.common.naming.NamespaceBundles.java

public NamespaceBundles(NamespaceName nsname, long[] partitions, NamespaceBundleFactory factory) {
    // check input arguments
    this.nsname = checkNotNull(nsname);
    this.factory = checkNotNull(factory);
    checkArgument(partitions.length > 0, "Can't create bundles w/o partition boundaries");

    // calculate bundles based on partition boundaries
    this.bundles = Lists.newArrayList();
    fullBundle = new NamespaceBundle(nsname,
            Range.range(FULL_LOWER_BOUND, BoundType.CLOSED, FULL_UPPER_BOUND, BoundType.CLOSED), factory);

    if (partitions.length > 0) {
        if (partitions.length == 1) {
            throw new IllegalArgumentException("Need to specify at least 2 boundaries");
        }//  w ww . jav a 2  s.co  m

        this.partitions = partitions;
        long lowerBound = partitions[0];
        for (int i = 1; i < partitions.length; i++) {
            long upperBound = partitions[i];
            checkArgument(upperBound >= lowerBound);
            Range<Long> newRange = null;
            if (i != partitions.length - 1) {
                newRange = Range.range(lowerBound, BoundType.CLOSED, upperBound, BoundType.OPEN);
            } else {
                // last one has a closed right end
                newRange = Range.range(lowerBound, BoundType.CLOSED, upperBound, BoundType.CLOSED);
            }
            bundles.add(new NamespaceBundle(nsname, newRange, factory));
            lowerBound = upperBound;
        }
    } else {
        this.partitions = new long[] { 0l };
        bundles.add(fullBundle);
    }
}

From source file:io.horizondb.model.core.filters.RangeFilter.java

/**
 * {@inheritDoc}/*from  w  ww .j  a v  a  2  s  .  co  m*/
 */
@Override
public boolean accept(T value) throws IOException {

    if (!this.range.contains(value)) {

        if (this.valuesNeverDecrease && ((this.range.upperBoundType() == BoundType.CLOSED
                && this.range.upperEndpoint().compareTo(value) < 0)
                || (this.range.upperBoundType() == BoundType.OPEN
                        && this.range.upperEndpoint().compareTo(value) <= 0))) {

            this.isDone = true;
        }

        return false;
    }

    return true;
}

From source file:com.techshroom.wood.ModuleDependency.java

public static ModuleDependency fromString(String dependency) {
    // Dependency format: '<id>:<version>'
    // List format: '<dep>;<dep>;<dep>'
    // Version range format:
    // Any version: [0.0.0,) or * or omitted
    // Any version above 1.0.0: [1.0.0,)
    // Any version with major 1: [1.0.0,2.0.0)
    // Any version with major.minor 1.0: [1.0.0,1.1.0)
    // 1.0.0-1.2.0: [1.0.0,1.2.0]
    // etc. Basically works like Range.
    String id;//from  ww  w .  ja  v  a 2  s.c o m
    Range<SemVer> range;
    String[] idSplit = dependency.split(":", 2);
    id = idSplit[0];
    if (idSplit.length == 2 && !idSplit[1].equals("*")) {
        String r = idSplit[1];
        Matcher matcher = VERSION_RANGE_PATTERN.matcher(r);

        checkArgument(matcher.matches(), "'%s' is not a valid range", r);

        BoundType lowBound = matcher.group(1).equals("(") ? BoundType.OPEN : BoundType.CLOSED;
        BoundType hiBound = matcher.group(4).equals(")") ? BoundType.OPEN : BoundType.CLOSED;
        String lowVersion = matcher.group(2);
        String hiVersion = matcher.group(3);
        checkArgument(lowVersion != null || hiVersion != null,
                "A bound must have at least one version. Use \"[0.0.0,)\" or '*' for any.");
        if (lowVersion == null) {
            checkArgument(lowBound == BoundType.OPEN, "must use '(' with no lower bound");
            range = Range.upTo(SemVer.fromString(hiVersion), hiBound);
        } else if (hiVersion == null) {
            checkArgument(hiBound == BoundType.OPEN, "must use ')' with no upper bound");
            range = Range.downTo(SemVer.fromString(lowVersion), lowBound);
        } else {
            range = Range.range(SemVer.fromString(lowVersion), lowBound, SemVer.fromString(hiVersion), hiBound);
        }
    } else {
        range = Range.downTo(ZERO, BoundType.CLOSED);
    }
    return fromFields(id, range);
}

From source file:org.cinchapi.concourse.server.model.Ranges.java

/**
 * Convert the given {@code range} for {@code key} to a matching
 * {@link RangeToken}.//from  www  .  j a va2  s .  c  o m
 * 
 * @param key
 * @param range
 * @return the RangeToken
 */
public static RangeToken convertToRangeToken(Text key, Range<Value> range) {
    Value lower = getLowerEndpoint(range);
    Value upper = getUpperEndpoint(range);
    boolean lowerClosed = getLowerBoundType(range) == BoundType.CLOSED;
    boolean upperClosed = getUpperBoundType(range) == BoundType.CLOSED;
    // We use the length of the values array in the RangeToken as a hack to
    // signal what kind of non-traditional (i.e. closedOpen) bounds to use
    // on the BETWEEN range when using the Guava data type.
    int size;
    if (!lowerClosed && !upperClosed) {
        size = 3;
    } else if (lowerClosed && upperClosed) {
        size = 4;
    } else if (!lowerClosed && upperClosed) {
        size = 5;
    } else {
        size = 2;
    }
    Value[] values = new Value[size];
    values[0] = lower;
    values[1] = upper;
    for (int i = 2; i < values.length; i++) {
        values[i] = Value.NEGATIVE_INFINITY;
    }
    return RangeToken.forReading(key, Operator.BETWEEN, values);
}

From source file:org.apache.kylin.metadata.realization.SQLDigestUtil.java

private static TupleFilter createFilterForRealtime(TupleFilter originFilter, TblColRef partitionColRef,
        Range<Long> tsRange) {
    DataType type = partitionColRef.getColumnDesc().getType();

    String startTimeStr, endTimeStr;
    CompareTupleFilter startFilter = null, endFilter = null;
    if (tsRange.hasLowerBound()) {
        startTimeStr = formatTimeStr(type, tsRange.lowerEndpoint());
        if (tsRange.lowerBoundType() == BoundType.CLOSED) {
            startFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.GTE);
        } else {/*  www .ja v  a  2  s  . co m*/
            startFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.GT);
        }
        ColumnTupleFilter columnTupleFilter = new ColumnTupleFilter(partitionColRef);
        ConstantTupleFilter constantTupleFilter = new ConstantTupleFilter(startTimeStr);
        startFilter.addChild(columnTupleFilter);
        startFilter.addChild(constantTupleFilter);
    }

    if (tsRange.hasUpperBound()) {
        endTimeStr = formatTimeStr(type, tsRange.upperEndpoint());
        if (tsRange.upperBoundType() == BoundType.CLOSED) {
            endFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.LTE);
        } else {
            endFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.LT);
        }
        ColumnTupleFilter columnTupleFilter = new ColumnTupleFilter(partitionColRef);
        ConstantTupleFilter constantTupleFilter = new ConstantTupleFilter(endTimeStr);
        endFilter.addChild(columnTupleFilter);
        endFilter.addChild(constantTupleFilter);
    }

    if (originFilter == null) {
        if (endFilter == null) {
            return startFilter;
        }
        if (startFilter == null) {
            return endFilter;
        }
    }

    LogicalTupleFilter logicalTupleFilter = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND);

    if (originFilter != null) {
        logicalTupleFilter.addChild(originFilter);
    }
    if (startFilter != null) {
        logicalTupleFilter.addChild(startFilter);
    }
    if (endFilter != null) {
        logicalTupleFilter.addChild(endFilter);
    }

    return logicalTupleFilter;
}