當前位置: 首頁>>代碼示例>>Java>>正文


Java Iterables.tryFind方法代碼示例

本文整理匯總了Java中com.google.common.collect.Iterables.tryFind方法的典型用法代碼示例。如果您正苦於以下問題:Java Iterables.tryFind方法的具體用法?Java Iterables.tryFind怎麽用?Java Iterables.tryFind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.Iterables的用法示例。


在下文中一共展示了Iterables.tryFind方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: formatConfiguration

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
static void formatConfiguration(StringBuilder sb, AttributeContainer fromConfigurationAttributes, AttributesSchema consumerSchema, List<ConfigurationMetadata> matches, Set<String> requestedAttributes, int maxConfLength, final String conf) {
    Optional<ConfigurationMetadata> match = Iterables.tryFind(matches, new Predicate<ConfigurationMetadata>() {
        @Override
        public boolean apply(ConfigurationMetadata input) {
            return conf.equals(input.getName());
        }
    });
    if (match.isPresent()) {
        AttributeContainer producerAttributes = match.get().getAttributes();
        Set<Attribute<?>> targetAttributes = producerAttributes.keySet();
        Set<String> targetAttributeNames = Sets.newTreeSet(Iterables.transform(targetAttributes, ATTRIBUTE_NAME));
        Set<Attribute<?>> allAttributes = Sets.union(fromConfigurationAttributes.keySet(), producerAttributes.keySet());
        Set<String> commonAttributes = Sets.intersection(requestedAttributes, targetAttributeNames);
        Set<String> consumerOnlyAttributes = Sets.difference(requestedAttributes, targetAttributeNames);
        sb.append("   ").append("- Configuration '").append(StringUtils.rightPad(conf + "'", maxConfLength + 1)).append(" :");
        List<Attribute<?>> sortedAttributes = Ordering.usingToString().sortedCopy(allAttributes);
        List<String> values = new ArrayList<String>(sortedAttributes.size());
        formatAttributes(sb, fromConfigurationAttributes, consumerSchema, producerAttributes, commonAttributes, consumerOnlyAttributes, sortedAttributes, values);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:21,代碼來源:AmbiguousConfigurationSelectionException.java

示例2: getFirstFile

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
public Optional<FileStatus> getFirstFile() throws IOException {
  return Iterables.tryFind(FluentIterable.from(statuses), new Predicate<FileStatus>() {

    @Override
    public boolean apply(FileStatus input) {
      return input.isFile();
    }});
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:9,代碼來源:FileSelection.java

示例3: findEqualIgnoreScopeVersionAndExclusions

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
private Optional<Dependency> findEqualIgnoreScopeVersionAndExclusions(Collection<Dependency> dependencies, Dependency candidate) {
    // For project dependencies de-duplication
    // Ignore scope on purpose
    // Ignore version because Maven doesn't support dependencies with different versions on different scopes
    // Ignore exclusions because we don't know how to choose/merge them
    // Consequence is that we use the highest version and the exclusions of highest priority dependency when de-duplicating
    // Use Maven Dependency "Management Key" as discriminator: groupId:artifactId:type:classifier
    final String candidateManagementKey = candidate.getManagementKey();
    return Iterables.tryFind(dependencies, new Predicate<Dependency>() {
        @Override
        public boolean apply(Dependency dependency) {
            return dependency.getManagementKey().equals(candidateManagementKey);
        }
    });
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:16,代碼來源:DefaultPomDependenciesConverter.java

示例4: findByTagName

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
public Optional<ContentFieldInfo> findByTagName(final String tagName, List<ContentFieldInfo> contentFieldInfos) {
    return Iterables.tryFind(contentFieldInfos, new Predicate<ContentFieldInfo>() {
        @Override
        public boolean apply(ContentFieldInfo fieldInfo) {
            String tag = fieldInfo.getTag();
            return tag.equals(tagName);
        }
    });
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:10,代碼來源:ContentFieldInfoSearcher.java

示例5: findActionType

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
public Optional<ActionType> findActionType() {
    Set<OutcomeDrivenAction> actions = actionTypeProvider.getActions();

    Optional<OutcomeDrivenAction> action = Iterables.tryFind(actions, actionPredicate);
    if (action.isPresent()) {
        ActionType actionType = action.get().getActionType();
        return Optional.of(actionType);
    }

    return Optional.absent();
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:12,代碼來源:OutcomeDrivenActionTypeGenerator.java

示例6: shouldReturnSingleHubEncryptionCert

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
@Test
public void shouldReturnSingleHubEncryptionCert() throws Exception {
    HubIdentityProviderMetadataDto metadataAsAnIdentityProvider = handler.getMetadataAsAnIdentityProvider();

    final List<Certificate> encryptionCertificates = metadataAsAnIdentityProvider.getEncryptionCertificates();
    assertThat(encryptionCertificates).hasSize(1);
    final Optional<Certificate> hubEncryptionCertificate = Iterables.tryFind(encryptionCertificates, getPredicateByIssuerId(TestEntityIds.HUB_ENTITY_ID));
    assertThat(hubEncryptionCertificate.isPresent()).isTrue();
    assertThat(hubEncryptionCertificate.get().getKeyUse()).isEqualTo(Certificate.KeyUse.Encryption);
}
 
開發者ID:alphagov,項目名稱:verify-hub,代碼行數:11,代碼來源:HubAsIdpMetadataHandlerTest.java

示例7: addSuppressWarningsFix

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
private Description.Builder addSuppressWarningsFix(
    Tree suggestTree, Description.Builder builder, String checkerName) {
  SuppressWarnings extantSuppressWarnings =
      ASTHelpers.getAnnotation(suggestTree, SuppressWarnings.class);
  SuggestedFix fix;
  if (extantSuppressWarnings == null) {
    fix = SuggestedFix.prefixWith(suggestTree, "@SuppressWarnings(\"" + checkerName + "\") ");
  } else {
    // need to update the existing list of warnings
    List<String> suppressions = Lists.newArrayList(extantSuppressWarnings.value());
    suppressions.add(checkerName);
    // find the existing annotation, so we can replace it
    ModifiersTree modifiers =
        (suggestTree instanceof MethodTree)
            ? ((MethodTree) suggestTree).getModifiers()
            : ((VariableTree) suggestTree).getModifiers();
    List<? extends AnnotationTree> annotations = modifiers.getAnnotations();
    // noinspection ConstantConditions
    com.google.common.base.Optional<? extends AnnotationTree> suppressWarningsAnnot =
        Iterables.tryFind(
            annotations,
            annot -> annot.getAnnotationType().toString().endsWith("SuppressWarnings"));
    if (!suppressWarningsAnnot.isPresent()) {
      throw new AssertionError("something went horribly wrong");
    }
    String replacement =
        "@SuppressWarnings({"
            + Joiner.on(',').join(Iterables.transform(suppressions, s -> '"' + s + '"'))
            + "}) ";
    fix = SuggestedFix.replace(suppressWarningsAnnot.get(), replacement);
  }
  return builder.addFix(fix);
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:34,代碼來源:NullAway.java

示例8: getBatchSchema

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
@Override
public BatchSchema getBatchSchema(final FileSelection selection, final FileSystemWrapper dfs) {
  final SabotContext context = formatPlugin.getContext();
  try (
    BufferAllocator sampleAllocator = context.getAllocator().newChildAllocator("sample-alloc", 0, Long.MAX_VALUE);
    OperatorContextImpl operatorContext = new OperatorContextImpl(context.getConfig(), sampleAllocator, context.getOptionManager(), 1000);
    SampleMutator mutator = new SampleMutator(context)
  ){
    final ImplicitFilesystemColumnFinder explorer = new ImplicitFilesystemColumnFinder(context.getOptionManager(), dfs, GroupScan.ALL_COLUMNS);

    Optional<FileStatus> fileName = Iterables.tryFind(selection.getStatuses(), new Predicate<FileStatus>() {
      @Override
      public boolean apply(@Nullable FileStatus input) {
        return input.getLen() > 0;
      }
    });

    final FileStatus file = fileName.or(selection.getStatuses().get(0));

    EasyDatasetSplitXAttr dataset = new EasyDatasetSplitXAttr();
    dataset.setStart(0l);
    dataset.setLength(Long.MAX_VALUE);
    dataset.setPath(file.getPath().toString());
    try(RecordReader reader = new AdditionalColumnsRecordReader(((EasyFormatPlugin)formatPlugin).getRecordReader(operatorContext, dfs, dataset, GroupScan.ALL_COLUMNS), explorer.getImplicitFieldsForSample(selection))) {
      reader.setup(mutator);
      Map<String, ValueVector> fieldVectorMap = new HashMap<>();
      for (VectorWrapper<?> vw : mutator.getContainer()) {
        fieldVectorMap.put(vw.getField().getName(), vw.getValueVector());
      }
      reader.allocate(fieldVectorMap);
      reader.next();
      mutator.getContainer().buildSchema(BatchSchema.SelectionVectorMode.NONE);
      return mutator.getContainer().getSchema();
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:39,代碼來源:EasyFormatDatasetAccessor.java

示例9: getLayoutById

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
public Optional<Layout> getLayoutById(final LayoutId id) {
  final Optional<Acceleration> acceleration = getByIndex(AccelerationIndexKeys.LAYOUT_ID, id.getId());
  if (!acceleration.isPresent()) {
    return Optional.absent();
  }

  return Iterables.tryFind(AccelerationUtils.getAllLayouts(acceleration.get()), new Predicate<Layout>() {
    @Override
    public boolean apply(@Nullable final Layout current) {
      return id.equals(current.getId());
    }
  });
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:14,代碼來源:AccelerationStore.java

示例10: assertIncluded

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
private static void assertIncluded(Iterable<Entry<String, String>> range, String... keys){
  for(final String key : keys){
    Optional<Entry<String, String>> out = Iterables.tryFind(range, new Predicate<Entry<String, String>>() {
      @Override
      public boolean apply(Entry<String, String> input) {
        return input.getKey().equals(key);
      }
    });
    assertTrue(String.format("Missing key expected: %s", key), out.isPresent());
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:12,代碼來源:AbstractTestKVStore.java

示例11: findItemOnPosition

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
private Optional<ConnectionItem> findItemOnPosition(final Point clickPoint, ConnectionItems connectionItems) {
    return Iterables.tryFind(connectionItems.getAllItems(), new IsClickInConnectionItemPredicate(clickPoint));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:4,代碼來源:ConnectionsBetweenItemsFinder.java

示例12: findConnectionItemForCoordinates

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
public Optional<ConnectionItem> findConnectionItemForCoordinates(Iterable<ConnectionItem> connectionItems, final int x, final int y) {
    return Iterables.tryFind(connectionItems, new CheckIfItemClickedPredicate(x, y));
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:4,代碼來源:ConnectionItemPairFinder.java

示例13: getClientById

import com.google.common.collect.Iterables; //導入方法依賴的package包/類
public Optional<SourcelistClient> getClientById(String clientid) {
    Predicate<SourcelistClient> idPredicates = getClientIdPredicates(clientid);
    return Iterables.tryFind(clients, idPredicates);
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:5,代碼來源:SourcelistGroup.java


注:本文中的com.google.common.collect.Iterables.tryFind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。