List of usage examples for com.google.common.collect Range upperEndpoint
public C upperEndpoint()
From source file:org.assertj.guava.error.RangeShouldHaveUpperEndpointEqual.java
public static <T extends Comparable<T>> ErrorMessageFactory shouldHaveEqualUpperEndpoint(final Range<T> actual, final Object value) { return new RangeShouldHaveUpperEndpointEqual("%n" + "Expecting:%n" + " <%s>%n" + "to have upper endpoint equal to:%n" + " <%s>%n" + "but was:%n" + " <%s>", actual, value, actual.upperEndpoint()); }
From source file:edu.mit.streamjit.impl.compiler2.InternalArrayConcreteStorage.java
public static StorageFactory initFactory(final Map<ActorGroup, Integer> initSchedule) { return (Storage storage) -> { Range<Integer> indices = storage.writeIndexSpan(initSchedule).span(storage.initialDataIndexSpan()); assert indices.upperBoundType() == BoundType.OPEN; int capacity = indices.upperEndpoint(); Arrayish array1 = new Arrayish.ArrayArrayish(storage.type(), capacity); return new InternalArrayConcreteStorage(array1, storage); };/* w w w .j a v a2 s .c o m*/ }
From source file:org.rf.ide.core.testdata.model.RobotExpressions.java
public static String resolve(final Map<String, String> knownVariables, final String expression) { final List<Range<Integer>> positions = getVariablesPositions(expression); Collections.sort(positions, new Comparator<Range<Integer>>() { @Override/*w ww .j a v a2s . c o m*/ public int compare(final Range<Integer> o1, final Range<Integer> o2) { return o2.lowerEndpoint().compareTo(o1.lowerEndpoint()); } }); final StringBuilder resolved = new StringBuilder(expression); for (final Range<Integer> position : positions) { final String variable = VariableNamesSupport.extractUnifiedVariableName( expression.substring(position.lowerEndpoint(), position.upperEndpoint() + 1)); if (knownVariables.containsKey(variable)) { resolved.replace(position.lowerEndpoint(), position.upperEndpoint() + 1, knownVariables.get(variable)); } } return resolved.toString(); }
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./*from ww w . j a v a 2s .co m*/ * <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.amelia.dsl.lib.util.Log.java
private static String cleanRedundantRegions(final List<Range<Integer>> regions, final String text) { String result = text;// w w w . j a v a2 s .c o m for (Range<Integer> r : regions) { result = result.substring(0, r.lowerEndpoint()) + "\u200B" + result.substring(r.lowerEndpoint() + 1, r.upperEndpoint()) + "\u200B" + result.substring(r.upperEndpoint() + 1); } return result; }
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;//from w w w.ja v a 2 s . com continue; } if (isEscaped && currentChar != '\\' && currentChar != '}') { escapedRegex.append('\\'); } escapedRegex.append(currentChar); isEscaped = false; } return escapedRegex.toString(); }
From source file:org.apache.druid.sql.calcite.filtration.Bounds.java
public static BoundDimFilter toFilter(final BoundRefKey boundRefKey, final Range<BoundValue> range) { return new BoundDimFilter(boundRefKey.getDimension(), range.hasLowerBound() ? range.lowerEndpoint().getValue() : null, range.hasUpperBound() ? range.upperEndpoint().getValue() : null, range.hasLowerBound() && range.lowerBoundType() == BoundType.OPEN, range.hasUpperBound() && range.upperBoundType() == BoundType.OPEN, null, boundRefKey.getExtractionFn(), boundRefKey.getComparator()); }
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:eu.itesla_project.modules.histo.HistoDbUtil.java
private static Range<Float> span(Range<Float> r1, Range<Float> r2) { return Range.closed( r2.lowerEndpoint() < r1.lowerEndpoint() || Float.isNaN(r1.lowerEndpoint()) ? r2.lowerEndpoint() : r1.lowerEndpoint(), r2.upperEndpoint() > r1.upperEndpoint() || Float.isNaN(r1.upperEndpoint()) ? r2.upperEndpoint() : r1.upperEndpoint()); }
From source file:org.amelia.dsl.lib.util.Log.java
private static String colorPairs(final String text) { String result = text;/* w w w . j a v a 2s . com*/ Map<ANSI, char[]> pairs = new HashMap<ANSI, char[]>(); pairs.put(ANSI.BLUE, new char[] { '(', ')' }); pairs.put(ANSI.MAGENTA, new char[] { '[', ']' }); pairs.put(ANSI.GREEN, new char[] { '{', '}' }); pairs.put(ANSI.CYAN, new char[] { '\'', '\'' }); pairs.put(ANSI.YELLOW, new char[] { '"', '"' }); for (ANSI color : pairs.keySet()) { char[] chars = pairs.get(color); PairMatcher matcher = new PairMatcher(result, chars[0], chars[1]); result = cleanRedundantRegions(matcher.redundantRegions(), result); matcher.removeRedundantRegions(); for (Range<Integer> r : matcher.getRegions()) { String start = result.substring(0, r.lowerEndpoint() + 1); String middle = result.substring(r.lowerEndpoint() + 1, r.upperEndpoint()); String end = result.substring(r.upperEndpoint()); String lastUsedColor = lastUsedColor(start); result = start + color.format(middle) + lastUsedColor + end; } } return result; }