List of usage examples for com.google.common.collect ImmutableList subList
@Override public ImmutableList<E> subList(int fromIndex, int toIndex)
From source file:com.palantir.atlasdb.keyvalue.remoting.RemotingKeyValueService.java
private static <T> RangeIterator<T> transformIterator(String tableName, RangeRequest range, long timestamp, ClosableIterator<RowResult<T>> closableIterator, Function<Pair<Boolean, ImmutableList<RowResult<T>>>, RangeIterator<T>> resultSupplier) { try {/*from w w w . ja v a 2s. c om*/ int pageSize = range.getBatchHint() != null ? range.getBatchHint() : 100; if (pageSize == 1) { pageSize = 2; } ImmutableList<RowResult<T>> page = ImmutableList.copyOf(Iterators.limit(closableIterator, pageSize)); if (page.size() < pageSize) { return resultSupplier.apply(Pair.create(false, page)); } else { return resultSupplier.apply(Pair.create(true, page.subList(0, pageSize - 1))); } } finally { closableIterator.close(); } }
From source file:com.github.rinde.logistics.pdptw.solver.CheapestInsertionHeuristic.java
static <T> ImmutableList<ImmutableList<T>> modifySchedule(ImmutableList<ImmutableList<T>> originalSchedule, ImmutableList<T> vehicleSchedule, int vehicleIndex) { checkArgument(vehicleIndex >= 0 && vehicleIndex < originalSchedule.size(), "Vehicle index must be >= 0 && < %s, it is %s.", originalSchedule.size(), vehicleIndex); final ImmutableList.Builder<ImmutableList<T>> builder = ImmutableList.builder(); builder.addAll(originalSchedule.subList(0, vehicleIndex)); builder.add(vehicleSchedule);/*from w ww. ja v a2 s . com*/ builder.addAll(originalSchedule.subList(vehicleIndex + 1, originalSchedule.size())); return builder.build(); }
From source file:de.ii.xtraplatform.feature.provider.pgis.MixAndMatch.java
public static <T> Source<T, NotUsed> create(Predicate<Pair<T, T>> matcher, Source<T, NotUsed>... sources) { ImmutableList<Source<T, ?>> sourcesList = ImmutableList.copyOf(sources); return Source.combine(sourcesList.get(0), sourcesList.get(1), sourcesList.size() > 2 ? sourcesList.subList(2, sourcesList.size()) : ImmutableList.of(), numberOfSources -> new MixAndMatchStage<>(numberOfSources, matcher)); }
From source file:de.ii.xtraplatform.feature.provider.pgis.MixAndMatch.java
public static <T> Source<T, NotUsed> create(Map<Integer, List<Integer>> sourceNesting, Map<Integer, Predicate<Pair<T, T>>> matchers, int mainSourceIndex, Source<T, NotUsed>... sources) { ImmutableList<Source<T, ?>> sourcesList = ImmutableList.copyOf(sources); return Source.combine(sourcesList.get(0), sourcesList.get(1), sourcesList.size() > 2 ? sourcesList.subList(2, sourcesList.size()) : ImmutableList.of(), numberOfSources -> new MixAndMatchStage<>(numberOfSources, sourceNesting, matchers, mainSourceIndex));//from w ww . j a va2s . com }
From source file:com.facebook.buck.parser.implicit.AbstractImplicitInclude.java
/** * Constructs a {@link AbstractImplicitInclude} from a configuration string in the form of * * <p>//path/to:bzl_file.bzl::symbol_to_import::second_symbol_to_import * * @param configurationString The string used in configuration * @return A parsed {@link AbstractImplicitInclude} object * @throws {@link HumanReadableException} if the configuration string is invalid */// w ww.j av a 2 s .c o m public static ImplicitInclude fromConfigurationString(String configurationString) { // Double colons are used so that if someone uses an absolute windows path, their error // messages will not be confusing. e.g. C:\foo.bzl:bar would lead to a file named // 'C', and symbols '\foo.bzl' and 'bar'. This just makes things explicit. ImmutableList<String> parts = Arrays.stream(configurationString.split("::")).map(String::trim) .collect(ImmutableList.toImmutableList()); if (parts.size() < 2) { throw new HumanReadableException( "Configuration setting '%s' did not list any symbols to load. Setting should be of " + "the format //<load label>::<symbol1>::<symbol2>...", configurationString); } String rawLabel = validateLabelFromConfiguration(parts.get(0), configurationString); ImmutableMap<String, String> symbols = parseAllSymbolsFromConfiguration(parts.subList(1, parts.size()), configurationString); return ImplicitInclude.of(rawLabel, symbols); }
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//from w ww .ja v a 2 s. com 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:org.glowroot.api.internal.ThrowableInfo.java
private static ThrowableInfo from(Throwable t, @Nullable List<StackTraceElement> causedStackTrace) { int framesInCommon = 0; ImmutableList<StackTraceElement> stackTrace = ImmutableList.copyOf(t.getStackTrace()); if (causedStackTrace != null) { ListIterator<StackTraceElement> i = stackTrace.listIterator(stackTrace.size()); ListIterator<StackTraceElement> j = causedStackTrace.listIterator(causedStackTrace.size()); while (i.hasPrevious() && j.hasPrevious()) { StackTraceElement element = i.previous(); StackTraceElement causedElement = j.previous(); if (!element.equals(causedElement)) { break; }// w w w. j ava 2 s . co m framesInCommon++; } if (framesInCommon > 0) { // strip off common frames stackTrace = stackTrace.subList(0, stackTrace.size() - framesInCommon); } } ImmutableThrowableInfo.Builder builder = ImmutableThrowableInfo.builder().display(t.toString()) .addAllStackTrace(stackTrace).framesInCommonWithCaused(framesInCommon); Throwable cause = t.getCause(); if (cause != null) { // pass t's original stack trace to construct the nested cause // (not stackTraces, which now has common frames removed) builder.cause(from(cause, Arrays.asList(t.getStackTrace()))); } return builder.build(); }
From source file:com.google.devtools.build.lib.query2.engine.BinaryOperatorExpression.java
/** * Evaluates an expression of the form "e1 - e2 - ... - eK" by noting its equivalence to * "e1 - (e2 + ... + eK)" and evaluating the subexpressions on the right-hand-side in parallel. *//*w w w . ja v a 2s . co m*/ private static <T> void parEvalMinus(ImmutableList<QueryExpression> operands, QueryEnvironment<T> env, VariableContext<T> context, ThreadSafeCallback<T> callback, ForkJoinPool forkJoinPool) throws QueryException, InterruptedException { final Set<T> lhsValue = Sets.newConcurrentHashSet(QueryUtil.evalAll(env, context, operands.get(0))); ThreadSafeCallback<T> subtractionCallback = new ThreadSafeCallback<T>() { @Override public void process(Iterable<T> partialResult) throws QueryException, InterruptedException { for (T target : partialResult) { lhsValue.remove(target); } } }; parEvalPlus(operands.subList(1, operands.size()), env, context, subtractionCallback, forkJoinPool); callback.process(lhsValue); }
From source file:com.palantir.common.base.BatchingVisitables.java
public static <T, TOKEN> TokenBackedBasicResultsPage<T, TOKEN> getFirstPage(BatchingVisitable<T> v, int numToVisitArg, Function<T, TOKEN> tokenExtractor) { Preconditions.checkArgument(numToVisitArg >= 0, "numToVisit cannot be negative. Value was: " + numToVisitArg); if (numToVisitArg == Integer.MAX_VALUE) { // prevent issue with overflow numToVisitArg--;/* w ww. j a va2 s . c om*/ } final int numToVisit = numToVisitArg + 1; ImmutableList<T> list = BatchingVisitableView.of(v).limit(numToVisit).immutableCopy(); Preconditions.checkState(list.size() <= numToVisit); if (list.size() >= numToVisit) { TOKEN token = tokenExtractor.apply(list.get(list.size() - 1)); list = list.subList(0, numToVisit - 1); return new SimpleTokenBackedResultsPage<T, TOKEN>(token, list, true); } return new SimpleTokenBackedResultsPage<T, TOKEN>(null, list, false); }
From source file:org.glowroot.agent.model.ErrorMessage.java
private static StackTraceWithoutCommonFrames getStackTraceAndFramesInCommon( StackTraceElement[] stackTraceElements, @Nullable List<StackTraceElement> causedStackTrace, AtomicInteger transactionThrowableFrameCount) { if (transactionThrowableFrameCount.get() >= TRANSACTION_THROWABLE_FRAME_LIMIT) { return ImmutableStackTraceWithoutCommonFrames.builder().build(); }//w w w . j a va2s. com if (causedStackTrace == null) { return ImmutableStackTraceWithoutCommonFrames.builder().addStackTrace(stackTraceElements).build(); } ImmutableList<StackTraceElement> stackTrace = ImmutableList.copyOf(stackTraceElements); int framesInCommonWithEnclosing = 0; ListIterator<StackTraceElement> i = stackTrace.listIterator(stackTrace.size()); ListIterator<StackTraceElement> j = causedStackTrace.listIterator(causedStackTrace.size()); while (i.hasPrevious() && j.hasPrevious()) { StackTraceElement element = i.previous(); StackTraceElement causedElement = j.previous(); if (!element.equals(causedElement)) { break; } framesInCommonWithEnclosing++; } if (framesInCommonWithEnclosing > 0) { // strip off common frames stackTrace = stackTrace.subList(0, stackTrace.size() - framesInCommonWithEnclosing); } return ImmutableStackTraceWithoutCommonFrames.builder().stackTrace(stackTrace) .framesInCommonWithEnclosing(framesInCommonWithEnclosing).build(); }