Example usage for com.google.common.collect Range lowerBoundType

List of usage examples for com.google.common.collect Range lowerBoundType

Introduction

In this page you can find the example usage for com.google.common.collect Range lowerBoundType.

Prototype

public BoundType lowerBoundType() 

Source Link

Document

Returns the type of this range's lower bound: BoundType#CLOSED if the range includes its lower endpoint, BoundType#OPEN if it does not.

Usage

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:com.google.googlejavaformat.intellij.FormatterUtil.java

private static TextRange toTextRange(Range<Integer> range) {
    checkState(/*  ww w.  j  a  va  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:net.conquiris.lucene.search.SearchSupport.java

static boolean minIncluded(Range<?> range) {
    return range.hasLowerBound() && range.lowerBoundType() == BoundType.CLOSED;
}

From source file:google.registry.model.common.PersistedRangeLong.java

public static PersistedRangeLong create(Range<Long> range) {
    PersistedRangeLong instance = new PersistedRangeLong();
    if (range.hasLowerBound()) {
        instance.lowerBound = range.lowerEndpoint();
        instance.lowerBoundType = range.lowerBoundType();
    }/*  w  w w  . j  av a  2 s.  com*/
    if (range.hasUpperBound()) {
        instance.upperBound = range.upperEndpoint();
        instance.upperBoundType = range.upperBoundType();
    }
    return instance;
}

From source file:com.stackframe.collect.RangeUtilities.java

/**
 * Build an expression suitable for passing to JDBC as part of an SQL query from a date range.
 *
 * @param column the name of the column//from  w  w  w .  j av a 2  s .  c om
 * @param dateRange the Range
 * @return a String containing the expression
 */
public static String toSQL(String column, Range<Date> dateRange) {
    StringBuilder buf = new StringBuilder();
    if (dateRange.hasLowerBound()) {
        BoundType lowerBound = dateRange.lowerBoundType();
        String operator;
        switch (lowerBound) {
        case CLOSED:
            operator = ">=";
            break;
        case OPEN:
            operator = ">";
            break;
        default:
            throw new AssertionError("unexpected bound type " + lowerBound);
        }

        Date lowerEndpoint = dateRange.lowerEndpoint();
        java.sql.Date lowerDate = convert(lowerEndpoint);
        buf.append(String.format("%s %s '%s'", column, operator, lowerDate.toString()));
        if (dateRange.hasUpperBound()) {
            buf.append(" AND ");
        }
    }

    if (dateRange.hasUpperBound()) {
        BoundType upperBound = dateRange.upperBoundType();
        String operator;
        switch (upperBound) {
        case CLOSED:
            operator = "<=";
            break;
        case OPEN:
            operator = "<";
            break;
        default:
            throw new AssertionError("unexpected bound type " + upperBound);
        }

        Date upperEndpoint = dateRange.upperEndpoint();
        java.sql.Date upperDate = convert(upperEndpoint);
        buf.append(String.format("%s %s '%s'", column, operator, upperDate.toString()));
    }

    return buf.toString();
}

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

/**
 * Serializes the specified range of <code>Field</code>s into the specified writer.
 * @param writer the writer to write to/*  ww  w. j a  v  a  2 s  .  c  om*/
 * @param range the range of fields to serialize
 * 
 * @throws IOException if an I/O problem occurs
 */
public static void writeRange(ByteWriter writer, Range<Field> range) throws IOException {

    writeField(writer, range.lowerEndpoint());
    writeBoundType(writer, range.lowerBoundType());
    writeField(writer, range.upperEndpoint());
    writeBoundType(writer, range.upperBoundType());
}

From source file:com.tinspx.util.base.NumberUtils.java

public static int getRandomInt(Range<Integer> range, Random random) {
    int min = range.lowerEndpoint();
    if (range.lowerBoundType() == BoundType.OPEN) {
        min++;/*from www  . j  a  v a  2  s.  co  m*/
    }
    int max = range.upperEndpoint();
    if (range.upperBoundType() == BoundType.CLOSED) {
        max++;
    }
    return random.nextInt(max - min) + min;
}

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

/**
 * Computes the serialized size of the specified range of fields. 
 * /*www  .j a va2s. c  o  m*/
 * @param range the range
 * @return the serialized size of the specified range of fields 
 */
public static int computeRangeSerializedSize(Range<Field> range) {

    return computeFieldSerializedSize(range.lowerEndpoint())
            + computeBoundTypeSerializedSize(range.lowerBoundType())
            + computeFieldSerializedSize(range.upperEndpoint())
            + computeBoundTypeSerializedSize(range.upperBoundType());
}

From source file:io.druid.sql.calcite.filtration.RangeSets.java

public static List<Interval> toIntervals(final RangeSet<Long> rangeSet) {
    final List<Interval> retVal = Lists.newArrayList();

    for (Range<Long> range : rangeSet.asRanges()) {
        final long start;
        final long end;

        if (range.hasLowerBound()) {
            final long millis = range.lowerEndpoint();
            start = millis + (range.lowerBoundType() == BoundType.OPEN ? 1 : 0);
        } else {/*www. j  a  v a2  s  .co  m*/
            start = Filtration.eternity().getStartMillis();
        }

        if (range.hasUpperBound()) {
            final long millis = range.upperEndpoint();
            end = millis + (range.upperBoundType() == BoundType.OPEN ? 0 : 1);
        } else {
            end = Filtration.eternity().getEndMillis();
        }

        retVal.add(Intervals.utc(start, end));
    }

    return retVal;
}

From source file:org.nmdp.ngs.range.Ranges.java

/**
 * Return true if the specified range is strictly greater than the specified value.
 *
 * @param <C> range endpoint type/*  www  .  jav a  2s .  com*/
 * @param range range, must not be null
 * @param value value, must not be null
 * @return true if the specified range is strictly greater than the specified value
 */
public static <C extends Comparable> boolean isGreaterThan(final Range<C> range, final C value) {
    checkNotNull(range);
    checkNotNull(value);

    if (!range.hasLowerBound()) {
        return false;
    }
    if (range.lowerBoundType() == BoundType.OPEN && range.lowerEndpoint().equals(value)) {
        return true;
    }
    return range.lowerEndpoint().compareTo(value) > 0;
}