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


Java DoubleSupplier类代码示例

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


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

示例1: shouldRequireNonNullCache

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<String, Double> cache = null;
    final Supplier<String> keySupplier = () -> "key";
    final DoubleSupplier supplier = () -> 123.456D;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide an empty map instead of NULL.");

    // then
    new ConcurrentMapBasedDoubleSupplierMemoizer<>(cache, keySupplier, supplier);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleSupplierMemoizerTest.java

示例2: shouldRequireNonNullKeySupplier

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullKeySupplier() {
    // given
    final ConcurrentMap<String, Double> cache = new ConcurrentHashMap<>();
    final Supplier<String> keySupplier = null;
    final DoubleSupplier supplier = () -> 123.456D;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide a key function, might just be 'MemoizationDefaults.defaultKeySupplier()'.");

    // then
    new ConcurrentMapBasedDoubleSupplierMemoizer<>(cache, keySupplier, supplier);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleSupplierMemoizerTest.java

示例3: shouldRequireNonNullValueSupplier

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullValueSupplier() {
    // given
    final ConcurrentMap<String, Double> cache = new ConcurrentHashMap<>();
    final Supplier<String> keySupplier = () -> "key";
    final DoubleSupplier supplier = null;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Cannot memoize a NULL Supplier - provide an actual Supplier to fix this.");

    // then
    new ConcurrentMapBasedDoubleSupplierMemoizer<>(cache, keySupplier, supplier);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedDoubleSupplierMemoizerTest.java

示例4: shouldUseSuppliedKey

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
public void shouldUseSuppliedKey() {
    // given
    final ConcurrentMap<String, Double> cache = new ConcurrentHashMap<>();
    final Supplier<String> keySupplier = () -> "key";
    final DoubleSupplier supplier = () -> 123.456D;

    // when
    final ConcurrentMapBasedDoubleSupplierMemoizer<String> memoizer = new ConcurrentMapBasedDoubleSupplierMemoizer<>(
            cache, keySupplier, supplier);

    // then
    Assert.assertTrue("Cache is not empty before memoization", memoizer.viewCacheForTest().isEmpty());
    Assert.assertEquals("Memoized value does not match expectations", 123.456D, memoizer.getAsDouble(), 0.0D);
    Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
    Assert.assertEquals("Memoization key does not match expectations", "key",
            memoizer.viewCacheForTest().keySet().iterator().next());
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:22,代码来源:ConcurrentMapBasedDoubleSupplierMemoizerTest.java

示例5: shouldTriggerOnce

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.BOXING)
public void shouldTriggerOnce() {
    // given
    final ConcurrentMap<String, Double> cache = new ConcurrentHashMap<>();
    final Supplier<String> keySupplier = () -> "key";
    final DoubleSupplier supplier = mock(DoubleSupplier.class);
    given(supplier.getAsDouble()).willReturn(123.456D);

    // when
    final ConcurrentMapBasedDoubleSupplierMemoizer<String> memoizer = new ConcurrentMapBasedDoubleSupplierMemoizer<>(
            cache, keySupplier, supplier);

    // then
    Assert.assertEquals("Memoized value does not match expectations", 123.456D, memoizer.getAsDouble(), 0.0D); // triggers
    Assert.assertEquals("Memoized value does not match expectations", 123.456D, memoizer.getAsDouble(), 0.0D); // memoized
    Assert.assertEquals("Memoized value does not match expectations", 123.456D, memoizer.getAsDouble(), 0.0D); // memoized
    Assert.assertEquals("Memoized value does not match expectations", 123.456D, memoizer.getAsDouble(), 0.0D); // memoized
    verify(supplier, times(1)).getAsDouble(); // real supplier triggered once, all other calls were memoized
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:24,代码来源:ConcurrentMapBasedDoubleSupplierMemoizerTest.java

示例6: ViewConfiguration

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 * Creates a new view configuration
 *  
 * @param viewportSupplier A supplier that supplies the viewport, 
 * as 4 float elements, [x, y, width, height]
 * @param aspectRatioSupplier An optional supplier for the aspect ratio. 
 * If this is <code>null</code>, then the aspect ratio of the 
 * camera will be used
 * @param externalViewMatrixSupplier The optional external supplier of
 * a view matrix.
 * @param externalProjectionMatrixSupplier The optional external supplier
 * of a projection matrix.
 */
ViewConfiguration(
    Supplier<float[]> viewportSupplier,
    DoubleSupplier aspectRatioSupplier,
    Supplier<float[]> externalViewMatrixSupplier, 
    Supplier<float[]> externalProjectionMatrixSupplier)
{
    this.viewportSupplier = Objects.requireNonNull(
        viewportSupplier, "The viewportSupplier may not be null");
    this.currentCameraModelSupplier = new SettableSupplier<CameraModel>();
    this.aspectRatioSupplier = aspectRatioSupplier;
    this.viewMatrixSupplier = 
        createViewMatrixSupplier(externalViewMatrixSupplier);
    this.projectionMatrixSupplier = 
        createProjectionMatrixSupplier(externalProjectionMatrixSupplier);
}
 
开发者ID:javagl,项目名称:JglTF,代码行数:29,代码来源:ViewConfiguration.java

示例7: create

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 * Create a gyroscope for the given functions that returns the angular displacement and velocity.
 *
 * @param angleSupplier the function that returns the angle; may not be null
 * @param rateSupplier the function that returns the angular acceleration; may not be null
 * @return the angle sensor
 */
public static Gyroscope create(DoubleSupplier angleSupplier, DoubleSupplier rateSupplier) {
    return new Gyroscope() {
        private volatile double zero = 0;

        @Override
        public double getAngle() {
            return angleSupplier.getAsDouble() - zero;
        }

        @Override
        public Gyroscope zero() {
            zero = angleSupplier.getAsDouble();
            return this;
        }

        @Override
        public double getRate() {
            return rateSupplier.getAsDouble();
        }
    };
}
 
开发者ID:strongback,项目名称:strongback-java,代码行数:29,代码来源:Gyroscope.java

示例8: create

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 * Create a distance sensor for the given function that returns the distance.
 *
 * @param distanceSupplier the function that returns the distance; may not be null
 * @return the angle sensor
 */
public static DistanceSensor create(DoubleSupplier distanceSupplier) {
    return new DistanceSensor() {
        private double zero = 0;

        @Override
        public double getDistanceInInches() {
            return distanceSupplier.getAsDouble() - zero;
        }

        @Override
        public DistanceSensor zero() {
            zero = distanceSupplier.getAsDouble();
            return this;
        }
    };
}
 
开发者ID:strongback,项目名称:strongback-java,代码行数:23,代码来源:DistanceSensor.java

示例9: create

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 * Create an angle sensor around the given function that returns the angle.
 *
 * @param angleSupplier the function that returns the angle; may not be null
 * @return the angle sensor
 */
public static AngleSensor create(DoubleSupplier angleSupplier) {
    return new AngleSensor() {
        private volatile double zero = 0;

        @Override
        public double getAngle() {
            return angleSupplier.getAsDouble() - zero;
        }

        @Override
        public AngleSensor zero() {
            zero = angleSupplier.getAsDouble();
            return this;
        }
    };
}
 
开发者ID:strongback,项目名称:strongback-java,代码行数:23,代码来源:AngleSensor.java

示例10: create

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 * Create a angle sensor for the given function that returns the angle.
 *
 * @param angleSupplier the function that returns the angle; may not be null
 * @return the angle sensor
 */
public static Compass create(DoubleSupplier angleSupplier) {
    return new Compass() {
        private volatile double zero = 0;

        @Override
        public double getAngle() {
            return angleSupplier.getAsDouble() - zero;
        }

        @Override
        public Compass zero() {
            zero = angleSupplier.getAsDouble();
            return this;
        }
    };
}
 
开发者ID:strongback,项目名称:strongback-java,代码行数:23,代码来源:Compass.java

示例11: create

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/**
 * Create a new PowerPanel from functions that supply the current for each channel, total current, voltage, and temperature.
 *
 * @param currentForChannel the function that returns the current for a given channel; may not be null
 * @param totalCurrent the function that returns total current; may not be null
 * @param voltage the function that returns voltage; may not be null
 * @param temperature the function that returns temperature; may not be null
 * @return the power panel; never null
 * @see Hardware#powerPanel()
 */
public static PowerPanel create(IntToDoubleFunction currentForChannel, DoubleSupplier totalCurrent, DoubleSupplier voltage,
        DoubleSupplier temperature) {
    return new PowerPanel() {

        @Override
        public CurrentSensor getCurrentSensor(int channel) {
            return () -> currentForChannel.applyAsDouble(channel);
        }

        @Override
        public CurrentSensor getTotalCurrentSensor() {
            return totalCurrent::getAsDouble;
        }

        @Override
        public VoltageSensor getVoltageSensor() {
            return voltage::getAsDouble;
        }

        @Override
        public TemperatureSensor getTemperatureSensor() {
            return voltage::getAsDouble;
        }
    };
}
 
开发者ID:strongback,项目名称:strongback-java,代码行数:36,代码来源:PowerPanel.java

示例12: from

import java.util.function.DoubleSupplier; //导入依赖的package包/类
/** Creates a `Box.Dbl` from a `DoubleSupplier` and a `DoubleConsumer`. */
public static Dbl from(DoubleSupplier getter, DoubleConsumer setter) {
	return new Dbl() {
		@Override
		public double getAsDouble() {
			return getter.getAsDouble();
		}

		@Override
		public void set(double value) {
			setter.accept(value);
		}

		@Override
		public String toString() {
			return "Box.Dbl.from[" + get() + "]";
		}
	};
}
 
开发者ID:diffplug,项目名称:durian,代码行数:20,代码来源:Box.java

示例13: optional_double_orElseGet

import java.util.function.DoubleSupplier; //导入依赖的package包/类
@Test
public void optional_double_orElseGet() {
	
	OptionalDouble optionalDouble = OptionalDouble.empty();

	assertEquals(10, optionalDouble.orElseGet(() -> 10), 0);
	
	// or 
	DoubleSupplier doubleSupplier = new DoubleSupplier() {
		@Override
		public double getAsDouble() {
			return 10;
		}
	};
	
	assertEquals(10, optionalDouble.orElseGet(doubleSupplier), 0);
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:18,代码来源:OptionalDoubleExample.java

示例14: testCheckedDoubleSupplier

import java.util.function.DoubleSupplier; //导入依赖的package包/类
@Test
public void testCheckedDoubleSupplier() {
    final CheckedDoubleSupplier doubleSupplier = () -> {
        throw new Exception("double");
    };

    DoubleSupplier s1 = Unchecked.doubleSupplier(doubleSupplier);
    DoubleSupplier s2 = CheckedDoubleSupplier.unchecked(doubleSupplier);
    DoubleSupplier s3 = Sneaky.doubleSupplier(doubleSupplier);
    DoubleSupplier s4 = CheckedDoubleSupplier.sneaky(doubleSupplier);

    assertDoubleSupplier(s1, UncheckedException.class);
    assertDoubleSupplier(s2, UncheckedException.class);
    assertDoubleSupplier(s3, Exception.class);
    assertDoubleSupplier(s4, Exception.class);
}
 
开发者ID:jOOQ,项目名称:jOOL,代码行数:17,代码来源:CheckedSupplierTest.java

示例15: createPrimitiveSuppliers

import java.util.function.DoubleSupplier; //导入依赖的package包/类
private static Map<Class<?>, Class<?>> createPrimitiveSuppliers() {
    Map<Class<?>, Class<?>> map = new HashMap<>();
    map.put(IntSupplier.class, Integer.TYPE);
    map.put(LongSupplier.class, Long.TYPE);
    map.put(BooleanSupplier.class, Boolean.TYPE);
    map.put(DoubleSupplier.class, Double.TYPE);
    return Collections.unmodifiableMap(map);
}
 
开发者ID:SeriyBg,项目名称:junit-easy-tools,代码行数:9,代码来源:FieldAssignment.java


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