/*
 * Copyright 2016 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.config.flexible.validators;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Validates a {@link Number} within the specified range.
 *
 * @param <T> The type of the {@link Number} to validate.
 */
public class RangedNumberValidator<T extends Number & Comparable<? super T>> implements SettingValueValidator<T> {
    private static final Logger LOGGER = LoggerFactory.getLogger(RangedNumberValidator.class);
    private boolean minInclusive;
    private boolean maxInclusive;

    private T min;
    private T max;

    public RangedNumberValidator(T min, T max, boolean minInclusive, boolean maxInclusive) {
        this.min = min;
        this.max = max;

        this.minInclusive = minInclusive;
        this.maxInclusive = maxInclusive;
    }

    public boolean isMinInclusive() {
        return minInclusive;
    }

    public boolean isMaxInclusive() {
        return maxInclusive;
    }

    public T getMin() {
        return min;
    }

    public T getMax() {
        return max;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean validate(T value) {
        boolean withinMinBoundary = true;

        if (min != null) {
            if (minInclusive) {
                withinMinBoundary = value.compareTo(min) >= 0;
            } else {
                withinMinBoundary = value.compareTo(min) > 0;
            }
        }

        boolean withinMaxBoundary = true;

        if (max != null) {
            if (maxInclusive) {
                withinMaxBoundary = value.compareTo(max) <= 0;
            } else {
                withinMaxBoundary = value.compareTo(max) < 0;
            }
        }

        return withinMinBoundary && withinMaxBoundary;
    }

    @Override
    public void issueWarnings(T value) {
        LOGGER.warn("Value {} is not in the range {}{}, {}{}", value, minInclusive ? "[" : "(",
                min != null ? min : "UNBOUNDED", max != null ? max : "UNBOUNDED", maxInclusive ? "]" : ")");
    }
}

@@ -1153,435 +1153,1341 @@
     
-public RangedNumberValidator(T min, T max, boolean minInclusive, boolean maxInclusive) %7B%0A        this.min = min;%0A        this.max = max;%0A%0A        this.minInclusive = minInclusive;%0A        this.maxInclusive = maxInclusive;%0A    %7D%0A%0A    public boolean isMinInclusive() %7B%0A        return minInclusive;%0A    %7D%0A%0A    public boolean isMaxInclusive() %7B%0A        return maxInclusive;%0A    %7D%0A%0A    public T getMin() %7B%0A        return min;%0A    %7D%0A
+/**%0A     * Creates a new instance of %7B@link RangedNumberValidator%7D.%0A     * @param min The minimum value in the range. A null value signifies the absence of any minimum value.%0A     * @param max The maximum value in the range. A null value signifies the absence of any maximum value.%0A     * @param minInclusive Should the minimum value be included in the range?%0A     * @param maxInclusive Should the maximum value be included in the range?%0A     */%0A    public RangedNumberValidator(T min, T max, boolean minInclusive, boolean maxInclusive) %7B%0A        this.min = min;%0A        this.max = max;%0A%0A        this.minInclusive = minInclusive;%0A        this.maxInclusive = maxInclusive;%0A    %7D%0A%0A    /**%0A     * Returns a boolean stating whether the minimum value should be included in the range.%0A     */%0A    public boolean isMinInclusive() %7B%0A        return minInclusive;%0A    %7D%0A%0A    /**%0A     * Returns a boolean stating whether the maximum value should be included in the range.%0A     */%0A    public boolean isMaxInclusive() %7B%0A        return maxInclusive;%0A    %7D%0A%0A    /**%0A     * Returns the minimum value in the range. A null value signifies the absence of any minimum value.%0A     */%0A    public T getMin() %7B%0A        return min;%0A    %7D%0A%0A    /**%0A     * Returns the maximum value in the range. A null value signifies the absence of any maximum value.%0A     */
 %0A   
@@ -3228,24 +3228,62 @@
 ary;%0A    %7D%0A%0A
+%0A    /**%0A     * %7B@inheritDoc%7D%0A     */%0A
     @Overrid

Document RangedValueValidator