java.util.function.DoubleSupplier Java Examples

The following examples show how to use java.util.function.DoubleSupplier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenDialogMenu.java    From paintera with GNU General Public License v2.0 7 votes vote down vote up
public static EventHandler<KeyEvent> keyPressedHandler(
		final PainteraGateway gateway,
		final Node target,
		Consumer<Exception> exceptionHandler,
		Predicate<KeyEvent> check,
		final String menuText,
		final PainteraBaseView viewer,
		final Supplier<String> projectDirectory,
		final DoubleSupplier x,
		final DoubleSupplier y)
{

	return event -> {
		if (check.test(event))
		{
			event.consume();
			OpenDialogMenu m = gateway.openDialogMenu();
			Optional<ContextMenu> cm = m.getContextMenu(menuText, viewer, projectDirectory, exceptionHandler);
			Bounds bounds = target.localToScreen(target.getBoundsInLocal());
			cm.ifPresent(menu -> menu.show(target, x.getAsDouble() + bounds.getMinX(), y.getAsDouble() + bounds.getMinY()));
		}
	};

}
 
Example #2
Source File: Rotate.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public Rotate(
		final DoubleSupplier speed,
		final AffineTransform3D globalTransform,
		final AffineTransform3D displayTransform,
		final AffineTransform3D globalToViewerTransform,
		final Consumer<AffineTransform3D> submitTransform,
		final Object lock)
{
	super();
	this.speed = speed;
	this.globalTransform = globalTransform;
	this.displayTransform = displayTransform;
	this.globalToViewerTransform = globalToViewerTransform;
	this.submitTransform = submitTransform;
	this.lock = lock;
}
 
Example #3
Source File: SinCosPerformance.java    From commons-numbers with Apache License 2.0 6 votes vote down vote up
@Override
protected double[] createNumbers(SplittableRandom rng) {
    DoubleSupplier generator;
    if ("pi".equals(type)) {
        generator = () -> rng.nextDouble() * 2 * Math.PI - Math.PI;
    } else if ("pi/2".equals(type)) {
        generator = () -> rng.nextDouble() * Math.PI - Math.PI / 2;
    } else if ("random".equals(type)) {
        generator = () -> createRandomNumber(rng);
    } else if ("edge".equals(type)) {
        generator = () -> createEdgeNumber(rng);
    } else {
        throw new IllegalStateException("Unknown number type: " + type);
    }
    return DoubleStream.generate(generator).limit(getSize()).toArray();
}
 
Example #4
Source File: TaskExecutor.java    From presto with Apache License 2.0 6 votes vote down vote up
public synchronized TaskHandle addTask(
        TaskId taskId,
        DoubleSupplier utilizationSupplier,
        int initialSplitConcurrency,
        Duration splitConcurrencyAdjustFrequency,
        OptionalInt maxDriversPerTask)
{
    requireNonNull(taskId, "taskId is null");
    requireNonNull(utilizationSupplier, "utilizationSupplier is null");
    checkArgument(maxDriversPerTask.isEmpty() || maxDriversPerTask.getAsInt() <= maximumNumberOfDriversPerTask,
            "maxDriversPerTask cannot be greater than the configured value");

    log.debug("Task scheduled " + taskId);

    TaskHandle taskHandle = new TaskHandle(taskId, waitingSplits, utilizationSupplier, initialSplitConcurrency, splitConcurrencyAdjustFrequency, maxDriversPerTask);

    tasks.add(taskHandle);
    return taskHandle;
}
 
Example #5
Source File: TaskHandle.java    From presto with Apache License 2.0 6 votes vote down vote up
public TaskHandle(
        TaskId taskId,
        MultilevelSplitQueue splitQueue,
        DoubleSupplier utilizationSupplier,
        int initialSplitConcurrency,
        Duration splitConcurrencyAdjustFrequency,
        OptionalInt maxDriversPerTask)
{
    this.taskId = requireNonNull(taskId, "taskId is null");
    this.splitQueue = requireNonNull(splitQueue, "splitQueue is null");
    this.utilizationSupplier = requireNonNull(utilizationSupplier, "utilizationSupplier is null");
    this.maxDriversPerTask = requireNonNull(maxDriversPerTask, "maxDriversPerTask is null");
    this.concurrencyController = new SplitConcurrencyController(
            initialSplitConcurrency,
            requireNonNull(splitConcurrencyAdjustFrequency, "splitConcurrencyAdjustFrequency is null"));
}
 
Example #6
Source File: VectorPerformance.java    From commons-geometry with Apache License 2.0 6 votes vote down vote up
/** Set up the instance for the benchmark.
 */
@Setup(Level.Iteration)
public void setup() {
    vectors = new ArrayList<>(size);

    final double[] values = new double[dimension];
    final DoubleSupplier doubleSupplier = createDoubleSupplier(getType(),
            RandomSource.create(RandomSource.XO_RO_SHI_RO_128_PP));

    for (int i = 0; i < size; ++i) {
        for (int j = 0; j < dimension; ++j) {
            values[j] = doubleSupplier.getAsDouble();
        }

        vectors.add(vectorFactory.apply(values));
    }
}
 
Example #7
Source File: VectorPerformance.java    From commons-geometry with Apache License 2.0 6 votes vote down vote up
/** Create a supplier that produces doubles of the given type.
 * @param type type of doubles to produce
 * @param rng random provider
 * @return a supplier that produces doubles of the given type
 */
private DoubleSupplier createDoubleSupplier(final String type, final UniformRandomProvider rng) {
    switch (type) {
    case RANDOM:
        return () -> createRandomDouble(rng);
    case NORMALIZABLE:
        final ZigguratNormalizedGaussianSampler sampler = ZigguratNormalizedGaussianSampler.of(rng);
        return () -> {
            double n = sampler.sample();
            return n == 0 ? 0.1 : n; // do not return exactly zero
        };
    case EDGE:
        return () -> EDGE_NUMBERS[rng.nextInt(EDGE_NUMBERS.length)];
    default:
        throw new IllegalStateException("Invalid input type: " + type);
    }
}
 
Example #8
Source File: ViewConfiguration.java    From JglTF with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #9
Source File: Zoom.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public Zoom(
		final DoubleSupplier speed,
		final GlobalTransformManager manager,
		final AffineTransform3D concatenated,
		final Object lock)
{
	this.speed = speed;
	this.manager = manager;
	this.concatenated = concatenated;
	this.lock = lock;

	this.manager.addListener(global::set);
}
 
Example #10
Source File: StubMetricsSystem.java    From besu with Apache License 2.0 5 votes vote down vote up
public double getGaugeValue(final String name) {
  final DoubleSupplier gauge = gauges.get(name);
  if (gauge == null) {
    throw new IllegalArgumentException("Unknown gauge: " + name);
  }
  return gauge.getAsDouble();
}
 
Example #11
Source File: PrometheusMetricsSystem.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public void createGauge(
    final MetricCategory category,
    final String name,
    final String help,
    final DoubleSupplier valueSupplier) {
  final String metricName = convertToPrometheusName(category, name);
  if (isCategoryEnabled(category)) {
    final Collector collector = new CurrentValueCollector(metricName, help, valueSupplier);
    addCollectorUnchecked(category, collector);
  }
}
 
Example #12
Source File: PostgreSQLDatabaseMetrics.java    From micrometer with Apache License 2.0 5 votes vote down vote up
/**
 * Function that makes sure functional counter values survive pg_stat_reset calls.
 */
Double resettableFunctionalCounter(String functionalCounterKey, DoubleSupplier function) {
    Double result = function.getAsDouble();
    Double previousResult = previousValueCacheMap.getOrDefault(functionalCounterKey, 0D);
    Double beforeResetValue = beforeResetValuesCacheMap.getOrDefault(functionalCounterKey, 0D);
    Double correctedValue = result + beforeResetValue;

    if (correctedValue < previousResult) {
        beforeResetValuesCacheMap.put(functionalCounterKey, previousResult);
        correctedValue = previousResult + result;
    }
    previousValueCacheMap.put(functionalCounterKey, correctedValue);
    return correctedValue;
}
 
Example #13
Source File: RecipeMap.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ModularUI.Builder createUITemplate(DoubleSupplier progressSupplier, IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids) {
    ModularUI.Builder builder = ModularUI.defaultBuilder();
    builder.widget(new ProgressWidget(progressSupplier, 77, 22, 20, 20, progressBarTexture, moveType));
    addInventorySlotGroup(builder, importItems, importFluids, false);
    addInventorySlotGroup(builder, exportItems, exportFluids, true);
    return builder;
}
 
Example #14
Source File: RecipeMapGroupOutput.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Builder createUITemplate(DoubleSupplier progressSupplier, IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids) {
    ModularUI.Builder builder = ModularUI.defaultBuilder();
    builder.widget(new ProgressWidget(progressSupplier, 77, 22, 20, 20, progressBarTexture, moveType));
    addInventorySlotGroup(builder, importItems, importFluids, false);
    BooleanWrapper booleanWrapper = new BooleanWrapper();
    ServerWidgetGroup itemOutputGroup = createItemOutputWidgetGroup(exportItems, new ServerWidgetGroup(() -> !booleanWrapper.getCurrentMode()));
    ServerWidgetGroup fluidOutputGroup = createFluidOutputWidgetGroup(exportFluids, new ServerWidgetGroup(booleanWrapper::getCurrentMode));
    builder.widget(itemOutputGroup).widget(fluidOutputGroup);
    ToggleButtonWidget buttonWidget = new ToggleButtonWidget(176 - 7 - 20, 60, 20, 20,
        GuiTextures.BUTTON_SWITCH_VIEW, booleanWrapper::getCurrentMode, booleanWrapper::setCurrentMode)
        .setTooltipText("gregtech.gui.toggle_view");
    builder.widget(buttonWidget);
    return builder;
}
 
Example #15
Source File: CalculateEntryTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Double average(Table table, CalculateEntry calculateEntry) throws Exception {
	DoubleSupplier ds = () -> {
		return 0d;
	};
	Double result = table.stream().mapToDouble(row -> row.getAsDouble(calculateEntry.getColumn())).average()
			.orElseGet(ds);
	return result;
}
 
Example #16
Source File: ProgressWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ProgressWidget(DoubleSupplier progressSupplier, int x, int y, int width, int height, TextureArea fullImage, MoveType moveType) {
    super(new Position(x, y), new Size(width, height));
    this.progressSupplier = progressSupplier;
    this.emptyBarArea = fullImage.getSubArea(0.0, 0.0, 1.0, 0.5);
    this.filledBarArea = fullImage.getSubArea(0.0, 0.5, 1.0, 0.5);
    this.moveType = moveType;
}
 
Example #17
Source File: MetaTileEntityLockedSafe.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
    DoubleSupplier supplier = () -> 0.2 + (unlockProgress / (MAX_UNLOCK_PROGRESS * 1.0)) * 0.8;
    ModularUI.Builder builder = ModularUI.defaultBuilder()
        .widget(new ProgressWidget(supplier, 5, 5, 166, 74,
            GuiTextures.PROGRESS_BAR_UNLOCK,
            MoveType.VERTICAL_INVERTED))
        .bindPlayerInventory(entityPlayer.inventory);

    ServerWidgetGroup lockedGroup = new ServerWidgetGroup(() -> !isSafeUnlocked && unlockProgress < 0);
    lockedGroup.addWidget(new LabelWidget(5, 20, "gregtech.machine.locked_safe.malfunctioning"));
    lockedGroup.addWidget(new LabelWidget(5, 30, "gregtech.machine.locked_safe.requirements"));

    lockedGroup.addWidget(new SlotWidget(unlockInventory, 0, 70, 40, false, true).setBackgroundTexture(GuiTextures.SLOT));
    lockedGroup.addWidget(new SlotWidget(unlockInventory, 1, 70 + 18, 40, false, true).setBackgroundTexture(GuiTextures.SLOT));

    lockedGroup.addWidget(new SlotWidget(unlockComponents, 0, 70, 58, false, false));
    lockedGroup.addWidget(new SlotWidget(unlockComponents, 1, 70 + 18, 58, false, false));

    ServerWidgetGroup unlockedGroup = new ServerWidgetGroup(() -> isSafeUnlocked);
    for (int row = 0; row < 3; row++) {
        for (int col = 0; col < 9; col++) {
            unlockedGroup.addWidget(new SlotWidget(safeLootInventory, col + row * 9,
                8 + col * 18, 15 + row * 18, true, false));
        }
    }

    return builder.widget(unlockedGroup)
        .widget(lockedGroup)
        .build(getHolder(), entityPlayer);
}
 
Example #18
Source File: SphereTest.java    From commons-geometry with Apache License 2.0 5 votes vote down vote up
@Test
public void testToTree_randomSpheres() {
    // arrange
    UniformRandomProvider rand = RandomSource.create(RandomSource.XO_RO_SHI_RO_128_PP, 1L);
    DoublePrecisionContext precision = new EpsilonDoublePrecisionContext(1e-10);
    double min = 1e-1;
    double max = 1e2;

    DoubleSupplier randDouble = () -> (rand.nextDouble() * (max - min)) + min;

    int count = 10;
    for (int i = 0; i < count; ++i) {
        Vector3D center = Vector3D.of(
                randDouble.getAsDouble(),
                randDouble.getAsDouble(),
                randDouble.getAsDouble());

        double radius = randDouble.getAsDouble();
        Sphere sphere = Sphere.from(center, radius, precision);

        for (int s = 0; s < 7; ++s) {
            // act
            RegionBSPTree3D tree = sphere.toTree(s);

            // assert
            Assert.assertEquals((int)(8 * Math.pow(4, s)), tree.getBoundaries().size());
            Assert.assertTrue(tree.isFinite());
            Assert.assertFalse(tree.isEmpty());
            Assert.assertTrue(tree.getSize() < sphere.getSize());
        }
    }
}
 
Example #19
Source File: StubGauge.java    From teku with Apache License 2.0 5 votes vote down vote up
protected StubGauge(
    final MetricCategory category,
    final String name,
    final String help,
    final DoubleSupplier supplier) {
  super(category, name, help);
  this.supplier = supplier;
}
 
Example #20
Source File: StubMetricsSystem.java    From teku with Apache License 2.0 5 votes vote down vote up
@Override
public void createGauge(
    final MetricCategory category,
    final String name,
    final String help,
    final DoubleSupplier valueSupplier) {
  final StubGauge guage = new StubGauge(category, name, help, valueSupplier);
  final Map<String, StubGauge> gaugesInCategory =
      gauges.computeIfAbsent(category, key -> new ConcurrentHashMap<>());

  if (gaugesInCategory.putIfAbsent(name, guage) != null) {
    throw new IllegalArgumentException("Attempting to create two gauges with the same name");
  }
}
 
Example #21
Source File: TranslateAlongNormal.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public TranslateAlongNormal(
		final DoubleSupplier translationSpeed,
		final GlobalTransformManager manager,
		final AffineTransform3D worldToSharedViewerSpace,
		final Object lock)
{
	this.translationSpeed = translationSpeed;
	this.manager = manager;
	this.worldToSharedViewerSpace = worldToSharedViewerSpace;
	this.lock = lock;

	manager.addListener(global::set);
}
 
Example #22
Source File: CalculateEntry.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Double average(Table table) throws Exception {
	DoubleSupplier ds = () -> {
		return 0d;
	};
	Double result = table.stream().mapToDouble(row -> row.getAsDouble(this.column)).average().orElseGet(ds);
	return result;
}
 
Example #23
Source File: DoubleCheckedDataWriter.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public DoubleCheckedDataWriter(DataOutput output, DoubleSupplier extractor, BooleanSupplier existsSupplier) {
  super(output, extractor, existsSupplier);
}
 
Example #24
Source File: DoubleArrayReservation.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public DoubleArrayReservation(DoubleConsumer applier, IntConsumer sizeApplier, DoubleSupplier extractor, IntSupplier sizeExtractor) {
  super(applier, sizeApplier, extractor, sizeExtractor);
}
 
Example #25
Source File: FitToInterval.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public FitToInterval(final GlobalTransformManager manager, final DoubleSupplier width)
{
	super();
	this.manager = manager;
	this.width = width;
}
 
Example #26
Source File: DoubleCheckedReservation.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public DoubleCheckedReservation(DoubleConsumer applier, DoubleSupplier extractor, BooleanSupplier exists) {
  super(applier, extractor, exists);
}
 
Example #27
Source File: FitToInterval.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public static ListChangeListener<Source<?>> fitToIntervalWhenSourceAddedListener(
		final GlobalTransformManager manager,
		final DoubleSupplier width)
{
	return fitToIntervalWhenSourceAddedListener(new FitToInterval(manager, width));
}
 
Example #28
Source File: StreamSpliterators.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
OfDouble(long size, DoubleSupplier s) {
    super(size);
    this.s = s;
}
 
Example #29
Source File: StreamSpliterators.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
OfDouble(long size, DoubleSupplier s) {
    super(size);
    this.s = s;
}
 
Example #30
Source File: StreamSpliterators.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
OfDouble(long size, DoubleSupplier s) {
    super(size);
    this.s = s;
}