Example usage for org.apache.commons.lang.math Range containsNumber

List of usage examples for org.apache.commons.lang.math Range containsNumber

Introduction

In this page you can find the example usage for org.apache.commons.lang.math Range containsNumber.

Prototype

public abstract boolean containsNumber(Number number);

Source Link

Document

Tests whether the specified Number occurs within this range.

The exact comparison implementation varies by subclass.

Usage

From source file:io.seldon.prediction.VariationPredictionStrategy.java

public SimplePredictionStrategy sample() {
    Integer hash = ThreadLocalRandom.current().nextInt();
    int sample = Math.abs(hash % 100) + 1;
    BigDecimal sampleDec = BigDecimal.valueOf(sample).divide(BigDecimal.valueOf(100));
    for (Range range : strategyMap.keySet()) {
        if (range.containsNumber(sampleDec)) {
            return strategyMap.get(range);
        }//from   w ww .  ja va2  s .c om
    }
    return null;
}

From source file:io.seldon.recommendation.VariationTestingClientStrategy.java

public ClientStrategy sample(String userId) {
    Integer hash = MurmurHash.hash(userId.getBytes(), HASH_SEED);
    int sample = Math.abs(hash % 100) + 1;
    BigDecimal sampleDec = BigDecimal.valueOf(sample).divide(BigDecimal.valueOf(100));
    for (Range range : strategyMap.keySet()) {
        if (range.containsNumber(sampleDec)) {
            return strategyMap.get(range);
        }/*ww  w  .  j av a  2  s .co  m*/
    }
    return null;
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

public <T extends Number> void testApacheCommonsRangeTime(org.apache.commons.lang.math.Range testRange,
        boolean isPoint, T[] array) {
    int totalCycles = NOT_BENCHMARK_ITERATION + BENCHMARK_ITERATION;
    // Initialization of the statistics
    long mean = 0;
    for (int i = 0; i < totalCycles; i++) {
        // Total calculation time
        long start = System.nanoTime();

        for (int j = 0; j < array.length; j++) {
            testRange.containsNumber(array[j]);
        }/*from   w  ww.ja va 2s  .c o  m*/
        long end = System.nanoTime() - start;

        // If the the first NOT_BENCHMARK_ITERATION cycles has been done, then the mean, maximum and minimum values are stored
        if (i > NOT_BENCHMARK_ITERATION - 1) {
            if (i == NOT_BENCHMARK_ITERATION) {
                mean = end;
            } else {
                mean = mean + end;
            }
        }
    }
    String description = "";
    if (isPoint) {
        description += " a single point";
    }
    // Mean values
    double meanValue = mean / BENCHMARK_ITERATION;
    // Output print
    System.out.println("\nMean value for" + description + " Apache Common Range : " + meanValue + " nsec.");
}

From source file:org.mili.core.lang.ASFValidate.java

/**
 * <p>/*w ww.ja  va 2s.c om*/
 * Checks if a number is in range and throws <code>IllegalArgumentException</code>, if
 * number is out of range.
 * </p>
 *
 * <p>The method is used to check numbers in range or not. As example if a port parameter is
 * checked.</p>
 *
 * <pre>
 * ASFValidate.isInRange(13, new IntegerRange(1, 10), "Not in range!");
 * </pre>
 *
 * @param n number.
 * @param r range.
 * @param message message if number is not in range.
 * @throws IllegalArgumentException if number is not in range.
 */
public static void isInRange(Number n, Range r, String message) {
    Validate.notNull(n, "number can't be null!");
    Validate.notNull(r, "range can't be null!");
    if (message == null) {
        message = "The validated number[" + n + "] is not in range[" + r.getMinimumNumber() + ".."
                + r.getMaximumNumber() + "]";
    }
    Validate.isTrue(r.containsNumber(n), message);
}