List of usage examples for com.google.common.collect Range closed
public static <C extends Comparable<?>> Range<C> closed(C lower, C upper)
From source file:net.sf.mzmine.util.RangeUtils.java
public static Range<Double> fromArray(double array[]) { if ((array == null) || (array.length == 0)) return Range.open(0.0, 0.0); double min = array[0], max = array[0]; for (double d : array) { if (d > max) max = d;/* w w w . ja v a2s .c o m*/ if (d < min) min = d; } return Range.closed(min, max); }
From source file:net.sf.mzmine.parameters.parametertypes.ranges.DoubleRangeComponent.java
public Range<Double> getValue() { String minString = minTxtField.getText(); String maxString = maxTxtField.getText(); try {// ww w . jav a 2s . c o m Number minValue = format.parse(minString); Number maxValue = format.parse(maxString); if ((minValue == null) || (maxValue == null)) return null; return Range.closed(minValue.doubleValue(), maxValue.doubleValue()); } catch (Exception e) { return null; } }
From source file:org.asoem.greyfish.utils.collect.LinearSequences.java
/** * Create a crossover product between two {@code Iterables} with crossovers at given {@code indices}. This means * that both {@code Iterable}s in the returned product are a combination of the input iterables in such a way, that * the constructed iterable switches the input iterable at each given position. Both input {@code Iterable}s will be * zipped with {@link Products#zip(Iterable, Iterable)}. Therefore the returned {@code Iterable}s will have the same * size equal to the size of the input iterable with the fewest elements. * * @param x The first Iterable/* w w w . j a v a 2 s.co m*/ * @param y The second Iterable * @param indices the indices at which to do the crossovers * @param <E> the type of the elements in {@code Iterable}s * @return a product of Iterables with crossovers at the given indices */ public static <E> Product2<Iterable<E>, Iterable<E>> crossover(final Iterable<E> x, final Iterable<E> y, final Set<Integer> indices) { checkNotNull(x); checkNotNull(y); checkNotNull(indices); final Iterable<Product2<E, E>> zipped = Products.zip(x, y); if (indices.isEmpty()) { return Products.unzip(zipped); } else { final FunctionalList<Range<Integer>> ranges = ImmutableFunctionalList.copyOf( Iterables.transform(Iterables.partition(Ordering.natural().immutableSortedCopy(indices), 2), new Function<List<Integer>, Range<Integer>>() { @Nullable @Override public Range<Integer> apply(@Nullable final List<Integer> input) { assert input != null; return input.size() == 2 ? Range.closed(input.get(0), input.get(1)) : Range.atLeast(input.get(0)); } })); return Products.unzip(Iterables.transform(Products.zipWithIndex(zipped), new Function<Product2<Product2<E, E>, Integer>, Product2<E, E>>() { @Nullable @Override public Product2<E, E> apply(@Nullable final Product2<Product2<E, E>, Integer> input) { assert input != null; return ranges.any(new Predicate<Range<Integer>>() { @Override public boolean apply(@Nullable final Range<Integer> range) { assert range != null; return range.contains(input.second()); } }) ? Products.swap(input.first()) : input.first(); } })); } }
From source file:crud.http.util.FailedResponseOperator.java
/** * Treat all 500-range responses as errors. *//* w w w .j a v a 2 s . c o m*/ public static FailedResponseOperator serverErrors() { if (serverErrors == null) { // Don't delegate to fromStatusCodes(): it does extraneous checking serverErrors = new FailedResponseOperator( ContiguousSet.create(Range.closed(MIN_SERVER_ERROR_STATUS_CODE, MAX_SERVER_ERROR_STATUS_CODE), DiscreteDomain.integers())); } return serverErrors; }
From source file:org.robotframework.ide.eclipse.main.plugin.project.build.ProblemsReportingStrategy.java
public void handleProblem(final RobotProblem problem, final IFile file, final RobotToken token, final Map<String, Object> additionalAttributes) { final ProblemPosition position = new ProblemPosition(token.getLineNumber(), Range.closed(token.getStartOffset(), token.getStartOffset() + token.getText().length())); handleProblem(problem, file, position, additionalAttributes); }
From source file:io.github.msdk.util.ChromatogramUtil.java
/** * Returns the range of intensity values of all data points in this * chromatogram./* w ww . j a v a 2s . co m*/ * * @return a {@link com.google.common.collect.Range} object. * @param intensityValues * an array of {@link java.lang.Float} objects. * @param size * a {@link java.lang.Integer} object. */ public static @Nullable Range<Float> getDataPointsIntensityRange(@Nonnull Float intensityValues[], @Nonnull Integer size) { // Parameter check Preconditions.checkNotNull(intensityValues); Preconditions.checkNotNull(size); Preconditions.checkPositionIndex(size, intensityValues.length); if (size == 0) return null; float lower = intensityValues[0]; float upper = intensityValues[0]; for (int i = 0; i < size; i++) { if (intensityValues[i] < lower) lower = intensityValues[i]; if (intensityValues[i] > upper) upper = intensityValues[i]; } final Range<Float> intensityRange = Range.closed(lower, upper); return intensityRange; }
From source file:com.github.piotrkot.health.ServerHealthCheck.java
@Override public Result check() throws Exception { Result result = Result.healthy(); if (this.addr.isEmpty() || !Range.closed(HTTP_OK_MIN, HTTP_OK_MAX) .contains(Request.Get(this.addr).execute().returnResponse().getStatusLine().getStatusCode())) { result = Result.unhealthy("No connection to the server"); }/*from www. jav a 2 s .com*/ return result; }
From source file:algorithm.Chromosome.java
/** * Validate the coordinates, throws an exception if any of the coordinates * is not [0, (NUMBER_GENES - 1)]/*w w w .ja v a 2s .c o m*/ * * @throws IllegalArgumentException If any of the coordinates is not within bounds. */ private void validateCoordinates(ArrayList<Integer> coordinates) throws IllegalArgumentException { for (Integer coordinate : coordinates) { if (!Range.closed(0, (NUMBER_GENES - 1)).contains(coordinate)) { throw new IllegalArgumentException( "Invalid coordinate value, must be between [0, " + (NUMBER_GENES - 1) + "]"); } } }
From source file:be.nbb.jackcess.JackcessResultSet.java
@Nonnull public Range<RowId> getRange() throws IOException { RowId lower = (RowId) currentRow[currentRow.length - 2]; RowId upper = (RowId) currentRow[currentRow.length - 1]; return Range.closed(lower, upper); }
From source file:net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance.java
public Range<Double> getToleranceRange(final Range<Double> mzRange) { return Range.closed(mzRange.lowerEndpoint() - getMzToleranceForMass(mzRange.lowerEndpoint()), mzRange.upperEndpoint() + getMzToleranceForMass(mzRange.upperEndpoint())); }