Codota Logo
MoreCollectors
Code IndexAdd Codota to your IDE (free)

How to use
MoreCollectors
in
com.google.common.collect

Best Java code snippets using com.google.common.collect.MoreCollectors (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
DateTime d =
  • Codota Iconnew DateTime()
  • Codota IconDateTimeFormatter formatter;String text;formatter.parseDateTime(text)
  • Codota IconObject instant;new DateTime(instant)
  • Smart code suggestions by Codota
}
origin: google/error-prone

static TypeParameterTree typeParameterInList(
  List<? extends TypeParameterTree> typeParameters, Symbol v) {
 return typeParameters.stream()
   .filter(t -> t.getName().contentEquals(v.name))
   .collect(MoreCollectors.onlyElement());
}
origin: prestodb/presto

  @Override
  public Optional<SystemTable> getSystemTable(ConnectorSession session, SchemaTableName tableName)
  {
    return delegates.stream()
        .map(delegate -> delegate.getSystemTable(session, tableName))
        .filter(Optional::isPresent)
        // this ensures there is 0 or 1 element in stream
        .map(Optional::get)
        .collect(toOptional());
  }
}
origin: google/data-transfer-project

@VisibleForTesting
static TransferExtension findTransferExtension(
  ImmutableList<TransferExtension> transferExtensions, String service) {
 try {
  return transferExtensions
    .stream()
    .filter(ext -> ext.getServiceId().toLowerCase().equals(service.toLowerCase()))
    .collect(onlyElement());
 } catch (IllegalArgumentException e) {
  throw new IllegalStateException(
    "Found multiple transfer extensions for service " + service, e);
 } catch (NoSuchElementException e) {
  throw new IllegalStateException(
    "Did not find a valid transfer extension for service " + service, e);
 }
}
origin: google/error-prone

private static Optional<? extends VariableTree> findParameterWithSymbol(
  List<? extends VariableTree> parameters, Symbol symbol) {
 return parameters.stream()
   .filter(parameter -> symbol.equals(ASTHelpers.getSymbol(parameter)))
   .collect(toOptional());
}
origin: google/guava

public void testOnlyElement() {
 try {
  Stream.empty().collect(MoreCollectors.onlyElement());
  fail("Expected NoSuchElementException");
 } catch (NoSuchElementException expected) {
 }
}
origin: prestodb/presto

/**
 * Resolves a node by materializing GroupReference nodes
 * representing symbolic references to other nodes. This method
 * is deprecated since is assumes group contains only one node.
 * <p>
 * If the node is not a GroupReference, it returns the
 * argument as is.
 */
@Deprecated
default PlanNode resolve(PlanNode node)
{
  if (node instanceof GroupReference) {
    return resolveGroup(node).collect(toOptional()).get();
  }
  return node;
}
origin: google/guava

public void testOnlyElementNull() {
 assertThat(Stream.of((Object) null).collect(MoreCollectors.onlyElement())).isNull();
}
origin: google/guava

public void testToOptionalNull() {
 Stream<Object> stream = Stream.of((Object) null);
 try {
  stream.collect(MoreCollectors.toOptional());
  fail("Expected NullPointerException");
 } catch (NullPointerException expected) {
 }
}
origin: google/guava

public void testOnlyElementSingleton() {
 assertThat(Stream.of(1).collect(MoreCollectors.onlyElement())).isEqualTo(1);
}
origin: google/guava

public void testToOptionalMany() {
 try {
  Stream.of(1, 2, 3, 4, 5, 6).collect(MoreCollectors.toOptional());
  fail("Expected IllegalArgumentException");
 } catch (IllegalArgumentException expected) {
  assertThat(expected.getMessage()).contains("1, 2, 3, 4, 5, ...");
 }
}
origin: google/guava

 public void testOnlyElementMany() {
  try {
   Stream.of(1, 2, 3, 4, 5, 6).collect(MoreCollectors.onlyElement());
   fail("Expected IllegalArgumentException");
  } catch (IllegalArgumentException expected) {
   assertThat(expected.getMessage()).contains("1, 2, 3, 4, 5, ...");
  }
 }
}
origin: google/guava

public void testToOptionalMultiple() {
 try {
  Stream.of(1, 2).collect(MoreCollectors.toOptional());
  fail("Expected IllegalArgumentException");
 } catch (IllegalArgumentException expected) {
  assertThat(expected.getMessage()).contains("1, 2");
 }
}
origin: google/guava

public void testOnlyElementMultiple() {
 try {
  Stream.of(1, 2).collect(MoreCollectors.onlyElement());
  fail("Expected IllegalArgumentException");
 } catch (IllegalArgumentException expected) {
  assertThat(expected.getMessage()).contains("1, 2");
 }
}
origin: prestodb/presto

private synchronized void callOomKiller(Iterable<QueryExecution> runningQueries)
{
  List<QueryMemoryInfo> queryMemoryInfoList = Streams.stream(runningQueries)
      .map(this::createQueryMemoryInfo)
      .collect(toImmutableList());
  List<MemoryInfo> nodeMemoryInfos = nodes.values().stream()
      .map(RemoteNodeMemory::getInfo)
      .filter(Optional::isPresent)
      .map(Optional::get)
      .collect(toImmutableList());
  Optional<QueryId> chosenQueryId = lowMemoryKiller.chooseQueryToKill(queryMemoryInfoList, nodeMemoryInfos);
  if (chosenQueryId.isPresent()) {
    log.debug("Low memory killer chose %s", chosenQueryId.get());
    Optional<QueryExecution> chosenQuery = Streams.stream(runningQueries).filter(query -> chosenQueryId.get().equals(query.getQueryId())).collect(toOptional());
    if (chosenQuery.isPresent()) {
      // See comments in  isLastKilledQueryGone for why chosenQuery might be absent.
      chosenQuery.get().fail(new PrestoException(CLUSTER_OUT_OF_MEMORY, "Query killed because the cluster is out of memory. Please try again in a few minutes."));
      queriesKilledDueToOutOfMemory.incrementAndGet();
      lastKilledQuery = chosenQueryId.get();
      logQueryKill(chosenQueryId.get(), nodeMemoryInfos);
    }
  }
}
origin: prestodb/presto

    (int) idCount.values().stream()
        .distinct()
        .collect(onlyElement()),
    3);
assertEquals(idCount.keySet(), expectedIds);
origin: google/guava

public void testToOptionalSingleton() {
 assertThat(Stream.of(1).collect(MoreCollectors.toOptional())).hasValue(1);
}
origin: google/bundletool

private static ImmutableSet<AbiAlias> getMultiAbi(VariantTargeting variantTargeting) {
 if (variantTargeting.getMultiAbiTargeting().getValueList().isEmpty()) {
  return ImmutableSet.of();
 }
 return variantTargeting.getMultiAbiTargeting().getValueList().stream()
   // For now we only support one value in MultiAbiTargeting.
   .collect(MoreCollectors.onlyElement())
   .getAbiList()
   .stream()
   .map(Abi::getAlias)
   .collect(toImmutableSet());
}
origin: google/guava

public void testToOptionalEmpty() {
 assertThat(Stream.empty().collect(MoreCollectors.toOptional())).isEmpty();
}
origin: google/bundletool

private static Optional<AbiAlias> getAbi(VariantTargeting variantTargeting) {
 if (variantTargeting.getAbiTargeting().getValueList().isEmpty()) {
  return Optional.empty();
 }
 return Optional.of(
   variantTargeting
     .getAbiTargeting()
     .getValueList()
     .stream()
     // For now we only support one value in AbiTargeting.
     .collect(MoreCollectors.onlyElement())
     .getAlias());
}
origin: google/bundletool

/**
 * Returns a single variant matching a full device-spec.
 *
 * @throws IllegalArgumentException if multiple variants are matched.
 */
public Optional<Variant> getMatchingVariant(BuildApksResult buildApksResult) {
 return getAllMatchingVariants(buildApksResult).stream().collect(MoreCollectors.toOptional());
}
com.google.common.collectMoreCollectors

Javadoc

Collectors not present in java.util.stream.Collectors that are not otherwise associated with a com.google.common type.

Most used methods

  • onlyElement
    A collector that takes a stream containing exactly one element and returns that element. The returne
  • toOptional
    A collector that converts a stream of zero or one elements to an Optional. The returned collector th

Popular in Java

  • Creating JSON documents from java classes using gson
  • scheduleAtFixedRate (ScheduledExecutorService)
  • putExtra (Intent)
  • notifyDataSetChanged (ArrayAdapter)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • PrintStream (java.io)
    A PrintStream adds functionality to another output stream, namely the ability to print representatio
  • BitSet (java.util)
    This class implements a vector of bits that grows as needed. Each component of the bit set has a boo
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • JLabel (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now