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

cdc.bench.support.checks.StringAsDoublePredicate Maven / Gradle / Ivy

There is a newer version: 0.2.1
Show newest version
package cdc.bench.support.checks;

import java.util.function.Predicate;

public class StringAsDoublePredicate implements Predicate {
    private final double min;
    private final double max;

    public static final StringAsDoublePredicate INSTANCE = new StringAsDoublePredicate();
    public static final StringAsDoublePredicate NAT_INSTANCE = new StringAsDoublePredicate(0.0, Double.MAX_VALUE);

    public StringAsDoublePredicate() {
        this.min = Double.MIN_VALUE;
        this.max = Double.MAX_VALUE;
    }

    public StringAsDoublePredicate(double min,
                                   double max) {
        this.min = min;
        this.max = max;
    }

    @Override
    public boolean test(String value) {
        try {
            final double x = Double.parseDouble(value);
            return x >= min && x <= max;
        } catch (final NumberFormatException e) {
            return false;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy