Example usage for org.apache.commons.lang Validate isTrue

List of usage examples for org.apache.commons.lang Validate isTrue

Introduction

In this page you can find the example usage for org.apache.commons.lang Validate isTrue.

Prototype

public static void isTrue(boolean expression) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the test result is false.

This is used when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

 Validate.isTrue( i > 0 ); Validate.isTrue( myObject.isOk() ); 

The message in the exception is 'The validated expression is false'.

Usage

From source file:ar.com.zauber.commons.auth.acegi.ChangePasswordAdvice.java

/**
 * @see AfterReturningAdvice#afterReturning(Object, Method, Object[],
 *      Object)/*  w  w w  . j a  v a  2s .c o  m*/
 */
public final void afterReturning(final Object returnValue, final Method method, final Object[] args,
        final Object target) throws Throwable {
    final int numberOfParam = 2;
    Validate.isTrue(args.length == numberOfParam);
    changePassword((String) args[0], (String) args[1]);
}

From source file:com.opengamma.analytics.financial.schedule.EndOfYearScheduleCalculator.java

public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        if (startDate.getDayOfMonth() == 31 && startDate.getMonthOfYear() == MonthOfYear.DECEMBER) {
            return new ZonedDateTime[] { startDate };
        }/*w w  w  .  jav a  2 s  .co  m*/
        throw new IllegalArgumentException(
                "Start date and end date were the same but neither was the last day of the year");
    }
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    ZonedDateTime date = startDate.with(DateAdjusters.lastDayOfYear());
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.plusYears(1).with(DateAdjusters.lastDayOfYear());
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:ar.com.zauber.commons.message.impl.mail.BufferedServiceEmailNotificationStrategy.java

/**
 * Creates the BufferedServiceEmailNotificationStrategy.
 *///from   ww  w  . java  2  s  .c o m
public BufferedServiceEmailNotificationStrategy(final EmailService emailService, final int qtyFlush,
        final String senderDomain, final String senderAccount) {
    Validate.notNull(emailService);
    Validate.isTrue(qtyFlush > 0);
    Validate.notEmpty(senderDomain);
    Validate.notEmpty(senderAccount);

    this.queue = new ArrayBlockingQueue<SendEmailDTO>(qtyFlush);
    this.emailService = emailService;
    this.senderDomain = senderDomain;
    this.senderAccount = senderAccount;
}

From source file:com.vmware.identity.interop.ldap.LdapConnectionFactory.java

/**
 * Create a LDAP connection with the specified host & port parameter
 * @param host  cannot be null//ww w.  java2s . c  o m
 * @param port  positive number
 * @return the LDAP scheme connection.
 */
public ILdapConnection getLdapConnection(String host, int port) {
    Validate.notNull(host);
    Validate.isTrue(port > 0);
    // keep the implementation unchanged for external client such as lookup service
    // and STS installer by providing empty connection option for external request
    List<LdapSetting> connOptions = Collections.emptyList();

    return getLdapConnection(PlatformUtils.getConnectionUriDefaultScheme(host, port), connOptions);
}

From source file:com.opengamma.analytics.math.interpolation.MonotonicIncreasingInterpolator1D.java

@Override
public double firstDerivative(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(data, "data bundle");
    Validate.isTrue(data instanceof Interpolator1DMonotonicIncreasingDataBundle);
    final Interpolator1DMonotonicIncreasingDataBundle miData = (Interpolator1DMonotonicIncreasingDataBundle) data;

    final int n = data.size() - 1;
    final double[] xData = data.getKeys();
    final double[] yData = data.getValues();

    double h, dx, a, b;
    if (value < data.firstKey()) {
        h = 0;/*from ww w .j a va 2  s. c om*/
        dx = value;
        a = miData.getA(0);
        b = miData.getB(0);
    } else if (value > data.lastKey()) {
        h = yData[n];
        dx = value - xData[n];
        a = miData.getA(n + 1);
        b = miData.getB(n + 1);
    } else {
        final int low = data.getLowerBoundIndex(value);
        h = yData[low];
        dx = value - xData[low];
        a = miData.getA(low + 1);
        b = miData.getB(low + 1);
    }
    if (Math.abs(b * dx) < 1e-8) {
        return h + a * (dx + b * dx * dx / 2);
    }

    return a * Math.exp(b * dx);

}

From source file:com.vmware.identity.interop.ldap.LdapConnectionFactoryEx.java

/**
 * Create a LDAP connection with the specified host & port parameter
 * @param host  cannot be null//from   ww  w  . j  a v a 2  s  .c o m
 * @param port  positive number
 * @return the LDAP scheme connection.
 */
public ILdapConnectionEx getLdapConnection(String host, int port) {
    Validate.notNull(host);
    Validate.isTrue(port > 0);
    // keep the implementation unchanged for external client such as lookup service
    // and STS installer by providing empty connection option for external request
    List<LdapSetting> connOptions = Collections.emptyList();

    return getLdapConnection(PlatformUtils.getConnectionUriDefaultScheme(host, port), connOptions);
}

From source file:com.opengamma.analytics.financial.simpleinstruments.definition.SimpleFXFutureDefinition.java

@Override
public SimpleFXFuture toDerivative(final ZonedDateTime date) {
    Validate.notNull(date, "date");
    Validate.isTrue(date.isBefore(_expiryDate));
    double timeToFixing = TimeCalculator.getTimeBetween(date, _expiryDate);
    double timeToDelivery = TimeCalculator.getTimeBetween(date, _settlementDate);
    return new SimpleFXFuture(timeToFixing, timeToDelivery, _referencePrice, _unitAmount, _payCurrency,
            _receiveCurrency);//from   ww  w.ja v  a 2s  .  c o  m
}

From source file:com.opengamma.analytics.financial.schedule.EndOfMonthScheduleCalculator.java

public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        if (startDate.getDayOfMonth() == startDate.getMonthOfYear()
                .lengthInDays(startDate.toLocalDate().isLeapYear())) {
            return new ZonedDateTime[] { startDate };
        }/*from  w w w. j  av  a2 s.com*/
        throw new IllegalArgumentException(
                "Start date and end date were the same but neither was the last day of the month");
    }
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    ZonedDateTime date = startDate.with(DateAdjusters.lastDayOfMonth());
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.plus(Period.ofMonths(1)).with(DateAdjusters.lastDayOfMonth());
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.opengamma.analytics.financial.schedule.FirstOfYearScheduleCalculator.java

public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        if (startDate.getDayOfMonth() == 1 && startDate.getMonthOfYear() == MonthOfYear.JANUARY) {
            return new ZonedDateTime[] { startDate };
        }/*from   w w  w.  j ava 2s  .  c  o  m*/
        throw new IllegalArgumentException(
                "Start date and end date were the same but neither was the first day of the year");
    }
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    ZonedDateTime date = startDate.with(DateAdjusters.firstDayOfYear());
    if (date.isBefore(startDate)) {
        date = date.plusYears(1);
    }
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.plusYears(1);
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.palantir.ptoss.cinch.swing.JPasswordFieldWiringHarness.java

public Collection<Binding> wire(Bound bound, BindingContext context, Field field)
        throws IllegalAccessException, IntrospectionException {
    String target = bound.to();/*from  w ww  .  j  a v a  2  s.  c  o m*/
    JPasswordField pwdField = context.getFieldObject(field, JPasswordField.class);
    ObjectFieldMethod setter = context.findSetter(target);
    ObjectFieldMethod getter = context.findGetter(target);
    if (setter == null || getter == null) {
        throw new IllegalArgumentException("could not find getter/setter for " + target);
    }
    BindableModel model1 = context.getFieldObject(setter.getField(), BindableModel.class);
    BindableModel model2 = context.getFieldObject(getter.getField(), BindableModel.class);
    Validate.isTrue(model1 == model2);
    // verify type parameters
    return bindJPasswordField(model1, pwdField, getter.getMethod(), setter.getMethod());
}