Example usage for org.apache.commons.lang3 Validate inclusiveBetween

List of usage examples for org.apache.commons.lang3 Validate inclusiveBetween

Introduction

In this page you can find the example usage for org.apache.commons.lang3 Validate inclusiveBetween.

Prototype

public static void inclusiveBetween(final double start, final double end, final double value,
        final String message) 

Source Link

Document

Validate that the specified primitive value falls between the two inclusive values specified; otherwise, throws an exception with the specified message.

Usage

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.database.Sign.java

private void validateParameters(String name, String nameLocaleDe, String mnemonic, int learningProgress) {
    Validate.notNull(name, "Name must not be null");
    Validate.notBlank(name, "Name must not be empty.");
    Validate.notNull(nameLocaleDe, "NameLocaleDe must not be null");
    Validate.notBlank(nameLocaleDe, "NameLocaleDe must not be empty.");
    Validate.notNull(mnemonic, "Mnemonic must not be null");
    Validate.notBlank(mnemonic, "Mnemonic must not be empty.");
    Validate.inclusiveBetween(LEARNING_PROGRESS_LOWER_BOUNDARY, LEARNING_PROGRESS_UPPER_BOUNDARY,
            learningProgress, "Learning progress cannot be < -5 or > 5");
}

From source file:com.callidusrobotics.rrb4j.AbstractRasPiRobot.java

@Override
public void setMotors(final float m1Speed, final MotorDirection m1Direction, final float m2Speed,
        final MotorDirection m2Direction) {
    Validate.notNull(m1Direction, "MotorDirection can not be null");
    Validate.notNull(m2Direction, "MotorDirection can not be null");
    Validate.inclusiveBetween(0.0, 1.0, m1Speed, "Motor speed must be in the range [0, 1]");
    Validate.inclusiveBetween(0.0, 1.0, m2Speed, "Motor speed must be in the range [0, 1]");

    if (!motorsInitialized) {
        softPwmCreate(m1PwmPin);//from w w w.j  a va 2 s . c o m
        softPwmCreate(m2PwmPin);

        motorsInitialized = true;
    }

    // Stop the motors before reversing polarity
    if (this.m1Direction != m1Direction || this.m2Direction != m2Direction) {
        softPwmWrite(m1PwmPin, 0);
        softPwmWrite(m2PwmPin, 0);

        this.m1Direction = m1Direction;
        this.m2Direction = m2Direction;

        try {
            Thread.sleep(HB_DELAY_MILLIS);
        } catch (InterruptedException e) {
        }
    }

    m1PhasePin1.setState(m1Direction != MotorDirection.FORWARD);
    m1PhasePin2.setState(m1Direction == MotorDirection.FORWARD);
    m2PhasePin1.setState(m2Direction != MotorDirection.FORWARD);
    m2PhasePin2.setState(m2Direction == MotorDirection.FORWARD);
    softPwmWrite(m1PwmPin, (int) (100 * m1Speed * pwmScale));
    softPwmWrite(m2PwmPin, (int) (100 * m2Speed * pwmScale));
}

From source file:net.java.cargotracker.domain.model.flight.Flight.java

public Flight(Carrier airline, Airport from, Airport to, Date leaves, Date lands) {
    Validate.notNull(number, "Tracking ID is required.");
    Validate.inclusiveBetween(0, 999, number, "Flight number must be positive and below 1,000.");
    Validate.notNull(airline, "Flight must be run by an airline.");
    Validate.notNull(from, "Flight must take off somewhere.");
    Validate.notNull(to, "Flight must land somewhere.");
    Validate.notNull(leaves, "Take off time must be scheduled.");
    Validate.notNull(lands, "Landing time must be scheduled.");

    this.number = number;
    this.carrier = airline;
    this.departs = from;
    this.takeOff = leaves;
    this.arrives = to;
    this.landing = lands;
}

From source file:com.thinkbiganalytics.discovery.parsers.csv.CSVFileSchemaParser.java

private void validate() {
    Validate.isTrue(separatorChar != null && (separatorChar.length() == 1 || separatorChar.length() == 2),
            "Legal separator character required.");
    Validate.isTrue(StringUtils.isEmpty(quoteChar) || quoteChar.length() <= 2,
            "Legal quote character required.");
    Validate.isTrue(StringUtils.isEmpty(escapeChar) || escapeChar.length() <= 2,
            "Legal escape character required.");
    Validate.inclusiveBetween(1, MAX_ROWS, numRowsToSample, "Cannot sample more than " + MAX_ROWS + ".");
}

From source file:alfio.manager.EventManager.java

public void addPromoCode(String promoCode, Integer eventId, Integer organizationId, ZonedDateTime start,
        ZonedDateTime end, int discountAmount, DiscountType discountType, List<Integer> categoriesId) {
    Validate.isTrue(promoCode.length() >= 7, "min length is 7 chars");
    Validate.isTrue((eventId != null && organizationId == null) || (eventId == null && organizationId != null),
            "eventId or organizationId must be not null");
    if (DiscountType.PERCENTAGE == discountType) {
        Validate.inclusiveBetween(0, 100, discountAmount, "percentage discount must be between 0 and 100");
    }/*from  w w  w.ja va2s. c om*/
    if (DiscountType.FIXED_AMOUNT == discountType) {
        Validate.isTrue(discountAmount >= 0, "fixed discount amount cannot be less than zero");
    }

    //
    categoriesId = Optional.ofNullable(categoriesId).orElse(Collections.emptyList()).stream()
            .filter(Objects::nonNull).collect(toList());
    //

    promoCodeRepository.addPromoCode(promoCode, eventId, organizationId, start, end, discountAmount,
            discountType.toString(), Json.GSON.toJson(categoriesId));
}

From source file:org.apache.reef.tests.evaluator.failure.FailureDriver.java

@Inject
public FailureDriver(@Parameter(NumEvaluatorsToSubmit.class) final int numEvaluatorsToSubmit,
        @Parameter(NumEvaluatorsToFail.class) final int numEvaluatorsToFail,
        final EvaluatorRequestor requestor) {
    Validate.isTrue(numEvaluatorsToSubmit > 0, "The number of Evaluators to submit must be greater than 0.");
    Validate.inclusiveBetween(1, numEvaluatorsToSubmit, numEvaluatorsToFail,
            "The number of Evaluators to fail must be between 1 and numEvaluatorsToSubmit, inclusive.");

    this.numEvaluatorsToSubmit = numEvaluatorsToSubmit;
    this.numEvaluatorsToFail = numEvaluatorsToFail;

    this.numEvaluatorsLeftToSubmit = new AtomicInteger(numEvaluatorsToSubmit);

    // We should close numEvaluatorsToSubmit because all failed Evaluators are eventually resubmitted and closed.
    this.numEvaluatorsLeftToClose = new AtomicInteger(numEvaluatorsToSubmit);

    this.requestor = requestor;
    LOG.info("Driver instantiated");
}

From source file:org.codice.alliance.video.stream.mpegts.netty.BitReader.java

public void skipBits(int numberOfBits) throws EOFException {

    Validate.inclusiveBetween(0, Integer.MAX_VALUE, numberOfBits, "numberOfBits must >=0");

    if (isByteBoundary() && numberOfBits % 8 == 0) {
        skipBytes(numberOfBits / 8);//from w w w.  j  a v  a2  s . com
        return;
    }

    int tmp = numberOfBits;
    while (tmp >= 32) {
        readBits(32);
        tmp -= 32;
    }
    if (tmp > 0) {
        readBits(tmp);
    }
}

From source file:org.codice.alliance.video.stream.mpegts.netty.BitReader.java

public long readBits(int numberOfBits) throws EOFException {

    Validate.inclusiveBetween(1, 32, numberOfBits, "numberOfBits must be [1,32]");

    if (numberOfBits == 1) {
        return readBit();
    }/*from  w w w. ja  va2s.c  om*/

    long result = 0;

    for (int i = 0; i < numberOfBits; i++) {
        result |= readBit() << (numberOfBits - i - 1);
    }

    return result;
}

From source file:org.codice.alliance.video.stream.mpegts.netty.UdpStreamProcessor.java

/**
 * @param metacardUpdateInitialDelay must be non-null and >=0 and <={@link #MAX_METACARD_UPDATE_INITIAL_DELAY}
 *//*from   w  w w. ja  va  2 s  . c  o m*/
public void setMetacardUpdateInitialDelay(Long metacardUpdateInitialDelay) {
    notNull(metacardUpdateInitialDelay, "metacardUpdateInitialDelay must be non-null");
    Validate.inclusiveBetween(0, MAX_METACARD_UPDATE_INITIAL_DELAY, metacardUpdateInitialDelay, String
            .format("metacardUpdateInitialDelay must be >=0 and <=%d", MAX_METACARD_UPDATE_INITIAL_DELAY));
    this.metacardUpdateInitialDelay = metacardUpdateInitialDelay;
}

From source file:org.jodconverter.office.DefaultOfficeManagerBuilder.java

/**
 * Specifies the timeout, in milliseconds, when trying to execute an office process call
 * (start/terminate)./*  w  w w . ja va 2 s  .  c om*/
 *
 * <p>&nbsp; <b><i>Default</i></b>: 120000 (2 minutes)
 *
 * @param retryTimeout the process timeout, in milliseconds.
 * @return This builder instance.
 */
@Deprecated
public DefaultOfficeManagerBuilder setRetryTimeout(final long retryTimeout) {

    Validate.inclusiveBetween(0, Long.MAX_VALUE, retryTimeout,
            String.format("The processTimeout %s must be greater than or equal to 0", retryTimeout));
    this.processTimeout = retryTimeout;
    return this;
}