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