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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:org.robotframework.ide.eclipse.main.plugin.tableeditor.HeaderFilterMatchesCollection.java

protected final boolean collectMatches(final String filter, final String label) {
    int index = label.indexOf(filter);
    final boolean result = index >= 0;
    while (index >= 0) {
        matches.put(label, Range.closedOpen(index, index + filter.length()));
        allMatches++;/*  w  ww.  ja v  a2  s. co  m*/
        index = label.indexOf(filter, index + 1);
    }
    return result;
}

From source file:algorithm.Breed.java

/**
 * Increases the amount of genetic mutations that occur, which is usually
 * as a result of in-breeding in genetics. This simulates the negative effects
 * of in-breeding within a population and increases the mutation rate by 5% each
 * time up to a maximum threshold value, otherwise if the population is not in-bred
 * the amount of mutation decreases down to the original mutation rate of 1%.
 * /*from   ww w .  j  av  a  2s .  co m*/
 * If the population is in-bred the amount of genetic mutation that occur increases,
 * whereas if the amount of in-breeding is minimal the amount of genetic mutations
 * that occurs is minimized.
 * 
 * @inBred True if the current population is in-bred and at the minimum threshold,
 * false otherwise.
 */
public static void inBreeding(boolean inBred) {
    if (inBred) {
        if (MUTATION.lowerEndpoint() > 1) {
            /* Decrease the MUTATION lower bound by 1 */
            Breed.MUTATION = Range.closedOpen(MUTATION.lowerEndpoint() - 1, 100);
        }
    } else {
        if (MUTATION.lowerEndpoint() < 99) {
            /* Increase the MUTATION lower bound by 1 */
            Breed.MUTATION = Range.closedOpen(MUTATION.lowerEndpoint() + 1, 100);
        }
    }
}

From source file:it.frob.auto.value.neuteredtostring.AutoValueNeuterToStringExtension.java

/**
 * Class constructor method generator./*  w  w  w .  j  ava 2 s.  co  m*/
 *
 * @param properties the properties of the class constructor to generate.
 * @return a {@link MethodSpec} instance containing the class constructor.
 */
private static MethodSpec generateConstructor(Map<String, ExecutableElement> properties) {
    List<ParameterSpec> params = new ArrayList<ParameterSpec>();
    for (Map.Entry<String, ExecutableElement> entry : properties.entrySet()) {
        TypeName typeName = TypeName.get(entry.getValue().getReturnType());
        params.add(ParameterSpec.builder(typeName, entry.getKey()).build());
    }

    String body = String.format("super(%s)",
            Joiner.on(", ")
                    .join(FluentIterable
                            .from(ImmutableRangeSet.of(Range.closedOpen(0, properties.size()))
                                    .asSet(DiscreteDomain.integers()).descendingSet())
                            .transform(new Function<Integer, String>() {
                                @Override
                                public String apply(Integer input) {
                                    return "$N";
                                }
                            })));

    return MethodSpec.constructorBuilder().addParameters(params)
            .addStatement(body, properties.keySet().toArray()).build();
}

From source file:com.google.googlejavaformat.java.FormatFileCallable.java

private RangeSet<Integer> characterRanges(String input) {
    final RangeSet<Integer> characterRanges = TreeRangeSet.create();

    if (parameters.lines().isEmpty() && parameters.offsets().isEmpty()) {
        characterRanges.add(Range.closedOpen(0, input.length()));
        return characterRanges;
    }/* w  w  w.  j a  v  a  2s  . c  o  m*/

    characterRanges.addAll(Formatter.lineRangesToCharRanges(input, parameters.lines()));

    for (int i = 0; i < parameters.offsets().size(); i++) {
        Integer length = parameters.lengths().get(i);
        if (length == 0) {
            // 0 stands for "format the line under the cursor"
            length = 1;
        }
        characterRanges
                .add(Range.closedOpen(parameters.offsets().get(i), parameters.offsets().get(i) + length));
    }

    return characterRanges;
}

From source file:com.google.googlejavaformat.InputOutput.java

/**
 * Given an {@code InputOutput}, compute the map from tok indices to line ranges.
 *
 * @param put the {@code InputOutput}/* ww  w.ja va 2s  .c o  m*/
 * @return the map from {@code com.google.googlejavaformat.java.JavaInput.Tok} indices to line
 *     ranges in this {@code put}
 */
public static Map<Integer, Range<Integer>> makeKToIJ(InputOutput put) {
    Map<Integer, Range<Integer>> map = new HashMap<>();
    int ijN = put.getLineCount();
    for (int ij = 0; ij <= ijN; ij++) {
        Range<Integer> range = put.getRanges(ij).canonical(INTEGERS);
        for (int k = range.lowerEndpoint(); k < range.upperEndpoint(); k++) {
            if (map.containsKey(k)) {
                map.put(k, Range.closedOpen(map.get(k).lowerEndpoint(), ij + 1));
            } else {
                map.put(k, Range.closedOpen(ij, ij + 1));
            }
        }
    }
    return map;
}

From source file:com.google.errorprone.refaster.UClassDecl.java

private static Function<UnifierWithRemainingMembers, Choice<UnifierWithRemainingMembers>> match(
        final Tree tree) {
    return new Function<UnifierWithRemainingMembers, Choice<UnifierWithRemainingMembers>>() {
        @Override/* w ww  .  ja v a 2s  .  co m*/
        public Choice<UnifierWithRemainingMembers> apply(final UnifierWithRemainingMembers state) {
            final ImmutableList<UMethodDecl> currentMembers = state.remainingMembers();
            Choice<Integer> methodChoice = Choice.from(ContiguousSet
                    .create(Range.closedOpen(0, currentMembers.size()), DiscreteDomain.integers()));
            return methodChoice.thenChoose(new Function<Integer, Choice<UnifierWithRemainingMembers>>() {
                @Override
                public Choice<UnifierWithRemainingMembers> apply(Integer i) {
                    ImmutableList<UMethodDecl> remainingMembers = new ImmutableList.Builder<UMethodDecl>()
                            .addAll(currentMembers.subList(0, i))
                            .addAll(currentMembers.subList(i + 1, currentMembers.size())).build();
                    UMethodDecl chosenMethod = currentMembers.get(i);
                    Unifier unifier = state.unifier().fork();
                    /* 
                     * If multiple methods use the same parameter name, preserve the last parameter
                     * name from the target code.  For example, given a @BeforeTemplate with
                     * 
                     *    int get(int index) {...}
                     *    int set(int index, int value) {...}
                     *    
                     * and target code with the lines
                     * 
                     *    int get(int i) {...}
                     *    int set(int j) {...}
                     *    
                     * then use "j" in place of index in the @AfterTemplates.
                     */
                    for (UVariableDecl param : chosenMethod.getParameters()) {
                        unifier.clearBinding(param.key());
                    }
                    return chosenMethod.unify(tree, unifier)
                            .transform(UnifierWithRemainingMembers.withRemaining(remainingMembers));
                }
            });
        }
    };
}

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

public static RangeSet<Long> fromIntervals(final Iterable<Interval> intervals) {
    final RangeSet<Long> retVal = TreeRangeSet.create();
    for (Interval interval : intervals) {
        retVal.add(Range.closedOpen(interval.getStartMillis(), interval.getEndMillis()));
    }// w ww.ja  v a  2s.  co  m
    return retVal;
}

From source file:eu.interedition.text.xml.OffsetMapper.java

private void add(int addToText, int addToSource) {
    if (addToText == 0 && addToSource == 0) {
        return;//from   w w w  . ja  v a2s .  c  o  m
    }

    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("Moving offsets: text += " + addToText + "; source += " + addToSource);
    }

    final int textOffsetRangeLength = textOffsetRange.upperEndpoint() - textOffsetRange.lowerEndpoint();
    final int sourceOffsetRangeLength = sourceOffsetRange.upperEndpoint() - sourceOffsetRange.lowerEndpoint();

    if (addToText == 0 && textOffsetRangeLength == 0) {
        sourceOffsetRange = Range.closedOpen(sourceOffsetRange.lowerEndpoint(),
                sourceOffsetRange.upperEndpoint() + addToSource);
    } else if (addToSource == 0 && sourceOffsetRangeLength == 0) {
        textOffsetRange = Range.closedOpen(textOffsetRange.lowerEndpoint(),
                textOffsetRange.upperEndpoint() + addToText);
    } else if (textOffsetRangeLength == sourceOffsetRangeLength && addToText == addToSource) {
        sourceOffsetRange = Range.closedOpen(sourceOffsetRange.lowerEndpoint(),
                sourceOffsetRange.upperEndpoint() + addToSource);
        textOffsetRange = Range.closedOpen(textOffsetRange.lowerEndpoint(),
                textOffsetRange.upperEndpoint() + addToText);
    } else {
        map();
        sourceOffsetRange = Range.closedOpen(sourceOffsetRange.upperEndpoint(),
                sourceOffsetRange.upperEndpoint() + addToSource);
        textOffsetRange = Range.closedOpen(textOffsetRange.upperEndpoint(),
                textOffsetRange.upperEndpoint() + addToText);
    }
}

From source file:org.dishevelled.bio.range.rtree.RangeGeometries.java

/**
 * Create and return a new rectangle geometry from the specified closed open range <code>[lower..upper)</code>.
 *
 * @param <N> value type/*from w ww .  ja v a2 s . co  m*/
 * @param lower lower endpoint, must not be null
 * @param upper upper endpoint, must not be null
 * @return a new rectangle geometry from the specified closed range
 */
public static <N extends Number & Comparable<? super N>> Rectangle closedOpen(final N lower, final N upper) {
    checkNotNull(lower);
    checkNotNull(upper);
    return range(Range.closedOpen(lower, upper));
}

From source file:crud.http.util.FailedResponseOperator.java

/**
 * Treat all non-200-range responses as errors.
 *//*from  w  w w  . jav a 2 s  .c om*/
public static FailedResponseOperator nonSuccessResponses() {
    if (nonSuccessResponses == null) {
        final ImmutableSet<Integer> prefix = ContiguousSet
                .create(Range.closedOpen(MIN_STATUS_CODE, MIN_SUCCESS_STATUS_CODE), DiscreteDomain.integers());
        final ImmutableSet<Integer> suffix = ContiguousSet
                .create(Range.openClosed(MAX_SUCCESS_STATUS_CODE, MAX_STATUS_CODE), DiscreteDomain.integers());
        final ImmutableSet<Integer> all = ImmutableSet.<Integer>builder().addAll(prefix).addAll(suffix).build();
        // Don't delegate to fromStatusCodes(): it does extraneous checking
        nonSuccessResponses = new FailedResponseOperator(all);
    }
    return nonSuccessResponses;
}