本文整理汇总了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));
}
示例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};
}
示例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");
}
示例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();
}
示例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;
}
示例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();
}