List of usage examples for com.google.common.collect Range lowerEndpoint
public C lowerEndpoint()
From source file:com.github.fhirschmann.clozegen.lib.util.CollectionUtils.java
/** * Returns a view of a list made up of the n adjacent neighbors of an element * and the element itself./*www . j av a 2s . c om*/ * <p> * For example, assuming the list is something like [1, 2, 3, 4, 5, 6], * then getAdjacentTo(3, 1) will yield [2, 3, 4]. * </p> * <p> * The returned list is backed by this list, so non-structural changes in the * returned list are reflected in this list, and vice-versa. The returned list * supports all of the optional list operations supported by this list. * </p> * <p> * * @param <T> the type of the list elements * @param list the list to use * @param index the index of the element to get the adjacent neighbors for * @param num the number of neighbors (on each side) to include * @return a view based on the specified parameters */ public static <T> List<T> getAdjacentTo(final List<T> list, final int index, final int num) { /* The num adjacent neighbors of an element intersected with the list's bounds */ final Range<Integer> range = Ranges.closed(index - num, index + num) .intersection(Ranges.closed(0, list.size() - 1)); return list.subList(range.lowerEndpoint(), range.upperEndpoint() + 1); }
From source file:org.assertj.guava.error.RangeShouldHaveLowerEndpointEqual.java
public static <T extends Comparable<T>> ErrorMessageFactory shouldHaveEqualLowerEndpoint(final Range<T> actual, final Object value) { return new RangeShouldHaveLowerEndpointEqual("%n" + "Expecting:%n" + " <%s>%n" + "to have lower endpoint equal to:%n" + " <%s>%n" + "but was:%n" + " <%s>", actual, value, actual.lowerEndpoint()); }
From source file:com.google.android.apps.forscience.whistlepunk.NextRequestType.java
static NextRequestType compute(Range<Long> alreadyRequested, long minWanted, long maxWanted) { if (maxWanted < minWanted) { return NONE; } else if (alreadyRequested == null) { return FIRST; } else if (alreadyRequested.hasLowerBound() && minWanted < alreadyRequested.lowerEndpoint()) { return NEXT_LOWER; } else if (alreadyRequested.hasUpperBound() && maxWanted > alreadyRequested.upperEndpoint()) { return NEXT_HIGHER; } else {//from ww w . j a va2s .c om return NONE; } }
From source file:org.rf.ide.core.testdata.model.table.keywords.names.EmbeddedKeywordNamesSupport.java
private static String getEmbeddedArgumentRegex(final String definitionName, final Range<Integer> varRange) { final String varContent = definitionName.substring(varRange.lowerEndpoint() + 2, varRange.upperEndpoint()); final String unescapedRegex = varContent.indexOf(':') != -1 ? varContent.substring(varContent.indexOf(':') + 1) : ".+"; boolean isEscaped = false; final StringBuilder escapedRegex = new StringBuilder(); for (int i = 0; i < unescapedRegex.length(); i++) { final char currentChar = unescapedRegex.charAt(i); if (!isEscaped && currentChar == '\\') { isEscaped = true;// www. java2s . c o m continue; } if (isEscaped && currentChar != '\\' && currentChar != '}') { escapedRegex.append('\\'); } escapedRegex.append(currentChar); isEscaped = false; } return escapedRegex.toString(); }
From source file:org.obiba.opal.web.gwt.app.client.magma.derive.view.ValueMapEntry.java
public static Builder fromRange(Range<? extends Number> range) { return fromRange(range.hasLowerBound() ? range.lowerEndpoint() : null, range.hasUpperBound() ? range.upperEndpoint() : null).label(range.toString()); }
From source file:com.google.googlejavaformat.java.SnippetFormatter.java
private static Range<Integer> offsetRange(Range<Integer> range, int offset) { range = range.canonical(DiscreteDomain.integers()); return Range.closedOpen(range.lowerEndpoint() + offset, range.upperEndpoint() + offset); }
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 {/*from w w w. ja va 2s.c o 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: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 w ww . j a va2 s. c om } int max = range.upperEndpoint(); if (range.upperBoundType() == BoundType.CLOSED) { max++; } return random.nextInt(max - min) + min; }
From source file:com.github.fge.grappa.matchers.join.JoinMatcherBuilder.java
private static Range<Integer> toClosedRange(Range<Integer> range) { /*//from w w w .j av a 2 s .c om * The canonical form will always be the same: closed on the lower bound * (if any; but here we are guaranteed that), open on the upper bound * (if any). * * All we have to do is therefore to pick the canonical representation, * pick the lower bound, and if it has an upper bound, pick it and * substract 1. */ Range<Integer> canonical = range.canonical(DiscreteDomain.integers()); int lowerBound = canonical.lowerEndpoint(); return canonical.hasUpperBound() ? Range.closed(lowerBound, canonical.upperEndpoint() - 1) : Range.atLeast(lowerBound); }
From source file:be.nbb.jackcess.CursorFacade.java
@Nonnull public static CursorFacade range(@Nonnull Table table, @Nonnull Range<RowId> range) throws IOException { CursorFacade basic = basic(table);/*w w w .ja v a 2s .c o m*/ if (range.hasLowerBound()) { basic.moveBefore(range.lowerEndpoint()); } return range.hasUpperBound() ? new UpperBounded(basic, range.upperEndpoint()) : basic; }