当前位置: 首页>>代码示例>>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;未经允许,请勿转载。