當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。