Search in sources :

Example 1 with ValueException

use of io.micronaut.core.value.ValueException in project micronaut-core by micronaut-projects.

the class PropertySourcePropertyResolver method getNextLongInRange.

private long getNextLongInRange(String range, String property) {
    try {
        String[] tokens = range.split(",");
        long lowerBound = Long.parseLong(tokens[0]);
        if (tokens.length == 1) {
            return (long) (Math.random() * (lowerBound));
        }
        long upperBound = Long.parseLong(tokens[1]);
        return lowerBound + (long) (Math.random() * (upperBound - lowerBound));
    } catch (NumberFormatException ex) {
        throw new ValueException("Invalid range: `" + range + "` found for type Long while parsing property: " + property, ex);
    }
}
Also used : ValueException(io.micronaut.core.value.ValueException)

Example 2 with ValueException

use of io.micronaut.core.value.ValueException in project micronaut-core by micronaut-projects.

the class PropertySourcePropertyResolver method getNextFloatInRange.

private float getNextFloatInRange(String range, String property) {
    try {
        String[] tokens = range.split(",");
        float lowerBound = Float.parseFloat(tokens[0]);
        if (tokens.length == 1) {
            return (float) (Math.random() * (lowerBound));
        }
        float upperBound = Float.parseFloat(tokens[1]);
        return lowerBound + (float) (Math.random() * (upperBound - lowerBound));
    } catch (NumberFormatException ex) {
        throw new ValueException("Invalid range: `" + range + "` found for type Float while parsing property: " + property, ex);
    }
}
Also used : ValueException(io.micronaut.core.value.ValueException)

Example 3 with ValueException

use of io.micronaut.core.value.ValueException in project micronaut-core by micronaut-projects.

the class PropertySourcePropertyResolver method getNextIntegerInRange.

private int getNextIntegerInRange(String range, String property) {
    try {
        String[] tokens = range.split(",");
        int lowerBound = Integer.parseInt(tokens[0]);
        if (tokens.length == 1) {
            return lowerBound >= 0 ? 1 : -1 * (random.nextInt(Math.abs(lowerBound)));
        }
        int upperBound = Integer.parseInt(tokens[1]);
        return lowerBound + (int) (Math.random() * (upperBound - lowerBound));
    } catch (NumberFormatException ex) {
        throw new ValueException("Invalid range: `" + range + "` found for type Integer while parsing property: " + property, ex);
    }
}
Also used : ValueException(io.micronaut.core.value.ValueException)

Aggregations

ValueException (io.micronaut.core.value.ValueException)3