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


Java OptionalDouble.isPresent方法代码示例

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


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

示例1: usingJava8

import java.util.OptionalDouble; //导入方法依赖的package包/类
public void usingJava8() {
    // Using Java 8 techniques to find mean
    OptionalDouble mean = Arrays.stream(testData).average();
    if (mean.isPresent()) {
        out.println("The mean is " + mean.getAsDouble());
    } else {
        out.println("The stream was empty");
    }

    mean = Arrays.stream(testData).average();
    mean.ifPresent(x -> out.println("The mean is " + x));

    mean = Arrays.stream(testData).average();
    out.println("The mean is " + mean.orElse(0));

}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Made-Easy,代码行数:17,代码来源:Main.java

示例2: alignMFs

import java.util.OptionalDouble; //导入方法依赖的package包/类
private double[] alignMFs( List<MiniFacade> out, boolean onlyOneHard ) {
	
	OptionalDouble left = out.stream().filter( m -> !m.softLeft && (onlyOneHard || !m.softRight)).mapToDouble( m -> m.left ).average();
	if ( left.isPresent() )
		lp = left.getAsDouble();
	else if (!onlyOneHard)
		return null;
	else
		lp = out.stream().mapToDouble( m -> m.left ).min().getAsDouble();

	OptionalDouble right = out.stream().filter( m -> !m.softRight && (onlyOneHard || !m.softLeft) ).mapToDouble( m -> m.left + m.width ).average();
	if ( right.isPresent() )
		rp = right.getAsDouble();
	else if (!onlyOneHard)
		return null;
	else
		rp = out.stream().mapToDouble( m -> m.left + m.width ).max().getAsDouble();

	return new double[] {lp, rp};
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:21,代码来源:Regularizer.java

示例3: main

import java.util.OptionalDouble; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    OptionalDouble min = Arrays.stream(reader.readLine().split("\\s+"))
            .filter(n -> !n.isEmpty())
            .mapToDouble(Double::valueOf)
            .filter(n -> n % 2 == 0)
            .min();

    if(min.isPresent()) System.out.printf("%.2f%n", min.getAsDouble());
    else System.out.println("No match");
}
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:11,代码来源:p05_MinEvenNumber.java

示例4: parse

import java.util.OptionalDouble; //导入方法依赖的package包/类
static Optional<Result> parse(final String line) {
	final String[] parts = line.split(quote("|"));

	if (parts.length == 6) {
		final String name = parts[0].trim();
		final OptionalInt ntup = toOptionalInt(parts[1].trim());
		final OptionalInt tsamples = toOptionalInt(parts[2].trim());
		final OptionalInt psamples = toOptionalInt(parts[3].trim());
		final OptionalDouble pvalue = toOptionalDouble(parts[4].trim());
		final Optional<Assessment> assessment = Assessment.of(parts[5].trim());

		if (ntup.isPresent() &&
			tsamples.isPresent() &&
			psamples.isPresent() &&
			pvalue.isPresent() &&
			assessment.isPresent())
		{
			return Optional.of(new Result(
				name,
				ntup.getAsInt(),
				tsamples.getAsInt(),
				psamples.getAsInt(),
				pvalue.getAsDouble(),
				assessment.get()
			));
		}
	}

	return Optional.empty();
}
 
开发者ID:jenetics,项目名称:prngine,代码行数:31,代码来源:DieHarder.java

示例5: toJdbc

import java.util.OptionalDouble; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see jp.co.future.uroborosql.parameter.mapper.BindParameterMapper#toJdbc(java.lang.Object, java.sql.Connection, jp.co.future.uroborosql.parameter.mapper.BindParameterMapperManager)
 */
@Override
public Object toJdbc(final OptionalDouble original, final Connection connection,
		final BindParameterMapperManager parameterMapperManager) {
	return original.isPresent() ? original.getAsDouble() : null;
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:11,代码来源:OptionalDoubleParameterMapper.java

示例6: stream

import java.util.OptionalDouble; //导入方法依赖的package包/类
/**
 * If a value is present in {@code optional}, returns a stream containing only that element,
 * otherwise returns an empty stream.
 *
 * <p><b>Java 9 users:</b> use {@code optional.stream()} instead.
 */
public static DoubleStream stream(OptionalDouble optional) {
  return optional.isPresent() ? DoubleStream.of(optional.getAsDouble()) : DoubleStream.empty();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:Streams.java


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