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


Java OptionalDouble类代码示例

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


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

示例1: equals

import java.util.OptionalDouble; //导入依赖的package包/类
@Test
public void equals() {
  ImmutableJdkOptionals o1 = ImmutableJdkOptionals.of()
      .withV2("v2")
      .withI1(1)
      .withD1(1.0);

  ImmutableJdkOptionals o2 = ImmutableJdkOptionals.of(
      Optional.of("v2"),
      OptionalInt.of(1),
      OptionalLong.empty(),
      OptionalDouble.of(1.0));

  check(o1).is(o2);
  check(o1.hashCode()).is(o2.hashCode());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:JdkOptionalTest.java

示例2: 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

示例3: testMaxColumn

import java.util.OptionalDouble; //导入依赖的package包/类
@Test(dataProvider = "parallel")
public void testMaxColumn(boolean parallel) {
    final DataFrame<String,String> frame = TestDataFrames.random(Double.class, 100000, 10).applyDoubles(v -> Math.random() * 10d);
    final DataFrameColumns<String,String> columns = parallel ? frame.cols().parallel() : frame.cols();
    final Optional<DataFrameColumn<String,String>> colMatch = columns.max((col1, col2) -> {
        final double diff1 = col1.getDouble("R5") - col1.getDouble("R8");
        final double diff2 = col2.getDouble("R5") - col2.getDouble("R8");
        return Double.compare(Math.abs(diff1), Math.abs(diff2));
    });
    assertTrue(colMatch.isPresent(), "Column was matched");
    final DataFrameColumn<String,String> column = colMatch.get();
    final OptionalDouble expectedMin = frame.cols().stream().mapToDouble(col -> Math.abs(col.getDouble("R5") - col.getDouble("R8"))).max();
    final double actualMin = Math.abs(column.getDouble("R5") - column.getDouble("R8"));
    assertTrue(expectedMin.isPresent());
    System.out.println("Min diff for " + column.key() + " for row " + column.ordinal());
    assertEquals(actualMin, expectedMin.getAsDouble(), 0.0001);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:18,代码来源:MinMaxTests.java

示例4: 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

示例5: testMaxRow

import java.util.OptionalDouble; //导入依赖的package包/类
@Test(dataProvider = "parallel")
public void testMaxRow(boolean parallel) {
    final DataFrame<String,String> frame = TestDataFrames.random(Double.class, 100000, 10).applyDoubles(v -> Math.random() * 10d);
    final DataFrameRows<String,String> rows = parallel ? frame.rows().parallel() : frame.rows();
    final Optional<DataFrameRow<String,String>> rowMatch = rows.max((row1, row2) -> {
        final double diff1 = row1.getDouble("C5") - row1.getDouble("C8");
        final double diff2 = row2.getDouble("C5") - row2.getDouble("C8");
        return Double.compare(Math.abs(diff1), Math.abs(diff2));
    });
    assertTrue(rowMatch.isPresent(), "Row was matched");
    final DataFrameRow<String,String> minRow = rowMatch.get();
    final OptionalDouble expectedMin = frame.rows().stream().mapToDouble(row -> Math.abs(row.getDouble("C5") - row.getDouble("C8"))).max();
    final double actualMin = Math.abs(minRow.getDouble("C5") - minRow.getDouble("C8"));
    assertTrue(expectedMin.isPresent());
    System.out.println("Min diff for " + minRow.key() + " for row " + minRow.ordinal());
    assertEquals(actualMin, expectedMin.getAsDouble(), 0.0001);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:18,代码来源:MinMaxTests.java

示例6: average

import java.util.OptionalDouble; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @implNote The {@code double} format can represent all
 * consecutive integers in the range -2<sup>53</sup> to
 * 2<sup>53</sup>. If the pipeline has more than 2<sup>53</sup>
 * values, the divisor in the average computation will saturate at
 * 2<sup>53</sup>, leading to additional numerical errors.
 */
@Override
public final OptionalDouble average() {
    /*
     * In the arrays allocated for the collect operation, index 0
     * holds the high-order bits of the running sum, index 1 holds
     * the low-order bits of the sum computed via compensated
     * summation, index 2 holds the number of values seen, index 3
     * holds the simple sum.
     */
    double[] avg = collect(() -> new double[4],
                           (ll, d) -> {
                               ll[2]++;
                               Collectors.sumWithCompensation(ll, d);
                               ll[3] += d;
                           },
                           (ll, rr) -> {
                               Collectors.sumWithCompensation(ll, rr[0]);
                               Collectors.sumWithCompensation(ll, rr[1]);
                               ll[2] += rr[2];
                               ll[3] += rr[3];
                           });
    return avg[2] > 0
        ? OptionalDouble.of(Collectors.computeFinalSum(avg) / avg[2])
        : OptionalDouble.empty();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:DoublePipeline.java

示例7: testMinRow

import java.util.OptionalDouble; //导入依赖的package包/类
@Test(dataProvider = "parallel")
public void testMinRow(boolean parallel) {
    final DataFrame<String,String> frame = TestDataFrames.random(Double.class, 100000, 10).applyDoubles(v -> Math.random() * 10d);
    final DataFrameRows<String,String> rows = parallel ? frame.rows().parallel() : frame.rows();
    final Optional<DataFrameRow<String,String>> rowMatch = rows.min((row1, row2) -> {
        final double diff1 = row1.getDouble("C5") - row1.getDouble("C8");
        final double diff2 = row2.getDouble("C5") - row2.getDouble("C8");
        return Double.compare(Math.abs(diff1), Math.abs(diff2));
    });
    assertTrue(rowMatch.isPresent(), "Row was matched");
    final DataFrameRow<String,String> minRow = rowMatch.get();
    final OptionalDouble expectedMin = frame.rows().stream().mapToDouble(row -> Math.abs(row.getDouble("C5") - row.getDouble("C8"))).min();
    final double actualMin = Math.abs(minRow.getDouble("C5") - minRow.getDouble("C8"));
    assertTrue(expectedMin.isPresent());
    System.out.println("Min diff for " + minRow.key() + " for row " + minRow.ordinal());
    assertEquals(actualMin, expectedMin.getAsDouble(), 0.0001);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:18,代码来源:MinMaxTests.java

示例8: serializeOptionalPrimitive

import java.util.OptionalDouble; //导入依赖的package包/类
@Test
public void serializeOptionalPrimitive() {
	final OptionalPrimitiveTestEntity entity = new OptionalPrimitiveTestEntity();
	entity.d = OptionalDouble.of(69.5);
	entity.i = OptionalInt.of(69);
	entity.l = OptionalLong.of(69L);

	final VPackSlice vpack = vp.serialize(entity);
	assertThat(vpack, is(notNullValue()));
	assertThat(vpack.isObject(), is(true));
	assertThat(vpack.get("d").isDouble(), is(true));
	assertThat(vpack.get("d").getAsDouble(), is(69.5));
	assertThat(vpack.get("i").isInteger(), is(true));
	assertThat(vpack.get("i").getAsInt(), is(69));
	assertThat(vpack.get("l").isInteger(), is(true));
	assertThat(vpack.get("l").getAsLong(), is(69L));
}
 
开发者ID:arangodb,项目名称:java-velocypack-module-jdk8,代码行数:18,代码来源:VPackOptionalTest.java

示例9: test02

import java.util.OptionalDouble; //导入依赖的package包/类
@Test
public void test02() throws Exception {

	try (SqlAgent agent = config.agent()) {
		agent.required(() -> {
			PropertyMapperTestEntity test1 = new PropertyMapperTestEntity(1);
			test1.intValue = OptionalInt.empty();
			test1.longValue = OptionalLong.empty();
			test1.doubleValue = OptionalDouble.empty();
			test1.dateValue = null;
			test1.datetimeValue = null;
			test1.enumValue = null;
			test1.bigIntValue = null;
			agent.insert(test1);
			PropertyMapperTestEntity data = agent.find(PropertyMapperTestEntity.class, 1).orElse(null);
			assertThat(data, is(test1));
		});
	}
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:20,代码来源:PropertyMapperTest.java

示例10: testMinColumn

import java.util.OptionalDouble; //导入依赖的package包/类
@Test(dataProvider = "parallel")
public void testMinColumn(boolean parallel) {
    final DataFrame<String,String> frame = TestDataFrames.random(Double.class, 100000, 10).applyDoubles(v -> Math.random() * 10d);
    final DataFrameColumns<String,String> columns = parallel ? frame.cols().parallel() : frame.cols();
    final Optional<DataFrameColumn<String,String>> colMatch = columns.min((col1, col2) -> {
        final double diff1 = col1.getDouble("R5") - col1.getDouble("R8");
        final double diff2 = col2.getDouble("R5") - col2.getDouble("R8");
        return Double.compare(Math.abs(diff1), Math.abs(diff2));
    });
    assertTrue(colMatch.isPresent(), "Column was matched");
    final DataFrameColumn<String,String> column = colMatch.get();
    final OptionalDouble expectedMin = frame.cols().stream().mapToDouble(col -> Math.abs(col.getDouble("R5") - col.getDouble("R8"))).min();
    final double actualMin = Math.abs(column.getDouble("R5") - column.getDouble("R8"));
    assertTrue(expectedMin.isPresent());
    System.out.println("Min diff for " + column.key() + " for row " + column.ordinal());
    assertEquals(actualMin, expectedMin.getAsDouble(), 0.0001);
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:18,代码来源:MinMaxTests.java

示例11: testFindLast_doubleStream

import java.util.OptionalDouble; //导入依赖的package包/类
public void testFindLast_doubleStream() {
  Truth.assertThat(findLast(DoubleStream.of())).isEqualTo(OptionalDouble.empty());
  Truth.assertThat(findLast(DoubleStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalDouble.of(5));

  // test with a large, not-subsized Spliterator
  List<Long> list =
      LongStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new));
  Truth.assertThat(findLast(list.stream().mapToDouble(i -> i)))
      .isEqualTo(OptionalDouble.of(10000));

  // no way to find out the stream is empty without walking its spliterator
  Truth.assertThat(findLast(list.stream().mapToDouble(i -> i).filter(i -> i < 0)))
      .isEqualTo(OptionalDouble.empty());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:15,代码来源:StreamsTest.java

示例12: parseDouble

import java.util.OptionalDouble; //导入依赖的package包/类
private static OptionalDouble parseDouble(String text) {
	try {
		return OptionalDouble.of(Double.parseDouble(text));
	} catch (NumberFormatException e) {
		return OptionalDouble.empty();
	}
}
 
开发者ID:tom91136,项目名称:GestureFX,代码行数:8,代码来源:LenaSample.java

示例13: should_verify_an_actual_optional_double_is_conform_to_an_expected_result

import java.util.OptionalDouble; //导入依赖的package包/类
@Test
public void should_verify_an_actual_optional_double_is_conform_to_an_expected_result() {
    assertThat(resultOf(() -> {
        gwtMock.whenAnEventHappensInRelationToAnActionOfTheConsumer();
        return OptionalDouble.of(123);
    }).isPresent()).hasSameClassAs(assertThat(OptionalDouble.empty()));
}
 
开发者ID:xapn,项目名称:test-as-you-think,代码行数:8,代码来源:ResultOfEventTest.java

示例14: parseFloat

import java.util.OptionalDouble; //导入依赖的package包/类
@Nonnull
public static OptionalDouble parseFloat(@Nonnull String s) {
    try {
        return OptionalDouble.of(Float.parseFloat(s));
    } catch (NumberFormatException e) {
        return OptionalDouble.empty();
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:9,代码来源:Numbers.java

示例15: parseDouble

import java.util.OptionalDouble; //导入依赖的package包/类
@Nonnull
public static OptionalDouble parseDouble(@Nonnull String s) {
    try {
        return OptionalDouble.of(Double.parseDouble(s));
    } catch (NumberFormatException e) {
        return OptionalDouble.empty();
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:9,代码来源:Numbers.java


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