当前位置: 首页>>代码示例>>Java>>正文


Java Optional.flatMap方法代码示例

本文整理汇总了Java中java.util.Optional.flatMap方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.flatMap方法的具体用法?Java Optional.flatMap怎么用?Java Optional.flatMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Optional的用法示例。


在下文中一共展示了Optional.flatMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNodeIdFromIdOrName

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Convenience method for retrieving the id of a Node given the id or the name of the node, and
 * the id of the cluster and the datacenter it belongs to
 *
 * @param clusterId id of the cluster the DataCenter belongs to
 * @param datacenterId id of the datacenter the DataCenter belongs to
 * @param idOrName string which could be the id or the name of the Node
 * @return id of the cluster
 */
static Optional<Long> getNodeIdFromIdOrName(
    Server server, Long clusterId, Long datacenterId, String idOrName) {
  Optional<BoundDataCenter> dc =
      server
          .getCluster(clusterId)
          .getDataCenters()
          .stream()
          .filter(d -> d.getId().equals(datacenterId))
          .findAny();

  return dc.flatMap(
      d ->
          d.getNodes()
              .stream()
              .filter(n -> n.getName().equals(idOrName) || n.getId().toString().equals(idOrName))
              .findAny()
              .map(AbstractNodeProperties::getId));
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:28,代码来源:HttpUtils.java

示例2: getDisplayName

import java.util.Optional; //导入方法依赖的package包/类
private DisplayName getDisplayName(TestIdentifier testIdentifier) {
  LinkedList<String> names = new LinkedList<>();
  Optional<TestIdentifier> id = Optional.of(testIdentifier);
  do {
    TestIdentifier identifier = id.get();
    Optional<ClassSource> classSource = identifier.getSource()
        .filter(source -> source instanceof ClassSource)
        .map(source -> (ClassSource) source)
        .filter(source -> !source.getPosition().isPresent())
        .filter(source -> classesToSkip.contains(source.getJavaClass()));
    if (classSource.isPresent()) {
      break;
    }

    names.addFirst(identifier.getDisplayName());

    id = id.flatMap(testPlan::getParent);
  } while (id.isPresent());

  return DisplayName.create(names);
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:22,代码来源:TestPlanExecutionReport.java

示例3: getContextModuleTypes

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Returns module types that are present on the given context or any of its enclosing contexts.
 */
private static Set<Class<? extends Module>> getContextModuleTypes(
    Optional<ExtensionContext> context) {
  // TODO: Cache?

  Set<Class<? extends Module>> contextModuleTypes = new LinkedHashSet<>();
  while (context.isPresent() && (hasAnnotatedElement(context) || hasParent(context))) {
    context
        .flatMap(ExtensionContext::getElement)
        .map(GuiceExtension::getModuleTypes)
        .ifPresent(contextModuleTypes::addAll);
    context = context.flatMap(ExtensionContext::getParent);
  }

  return contextModuleTypes;
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:19,代码来源:GuiceExtension.java

示例4: getFieldsWriter

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Returns the {@link FieldsWriter} for a given model.
 *
 * @param  singleModel the single model
 * @param  embeddedPathElements the embedded path element list
 * @param  requestInfo the current request's information
 * @param  pathFunction the function to get the {@link Path}
 * @param  representorFunction the function to get the {@link Representor}
 * @return the {@code FieldsWriter} for the model
 */
public static <T> Optional<FieldsWriter<T, ?>> getFieldsWriter(
	SingleModel<T> singleModel, FunctionalList<String> embeddedPathElements,
	RequestInfo requestInfo, PathFunction pathFunction,
	RepresentorFunction representorFunction) {

	Optional<Representor<T, ?>> representorOptional =
		getRepresentorOptional(
			singleModel.getModelClass(), representorFunction);

	Optional<Path> pathOptional = getPathOptional(
		singleModel, pathFunction, representorFunction);

	return representorOptional.flatMap(
		representor -> pathOptional.map(
			path -> new FieldsWriter<>(
				singleModel, requestInfo, representor, path,
				embeddedPathElements)));
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:29,代码来源:WriterUtil.java

示例5: getOptionalInitParamValue

import java.util.Optional; //导入方法依赖的package包/类
static <T> Optional<T> getOptionalInitParamValue(String name, Map<String, ?> initParams,
                                                 Function<String, T> converter) throws UnavailableException
{
    Optional<String> value = getSingleValue(name, initParams);

    return value.flatMap(s -> Optional.ofNullable(converter.apply(s)));
}
 
开发者ID:curityio,项目名称:oauth-filter-for-java,代码行数:8,代码来源:FilterHelper.java

示例6: getDiffs

import java.util.Optional; //导入方法依赖的package包/类
public static TableAction getDiffs(Table table, Schema schema, Database existingDatabase, Log log) {

		Optional<Schema> existingSchemaOpt = existingDatabase.findSchema(schema.getName());
		Optional<Table> existingTableOpt = existingSchemaOpt.flatMap(existingSchema -> existingSchema.findTable(table.getName()));

		if (!existingTableOpt.isPresent()) {
			return TableAction.create(table, existingSchemaOpt);
		} else if (!existingTableOpt.get().equals(table)) {
			return TableAction.update(table, existingSchemaOpt);
		}

		return TableAction.noAction(table);
	}
 
开发者ID:h-omer,项目名称:neo4j-versioner-sql,代码行数:14,代码来源:DiffManager.java

示例7: toString

import java.util.Optional; //导入方法依赖的package包/类
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Beachline(");
    if (getRoot() != null) {
        Optional<LeafBeachNode> current = Optional.of(getRoot().getLeftmostLeaf());
        while (current.isPresent()) {
            sb.append(current.get().getSite()).append(',');
            current = current.flatMap(LeafBeachNode::getRightNeighbor);
        }
    }
    sb.append(")");
    return sb.toString();
}
 
开发者ID:aschlosser,项目名称:voronoi-java,代码行数:15,代码来源:Beachline.java

示例8: getRegionFromConfigFile

import java.util.Optional; //导入方法依赖的package包/类
private static Optional<String> getRegionFromConfigFile(File file, String profile) {
    AWSCLIConfigFile configFile = new AWSCLIConfigFile(file);
    AWSCLIConfigFile.Config config = configFile.getConfig();

    Optional<AWSCLIConfigFile.Section> profileSection = config.getSection(profile);

    // Legacy fallback
    if (!profileSection.isPresent()) {
        profileSection = config.getSection("profile " + profile);
    }

    return profileSection.flatMap(s -> s.getProperty("region"));
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:14,代码来源:CustomRegionProviderChain.java

示例9: getPathOptional

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Returns a model's {@link Path}, if the model's {@code Representor} and
 * {@code Path} exist. Otherwise, this method returns {@code
 * Optional#empty()}.
 *
 * @param  singleModel the single model
 * @param  pathFunction the function that gets the {@code Path}
 * @param  representorFunction the function that gets the {@code
 *         Representor}
 * @return the model's {@code Path}, if the model's {@code Representor} and
 *         {@code Path} exist; returns {@code Optional#empty()} otherwise
 */
public static <T> Optional<Path> getPathOptional(
	SingleModel<T> singleModel, PathFunction pathFunction,
	RepresentorFunction representorFunction) {

	Optional<Representor<T, ?>> optional = getRepresentorOptional(
		singleModel.getModelClass(), representorFunction);

	return optional.flatMap(
		representor -> pathFunction.apply(
			representor.getIdentifier(singleModel.getModel()),
			representor.getIdentifierClass(), singleModel.getModelClass()));
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:25,代码来源:WriterUtil.java

示例10: find

import java.util.Optional; //导入方法依赖的package包/类
public Optional<Relationship> find(RastDiff diff) {
	RastRoot before = diff.getBefore();
	RastRoot after = diff.getAfter();
	Optional<RastNode> oNodeBefore = RastRootHelper.findByNamePath(before, nodeQBefore.namePath);
	Optional<RastNode> oNodeAfter = RastRootHelper.findByNamePath(after, nodeQAfter.namePath);
	return oNodeBefore.flatMap(nodeBefore -> oNodeAfter.flatMap(nodeAfter -> {
		Relationship r = new Relationship(type, nodeBefore, nodeAfter);
		if (diff.getRelationships().contains(r)) {
			return Optional.of(r);
		}
		return Optional.empty();
	}));
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:14,代码来源:RastDiffMatchers.java

示例11: indicate

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<Ratio> indicate(final C marketPrice) {
    final Optional<Price> optDm = directionalMovement.indicate(marketPrice);
    final Optional<Price> optTr = trueRange.indicate(marketPrice);

    return optDm.flatMap(dm -> optTr.map(tr -> tr.asPipette() == 0 ? ZERO : new Ratio(dm.divide(tr).asBasic())));
}
 
开发者ID:rbi,项目名称:trading4j,代码行数:8,代码来源:DirectionalIndex.java

示例12: indicate

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<Ratio> indicate(final C marketPrice) {
    final Optional<Ratio> optPlusDi = averagePlusDi.indicate(marketPrice);
    final Optional<Ratio> optMinusDi = averageMinusDi.indicate(marketPrice);

    return optPlusDi.flatMap(plusDi -> optMinusDi.map(minusDi -> new Ratio(
            abs((plusDi.asBasic() - minusDi.asBasic()) / (plusDi.asBasic() + minusDi.asBasic())))));
}
 
开发者ID:rbi,项目名称:trading4j,代码行数:9,代码来源:DirectionalMovementIndex.java

示例13: lift

import java.util.Optional; //导入方法依赖的package包/类
static <R, T, Z> Optional<Z> lift(Optional<T> left, Optional<R> right,
                                  BiFunction<? super T, ? super R, ? extends Z> function) {
    return left.flatMap(leftVal -> right.map(rightVal -> function.apply(leftVal, rightVal)));
}
 
开发者ID:pszeliga,项目名称:functional-java,代码行数:5,代码来源:Optionals.java

示例14: create

import java.util.Optional; //导入方法依赖的package包/类
public static @NotNull Optional<CollectorServer> create(@NotNull Optional<ServerParameters> parameters) {
  return parameters
      .flatMap(params -> CollectorServer.create(params.config())
          .map(server -> server.init(params.address(), params.format())));
}
 
开发者ID:nolequen,项目名称:jmx-prometheus-exporter,代码行数:6,代码来源:Launcher.java

示例15: castTo

import java.util.Optional; //导入方法依赖的package包/类
private static <T> Optional<Converted<T>> castTo(Class<T> type, Object instance) {
	Optional<List<Class<?>>> matchingCastPath = Optional.ofNullable(TYPECAST_PATHS_MAP.get(Pair.of(instance.getClass(), type)));
	
	return matchingCastPath.flatMap(path -> castTo(type, instance, path));
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:6,代码来源:TypeConverter.java


注:本文中的java.util.Optional.flatMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。