All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.virtdata.libbasics.shared.conversions.from_double.ToString Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package io.virtdata.libbasics.shared.conversions.from_double;

import io.virtdata.annotations.Categories;
import io.virtdata.annotations.Category;
import io.virtdata.annotations.Example;
import io.virtdata.annotations.ThreadSafeMapper;

import java.util.function.DoubleFunction;
import java.util.function.DoubleUnaryOperator;
import java.util.function.Function;

@Categories({Category.conversion})
@ThreadSafeMapper
public class ToString implements DoubleFunction {
    private final DoubleUnaryOperator doubleFunc;

    @Example({"ToString()","map the double input value to a String"})
    public ToString() {
        doubleFunc = (d) -> d;
    }

    @Example({"ToString(Add(5.7D))","map the double input value X to X+5.7D and then to a String"})
    public ToString(DoubleUnaryOperator df) {
        this.doubleFunc = df;
    }

    public ToString(DoubleFunction df) {
        this.doubleFunc = df::apply;
    }

    public ToString(Function df) {
        this.doubleFunc = df::apply;
    }

    public String apply(double v) {
        return String.valueOf(doubleFunc.applyAsDouble(v));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy