List of usage examples for com.google.common.collect ImmutableList subList
@Override public ImmutableList<E> subList(int fromIndex, int toIndex)
From source file:com.google.javascript.rhino.jstype.TemplateTypeMap.java
/** * Returns a new TemplateTypeMap whose values have been extended with the * specified list.//ww w .j a v a 2 s . c om */ TemplateTypeMap addValues(ImmutableList<JSType> newValues) { // Ignore any new template values that will not align with an existing // template key. int numUnfilledKeys = numUnfilledTemplateKeys(); if (numUnfilledKeys < newValues.size()) { newValues = newValues.subList(0, numUnfilledKeys); } return registry.createTemplateTypeMap(templateKeys, concatImmutableLists(templateValues, newValues)); }
From source file:com.github.hilcode.versionator.impl.DefaultVersionChangeExtractor.java
Result<String, RequestedVersionChange> extractAny(final ImmutableList<String> arguments) { final int indexOfLastArgument = arguments.size() - 1; final String lastArgument = arguments.get(indexOfLastArgument); final Matcher matcher = GAV.matcher(lastArgument); if (!matcher.matches()) { return Result.failure(String .format("Expected a GAV, but you provided: '%s'.\n\n" + "Perhaps try --help?", lastArgument)); }// www.j a v a 2s.c om final Result<String, ImmutableList<Gav>> gavs = this.gavExtractor .extract(arguments.subList(0, indexOfLastArgument)); if (gavs.isFailure()) { return Result.asFailure(gavs); } else { final FromAnyToNewVersion versionChange = new FromAnyToNewVersion(this.matchers.toGav(matcher)); final Either<FromOldToNewVersion, FromAnyToNewVersion> fromAnyToNewVersion = Either .right(versionChange); return Result.success(new RequestedVersionChange(fromAnyToNewVersion, gavs.success())); } }
From source file:com.google.defcoin.crypto.DeterministicHierarchy.java
/** * Returns a key for the given path, optionally creating it. * * @param path the path to the key//from ww w . j av a2 s .c o m * @param relativePath whether the path is relative to the root path * @param create whether the key corresponding to path should be created (with any necessary ancestors) if it doesn't exist already * @return next newly created key using the child derivation function * @throws IllegalArgumentException if create is false and the path was not found. */ public DeterministicKey get(List<ChildNumber> path, boolean relativePath, boolean create) { ImmutableList<ChildNumber> absolutePath = relativePath ? ImmutableList.<ChildNumber>builder().addAll(rootPath).addAll(path).build() : ImmutableList.copyOf(path); if (!keys.containsKey(absolutePath)) { checkArgument(create, "No key found for {} path {}.", relativePath ? "relative" : "absolute", path); checkArgument(absolutePath.size() > 0, "Can't derive the master key: nothing to derive from."); DeterministicKey parent = get(absolutePath.subList(0, absolutePath.size() - 1), relativePath, true); putKey(HDKeyDerivation.deriveChildKey(parent, absolutePath.get(absolutePath.size() - 1))); } return keys.get(absolutePath); }
From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java
private static ImmutableList<InferredType> removeBackFromList(ImmutableList<InferredType> list, int countToRemove) { int origSize = list.size(); int index = origSize - 1; while (index >= 0 && countToRemove > 0) { InferredType type = list.get(index); if (type.equals(InferredType.TOP) && index > 0 && list.get(index - 1).isCategory2()) { --index; // A category 2 takes two slots. }// ww w .j ava2s. c o m --index; // Eat this local variable. --countToRemove; } checkState(countToRemove == 0, "countToRemove is %s but not 0. index=%s, list=%s", countToRemove, index, list); return list.subList(0, index + 1); }
From source file:com.google.javascript.rhino.jstype.TemplateTypeMap.java
TemplateTypeMap(JSTypeRegistry registry, ImmutableList<TemplateType> templateKeys, ImmutableList<JSType> templateValues) { Preconditions.checkNotNull(templateKeys); Preconditions.checkNotNull(templateValues); this.registry = registry; this.templateKeys = templateKeys; int nKeys = templateKeys.size(); this.templateValues = templateValues.size() > nKeys ? templateValues.subList(0, nKeys) : templateValues; // Iteratively resolve any JSType values that refer to the TemplateType keys // of this TemplateTypeMap. TemplateTypeMapReplacer replacer = new TemplateTypeMapReplacer(registry, this); ImmutableList.Builder<JSType> builder = ImmutableList.builder(); for (JSType templateValue : this.templateValues) { builder.add(templateValue.visit(replacer)); }//from w ww . jav a 2s. c o m this.resolvedTemplateValues = builder.build(); }
From source file:com.torodb.kvdocument.values.TwelveBytesValue.java
public TwelveBytesValue(ImmutableList<Byte> bytes) { Preconditions.checkArgument(bytes.size() <= 12, "The list size must be equal or smaller than 12 but " + bytes.size() + " were recived"); if (bytes.size() == 12) { this.bytes = bytes; } else {/*from www.j a v a 2 s.c om*/ ImmutableList.Builder<Byte> builder = ImmutableList.builder(); for (int i = 11; i >= bytes.size(); i--) { builder.add((byte) 0); } builder.addAll(bytes); this.bytes = bytes; } assert this.bytes.size() == 12; assert bytes.subList(12 - bytes.size(), 12).equals(bytes); }
From source file:com.facebook.buck.autodeps.AutodepsWriter.java
/** * Writes the {@code .autodeps} files in parallel using the {@code commandThreadManager}. * @param depsForBuildFiles Abstraction that contains the data that needs to be written to the * {@code .autodeps} files.// w ww .java2s . c om * @param buildFileName In practice, this should be derived from * {@link com.facebook.buck.rules.Cell#getBuildFileName()} * @param includeSignature Whether to insert a signature for the contents of the file. * @param mapper To aid in JSON serialization. * @return the number of files that were written. */ public static int write(DepsForBuildFiles depsForBuildFiles, String buildFileName, boolean includeSignature, ObjectMapper mapper, ListeningExecutorService executorService, int numThreads) throws ExecutionException { Preconditions.checkArgument(numThreads > 0, "Must be at least one thread available"); // We are going to divide the work into N groups, where N is the size of the thread pool. ImmutableList<DepsForBuildFiles.BuildFileWithDeps> buildFilesWithDeps = ImmutableList .copyOf(depsForBuildFiles); int numBuildFiles = buildFilesWithDeps.size(); if (numBuildFiles == 0) { return 0; } int chunkSize = numBuildFiles / numThreads; int extraItems = numBuildFiles % numThreads; // Add the work to the executor. Note that instead of creating one future per build file, we // create one future per thread. This should reduce object allocation and context switching. List<ListenableFuture<Integer>> futures = new ArrayList<>(); String autodepsFileName = buildFileName + GENERATED_BUILD_FILE_SUFFIX; for (int i = 0, endIndex = 0; i < numThreads; i++) { // Calculate how many items the thread should process. int numItemsToProcess = chunkSize; if (extraItems > 0) { numItemsToProcess++; extraItems--; } // Note that if buildFilesWithDeps.size() < numThreads, then this will be true for some // iterations of this loop. if (numItemsToProcess == 0) { break; } // Determine the subset of buildFilesWithDeps for the thread to process. int startIndex = endIndex; endIndex = startIndex + numItemsToProcess; ImmutableList<DepsForBuildFiles.BuildFileWithDeps> work = buildFilesWithDeps.subList(startIndex, endIndex); // Submit a job to the executor that will write .autodeps files, as appropriate. It will // return the number of .autodeps files it needed to write. ListenableFuture<Integer> future = executorService .submit(new AutodepsCallable(work, autodepsFileName, includeSignature, mapper)); futures.add(future); } // Sum up the total number of files written from each worker. int totalWritten = 0; ListenableFuture<List<Integer>> futuresList = Futures.allAsList(futures); for (int numWritten : Uninterruptibles.getUninterruptibly(futuresList)) { totalWritten += numWritten; } return totalWritten; }
From source file:org.killbill.billing.payment.provider.DefaultNoOpPaymentProviderPlugin.java
@Override public Pagination<PaymentTransactionInfoPlugin> searchPayments(final String searchKey, final Long offset, final Long limit, final Iterable<PluginProperty> properties, final TenantContext tenantContext) throws PaymentPluginApiException { final List<PaymentTransactionInfoPlugin> flattenedTransactions = ImmutableList .copyOf(Iterables.concat(payments.values())); final Collection<PaymentTransactionInfoPlugin> filteredTransactions = Collections2 .<PaymentTransactionInfoPlugin>filter(flattenedTransactions, new Predicate<PaymentTransactionInfoPlugin>() { @Override public boolean apply(final PaymentTransactionInfoPlugin input) { return (input.getKbPaymentId() != null && input.getKbPaymentId().toString().equals(searchKey)) || (input.getFirstPaymentReferenceId() != null && input.getFirstPaymentReferenceId().contains(searchKey)) || (input.getSecondPaymentReferenceId() != null && input.getSecondPaymentReferenceId().contains(searchKey)); }//from www . java 2 s . c om }); final ImmutableList<PaymentTransactionInfoPlugin> allResults = ImmutableList .<PaymentTransactionInfoPlugin>copyOf(filteredTransactions); final List<PaymentTransactionInfoPlugin> results; if (offset >= allResults.size()) { results = ImmutableList.<PaymentTransactionInfoPlugin>of(); } else if (offset + limit > allResults.size()) { results = allResults.subList(offset.intValue(), allResults.size()); } else { results = allResults.subList(offset.intValue(), offset.intValue() + limit.intValue()); } return new DefaultPagination<PaymentTransactionInfoPlugin>(offset, limit, (long) results.size(), (long) payments.values().size(), results.iterator()); }
From source file:com.matthewmitchell.nubitsj.crypto.DeterministicHierarchy.java
/** * Returns a key for the given path, optionally creating it. * * @param path the path to the key//www. j a va 2 s .c om * @param relativePath whether the path is relative to the root path * @param create whether the key corresponding to path should be created (with any necessary ancestors) if it doesn't exist already * @return next newly created key using the child derivation function * @throws IllegalArgumentException if create is false and the path was not found. */ public DeterministicKey get(List<ChildNumber> path, boolean relativePath, boolean create) { ImmutableList<ChildNumber> absolutePath = relativePath ? ImmutableList.<ChildNumber>builder().addAll(rootPath).addAll(path).build() : ImmutableList.copyOf(path); if (!keys.containsKey(absolutePath)) { if (!create) throw new IllegalArgumentException(String.format("No key found for %s path %s.", relativePath ? "relative" : "absolute", HDUtils.formatPath(path))); checkArgument(absolutePath.size() > 0, "Can't derive the master key: nothing to derive from."); DeterministicKey parent = get(absolutePath.subList(0, absolutePath.size() - 1), false, true); putKey(HDKeyDerivation.deriveChildKey(parent, absolutePath.get(absolutePath.size() - 1))); } return keys.get(absolutePath); }
From source file:org.glowroot.agent.live.LiveJvmServiceImpl.java
@Override public List<String> getMatchingMBeanObjectNames(String agentId, String partialObjectName, int limit) throws Exception { ObjectNameQueryExp queryExp = new ObjectNameQueryExp(partialObjectName); List<MBeanServer> mbeanServers = lazyPlatformMBeanServer.findAllMBeanServers(); Set<ObjectName> objectNames = lazyPlatformMBeanServer.queryNames(null, queryExp, mbeanServers); // unfortunately Wildfly returns lots of mbean object names without checking them against // the query (see TODO comment in org.jboss.as.jmx.model.ModelControllerMBeanHelper) // so must re-filter List<String> names = Lists.newArrayList(); for (ObjectName objectName : objectNames) { String objectNameStr = objectName.toString(); if (queryExp.apply(objectNameStr)) { names.add(objectNameStr);//w ww .ja va 2 s .c o m } } ImmutableList<String> sortedNames = Ordering.natural().immutableSortedCopy(names); if (sortedNames.size() > limit) { sortedNames = sortedNames.subList(0, limit); } return sortedNames; }