本文整理匯總了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();
}