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

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

Best Java code snippets using com.google.common.collect.MoreCollectors.onlyElement (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: 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/guava

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

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

public void testOnlyElementSingleton() {
 assertThat(Stream.of(1).collect(MoreCollectors.onlyElement())).isEqualTo(1);
}
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 testOnlyElementMultiple() {
 try {
  Stream.of(1, 2).collect(MoreCollectors.onlyElement());
  fail("Expected IllegalArgumentException");
 } catch (IllegalArgumentException expected) {
  assertThat(expected.getMessage()).contains("1, 2");
 }
}
origin: prestodb/presto

    (int) idCount.values().stream()
        .distinct()
        .collect(onlyElement()),
    3);
assertEquals(idCount.keySet(), expectedIds);
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/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

 public static Optional<Integer> getScreenDensityDpi(
   ScreenDensityTargeting screenDensityTargeting) {
  if (screenDensityTargeting.getValueList().isEmpty()) {
   return Optional.empty();
  }

  ScreenDensity densityTargeting =
    screenDensityTargeting.getValueList().stream()
      // For now we only support one value in ScreenDensityTargeting.
      .collect(MoreCollectors.onlyElement());
  return Optional.of(
    densityTargeting.getDensityOneofCase().equals(DENSITY_ALIAS)
      ? DENSITY_ALIAS_TO_DPI_MAP.get(densityTargeting.getDensityAlias())
      : densityTargeting.getDensityDpi());
 }
}
origin: google/bundletool

extractFilesFromJar(outputDir, osDirUrl, osDir);
try (Stream<Path> aapt2Binaries = Files.find(outputDir, /* maxDepth= */ 3, AAPT2_MATCHER)) {
 aapt2 = aapt2Binaries.collect(onlyElement());
origin: google/bundletool

 private static ModuleSplit findModuleSplitWithDefaultTargeting(
   ImmutableCollection<ModuleSplit> moduleSplits) {
  return moduleSplits.stream()
    .filter(split -> split.getApkTargeting().equals(ApkTargeting.getDefaultInstance()))
    .collect(onlyElement());
 }
}
origin: google/bundletool

private static ModuleSplit findModuleSplitWithScreenDensityTargeting(
  ImmutableCollection<ModuleSplit> moduleSplits, ScreenDensity density) {
 return moduleSplits.stream()
   .filter(
     split ->
       split.getApkTargeting().getScreenDensityTargeting().getValueCount() > 0
         && density.equals(
           split.getApkTargeting().getScreenDensityTargeting().getValue(0)))
   .collect(onlyElement());
}
origin: google/bundletool

 @Test
 public void modifyingDeepElementReflectsChangeInParentsToo() throws Exception {
  XmlNode.Builder xmlNode = XmlNode.newBuilder();
  TextFormat.merge(TestData.openReader("testdata/manifest/manifest1.textpb"), xmlNode);

  XmlProtoNodeBuilder node = new XmlProtoNode(xmlNode.build()).toBuilder();
  node.getElement()
    .getChildElement("uses-sdk")
    .getOrCreateAndroidAttribute("minSdkVersion", 0x0101020c)
    .setValueAsDecimalInteger(999);

  assertThat(
      node.build()
        .getProto()
        .getElement()
        .getChildList()
        .stream()
        .filter(childNode -> childNode.getElement().getName().equals("uses-sdk"))
        .collect(onlyElement())
        .getElement()
        .getAttributeList()
        .stream()
        .filter(attribute -> attribute.getName().equals("minSdkVersion"))
        .collect(onlyElement())
        .getCompiledItem()
        .getPrim()
        .getIntDecimalValue())
    .isEqualTo(999);
 }
}
origin: google/bundletool

@Test
public void process_fileExists() {
 InMemoryModuleEntry existingInMemoryModuleEntry =
   InMemoryModuleEntry.ofFile("res/xml/splits0.xml", "123".getBytes(UTF_8));
 ModuleSplit baseMasterSplit =
   createModuleSplit(
       BASE_MODULE_NAME,
       /* splitId= */ "",
       /* masterSplit= */ true,
       SPLIT,
       /* languageTargeting= */ null)
     .toBuilder()
     .setEntries(ImmutableList.of(existingInMemoryModuleEntry))
     .build();
 ModuleSplit processedBaseMasterSplit =
   splitsXmlInjector
     .process(GeneratedApks.fromModuleSplits(ImmutableList.of(baseMasterSplit)))
     .getAllApksStream()
     .collect(onlyElement());
 assertThat(processedBaseMasterSplit.getEntries()).hasSize(2);
 assertThat(processedBaseMasterSplit.getEntries()).contains(existingInMemoryModuleEntry);
 assertThat(processedBaseMasterSplit.getEntries().get(1).getPath().toString())
   .isEqualTo("res/xml/splits1.xml");
 assertThat(processedBaseMasterSplit.getResourceTable().get())
   .containsResource("com.example.app:xml/splits1")
   .withFileReference("res/xml/splits1.xml");
}
origin: google/bundletool

assertThat(languageSplits).hasSize(2);
ModuleSplit masterSplit =
  languageSplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
assertThat(masterSplit.getResourceTable())
  .hasValue(
  languageSplits.stream().filter(split -> !split.isMasterSplit()).collect(onlyElement());
assertThat(configSplit.getApkTargeting()).isEqualTo(apkLanguageTargeting("en"));
assertThat(configSplit.getResourceTable())
origin: google/bundletool

Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit);
ModuleSplit masterSplit =
  languageSplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
assertThat(masterSplit.getResourceTable())
  .hasValue(
origin: google/bundletool

  densitySplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
assertThat(extractPaths(masterSplit.getEntries()))
  .containsExactly("res/drawable-mdpi/image.jpg", "res/drawable-hdpi/image.jpg");
origin: google/bundletool

  splitsXmlInjector.process(GeneratedApks.fromModuleSplits(ImmutableList.of(standalone)));
ModuleSplit processedStandalone = result.getAllApksStream().collect(onlyElement());
com.google.common.collectMoreCollectorsonlyElement

Javadoc

A collector that takes a stream containing exactly one element and returns that element. The returned collector throws an IllegalArgumentException if the stream consists of two or more elements, and a NoSuchElementException if the stream is empty.

Popular methods of MoreCollectors

  • toOptional
    A collector that converts a stream of zero or one elements to an Optional. The returned collector th

Popular in Java

  • Reactive rest calls using spring rest template
  • startActivity (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • JTable (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