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

com.mercateo.common.rest.schemagen.ValueConstraints Maven / Gradle / Ivy

There is a newer version: 0.20.0
Show newest version
package com.mercateo.common.rest.schemagen;

import java.util.Optional;

public class ValueConstraints {

    private static final ValueConstraints EMPTY_CONSTRAINTS = new ValueConstraints();

    private Optional max;

    private Optional min;

    public Optional getMax() {
        return max;
    }

    public Optional getMin() {
        return min;
    }

    public ValueConstraints(Optional max, Optional min) {
        if (max.flatMap(x -> min.map(y -> y > x)).orElse(false)) {
            throw new IllegalArgumentException(String.format(
                    "Minimum value %s is larger than maximum value %s", min.get(), max.get()));
        }
        this.max = max;
        this.min = min;
    }

    public static ValueConstraints empty() {
        return EMPTY_CONSTRAINTS;
    }

    private ValueConstraints() {
        this.max = Optional.empty();
        this.min = Optional.empty();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy