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

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

Introduction

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

Prototype

public static <C extends Comparable<?>> Range<C> closed(C lower, C upper) 

Source Link

Document

Returns a range that contains all values greater than or equal to lower and less than or equal to upper .

Usage

From source file:net.sf.mzmine.util.RangeUtils.java

/**
 * Parses a range from String where upper and lower bounds are delimited by
 * a dash, e.g. "100.0-200.5". Note: we are dealing with doubles, so in an
 * unfortunate case the range might look like this
 * "3.402439E-36-1.310424E-2"//from w ww  .j av  a  2s.  c om
 * 
 */
public static Range<Double> parseRange(String text) {
    Pattern p = Pattern.compile("([\\d\\.]+(?:E\\-?\\d+)?)\\-([\\d\\.]+(?:E\\-?\\d+)?)");

    Matcher m = p.matcher(text);
    if (!m.find()) {
        throw new IllegalArgumentException("String '" + text + "' could not be parsed into a range");
    }
    double low = Double.parseDouble(m.group(1));
    double high = Double.parseDouble(m.group(2));
    Range<Double> result = Range.closed(low, high);
    return result;
}

From source file:org.apache.aurora.scheduler.updater.Updates.java

/**
 * Creates a range set representing all instance IDs represented by a set of instance
 * configurations included in a job update.
 *
 * @param configs Job update components.
 * @return A range set representing the instance IDs mentioned in instance groupings.
 *//*from w ww.j av  a 2 s . c om*/
public static ImmutableRangeSet<Integer> getInstanceIds(Set<IInstanceTaskConfig> configs) {
    ImmutableRangeSet.Builder<Integer> builder = ImmutableRangeSet.builder();
    for (IInstanceTaskConfig config : configs) {
        for (IRange range : config.getInstances()) {
            builder.add(Range.closed(range.getFirst(), range.getLast()));
        }
    }

    return builder.build();
}

From source file:eu.itesla_project.wca.WCAHistoLimits.java

private static Range<Float> range(String id, HistoDbAttr attr, HistoDbStats stats) {
    HistoDbAttributeId pAttrId = new HistoDbNetworkAttributeId(id, HistoDbAttr.P);
    float p_min = stats.getValue(HistoDbStatsType.MIN, pAttrId, INVALID_FLOAT_VALUE);
    float p_max = stats.getValue(HistoDbStatsType.MAX, pAttrId, INVALID_FLOAT_VALUE);
    return Range.closed(p_min, p_max);
}

From source file:io.github.msdk.util.ChromatogramUtil.java

/**
 * Returns the range of ChromatographyInfo of all data points in this
 * feature./*from w  w  w. j  a v  a2  s . c om*/
 *
 * @return a {@link com.google.common.collect.Range} object.
 * @param rtValues
 *            an array of
 *            {@link io.github.msdk.datamodel.rawdata.ChromatographyInfo}
 *            objects.
 * @param size
 *            a {@link java.lang.Integer} object.
 */
@SuppressWarnings("null")
@Nonnull
public static Range<ChromatographyInfo> getDataPointsChromatographyRange(@Nonnull ChromatographyInfo rtValues[],
        @Nonnull Integer size) {

    // Parameter check
    Preconditions.checkNotNull(rtValues);
    Preconditions.checkNotNull(size);
    Preconditions.checkPositionIndex(size, rtValues.length);

    final Range<ChromatographyInfo> chromatographyRange = Range.closed(rtValues[0], rtValues[size - 1]);
    return chromatographyRange;
}

From source file:org.opendaylight.mdsal.binding.java.api.generator.LengthGenerator.java

private static String createLengthString(final Collection<LengthConstraint> constraints) {
    final List<Range<BigInteger>> ranges = new ArrayList<>(constraints.size());

    for (LengthConstraint c : constraints) {
        ranges.add(Range.closed(new BigInteger(c.getMin().toString()), new BigInteger(c.getMax().toString())));
    }/*from  w w w  .  j  ava 2 s.  c o  m*/

    return ranges.toString();
}

From source file:org.rf.ide.core.testdata.model.FileRegion.java

public boolean isInside(final int offset) {
    return Range.closed(start.getOffset(), end.getOffset()).contains(offset);
}

From source file:com.twitter.aurora.scheduler.base.Numbers.java

/**
 * Converts a set of integers into a set of contiguous closed ranges that equally represent the
 * input integers.//from w w w .j  av a2s. com
 * <p>
 * The resulting ranges will be in ascending order.
 *
 * @param values Values to transform to ranges.
 * @return Closed ranges with identical members to the input set.
 */
public static Set<Range<Integer>> toRanges(Iterable<Integer> values) {
    ImmutableSet.Builder<Range<Integer>> builder = ImmutableSet.builder();

    PeekingIterator<Integer> iterator = Iterators.peekingIterator(Sets.newTreeSet(values).iterator());

    // Build ranges until there are no numbers left.
    while (iterator.hasNext()) {
        // Start a new range.
        int start = iterator.next();
        int end = start;
        // Increment the end until the range is non-contiguous.
        while (iterator.hasNext() && (iterator.peek() == (end + 1))) {
            end++;
            iterator.next();
        }

        builder.add(Range.closed(start, end));
    }

    return builder.build();
}

From source file:org.rf.ide.core.testdata.model.RobotExpressions.java

public static List<Range<Integer>> getVariablesPositions(final String expression) {
    final List<Range<Integer>> ranges = newArrayList();

    int rangeStart = -1;
    boolean inVariable = false;
    for (int i = 0; i < expression.length(); i++) {
        if (!inVariable && "%$@&".contains(Character.toString(expression.charAt(i)))
                && Character.valueOf('{').equals(lookahead(expression, i + 1))) {
            inVariable = true;/*from   w  w w .  j  av a2  s  .c o  m*/
            rangeStart = i;
        } else if (inVariable && expression.charAt(i) == '}') {
            inVariable = false;
            ranges.add(Range.closed(rangeStart, i));
        }
    }
    return ranges;
}

From source file:edu.sdsc.scigraph.annotation.Token.java

public Token(T token, int start, int end) {
    this.token = token;
    this.range = Range.closed(start, end);
}

From source file:com.github.drbookings.LocalDates.java

public static Range<LocalDate> getDateRange(final Collection<? extends LocalDate> dates,
        final boolean oneMoreAtTheBeginning) {
    final TreeSet<LocalDate> set = new TreeSet<>(dates);
    if (set.isEmpty()) {
        return null;
    }//from  ww  w . ja v  a 2 s  . c  o m
    final LocalDate d1;
    final LocalDate d2;
    d2 = set.last();
    if (oneMoreAtTheBeginning) {
        d1 = set.first().minusDays(1);
    } else {
        d1 = set.first();
    }
    return Range.closed(d1, d2);
}