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, String message) 

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), "The value must be greater than zero"); Validate.isTrue( myObject.isOk(), "The object is not OK"); 

For performance reasons, the message string should not involve a string append, instead use the #isTrue(boolean,String,Object) method.

Usage

From source file:com.opengamma.analytics.math.rootfinding.RealSingleRootFinder.java

/**
 * Tests that the inputs to the root-finder are not null, and that a root is bracketed by the bounding values.
 * @param function The function, not null
 * @param x1 The first bound, not null/* w w w  .j a v a2  s .  c om*/
 * @param x2 The second bound, not null, must be greater than x1
 * @throws IllegalArgumentException if x1 and x2 do not bracket a root
 */
protected void checkInputs(final Function1D<Double, Double> function, final Double x1, final Double x2) {
    Validate.notNull(function);
    Validate.notNull(x1);
    Validate.notNull(x2);
    Validate.isTrue(x1 <= x2, "x1 must be less or equal to  x2");
    Validate.isTrue(function.evaluate(x1) * function.evaluate(x2) <= 0, "x1 and x2 do not bracket a root");
}

From source file:com.opengamma.analytics.financial.interestrate.swap.derivative.CrossCurrencySwap.java

/**
 * A float-float cross currency swap//from   w  w w. j a  v a2  s .c  o m
 * @param domesticLeg The payments in domestic currency
 * @param foreignLeg The payments in foreign currency
 * @param spotFx units of domestic of one unit of foreign //TODO this is a hack until we can get this information into the calculator 
 */
public CrossCurrencySwap(FloatingRateNote domesticLeg, FloatingRateNote foreignLeg, final double spotFx) {

    Validate.notNull(domesticLeg, "nulldomesticLeg");
    Validate.notNull(foreignLeg, "null foreignLeg");
    Validate.isTrue(domesticLeg.getCurrency() != foreignLeg.getCurrency(), "Both legs are in same currency");
    _domesticLeg = domesticLeg;
    _foreignLeg = foreignLeg;
    _spotFX = spotFx;
}

From source file:com.opengamma.analytics.financial.instrument.annuity.AnnuityCapFloorCMSSpreadDefinition.java

/**
 * CMS spread cap/floor (or leg of CMS spread caplet/floorlet) constructor from standard description. The cap/floor have fixing in advance and payment in arrears. 
 * The CMS fixing is done at a Ibor lag before the coupon start.
 * @param settlementDate The settlement date.
 * @param maturityDate The annuity maturity date.
 * @param notional The notional.// www  . ja  v a2  s  . co m
 * @param index1 The first CMS index.
 * @param index2 The second CMS index.
 * @param paymentPeriod The payment period of the coupons.
 * @param dayCount The day count of the coupons.
 * @param isPayer Payer (true) / receiver (false) fleg.
 * @param strike The common strike.
 * @param isCap The cap (true) / floor (false) flag.
 * @return The CMS coupon leg.
 */
public static AnnuityCapFloorCMSSpreadDefinition from(final ZonedDateTime settlementDate,
        final ZonedDateTime maturityDate, final double notional, final IndexSwap index1, final IndexSwap index2,
        final Period paymentPeriod, final DayCount dayCount, final boolean isPayer, final double strike,
        final boolean isCap) {
    Validate.notNull(settlementDate, "settlement date");
    Validate.notNull(maturityDate, "maturity date");
    Validate.notNull(index1, "First index");
    Validate.notNull(index2, "Second index");
    Validate.isTrue(notional > 0, "notional <= 0");
    Validate.notNull(paymentPeriod, "Payment period");
    final ZonedDateTime[] paymentDatesUnadjusted = ScheduleCalculator.getUnadjustedDateSchedule(settlementDate,
            maturityDate, paymentPeriod, true, false);
    final ZonedDateTime[] paymentDates = ScheduleCalculator.getAdjustedDateSchedule(paymentDatesUnadjusted,
            index1.getIborIndex().getBusinessDayConvention(), index1.getIborIndex().getCalendar(), false);
    final double sign = isPayer ? -1.0 : 1.0;
    final CapFloorCMSSpreadDefinition[] coupons = new CapFloorCMSSpreadDefinition[paymentDates.length];
    coupons[0] = CapFloorCMSSpreadDefinition.from(paymentDates[0], settlementDate, paymentDates[0],
            dayCount.getDayCountFraction(settlementDate, paymentDates[0]), sign * notional, index1, index2,
            strike, isCap);
    for (int loopcpn = 1; loopcpn < paymentDates.length; loopcpn++) {
        coupons[loopcpn] = CapFloorCMSSpreadDefinition.from(paymentDates[loopcpn], paymentDates[loopcpn - 1],
                paymentDates[loopcpn],
                dayCount.getDayCountFraction(paymentDates[loopcpn - 1], paymentDates[loopcpn]), sign * notional,
                index1, index2, strike, isCap);
    }
    return new AnnuityCapFloorCMSSpreadDefinition(coupons);
}

From source file:net.daboross.bukkitdev.skywars.events.events.GameStartInfo.java

public GameStartInfo(ArenaGame game) {
    Validate.notNull(game, "Game cannot be null");
    this.game = game;
    List<UUID> playersList = game.getAlivePlayers();
    this.players = new ArrayList<>(playersList.size());
    for (UUID uuid : playersList) {
        Player p = Bukkit.getPlayer(uuid);
        Validate.isTrue(p != null, String.format("Player (uuid: %s) not online", uuid));
        players.add(p);/* ww w  . j  a va2 s . com*/
    }
}

From source file:com.hmsinc.epicenter.model.util.DatabaseConfiguration.java

@PostConstruct
public void validate() {
    Validate.notNull(databaseType, "Database name must be specified!");
    Validate.isTrue(databaseConstantsMap.containsKey("hibernate-" + databaseType),
            "Unsupported database: " + databaseType);
}

From source file:de.xaniox.heavyspleef.addon.access.CommandManagerAccess.java

public void registerSpleefCommand(Class<?> clazz, AddOn addOn) {
    Validate.isTrue(!isClassRegistered(clazz),
            "Command class " + clazz.getName() + " has already been registered");

    Set<Class<?>> classes = registeredAddOnCommands.get(addOn);
    if (classes == null) {
        classes = Sets.newHashSet();//from   w  w  w  .ja  v  a 2 s. co  m
        registeredAddOnCommands.put(addOn, classes);
    }

    classes.add(clazz);
    delegate.registerSpleefCommands(clazz);
}

From source file:hr.fer.spocc.grammar.BnfUtils.java

/**
 * Stvara pravila konteksno neovisne gramatike na temelju stringa koji
 * je u BNF notaciji.//  w w w.j  av  a  2s  .c  o  m
 * Nezavrsni znakovi opisuju se regularnim izrazom: &lt;{znak}*&gt;<br>
 * Zavrsni znakovi opisuju se regularnim izrazom: {znak}<br>
 * Epsilon se opisuje regularnim izrazom: $<br>
 * Izbor se opisuje pipe operatorom: |<br>
 * Pridruzivanje se opisuje regularnim izrazom: ::=<br>
 * Pravila moraju biti razdvojena jednom od bjelina
 * <p>Primjeri:
 * &lt;BROJ&gt; ::= &lt;ZNAMENKA&gt;&lt;BROJ&gt; | &lt;ZNAMENKA&gt;<br>
 * &lt;ZNAMENKA&gt; ::= 0|1|2|3| 4  | 5|  6 |7|8|  9
 * </p>
 * 
 * @param bnfNotation
 * @return
 * @see BnfEscaper
 */
public static List<CfgProductionRule<Character>> createCfgProductionRules(String bnfNotation) {
    List<CfgProductionRule<Character>> rules = new ArrayList<CfgProductionRule<Character>>();

    // insert sentinel variable at the end, to make parsing easier
    bnfNotation += "<>";
    Set<Integer> unescapedIndexes = new HashSet<Integer>();
    String[] bnfRules = bnfNotation.split("::=");
    Validate.isTrue(bnfRules.length > 1 && bnfRules[0].charAt(0) == '<'
            && bnfRules[0].charAt(bnfRules[0].length() - 1) == '>', "Invalid first BNF rule");
    String leftSideVariable = bnfRules[0].substring(1, bnfRules[0].length() - 1);

    for (int ruleNumber = 1; ruleNumber < bnfRules.length; ++ruleNumber) {
        String unescapedBnf = BnfEscaper.getInstance().unescape(bnfRules[ruleNumber], unescapedIndexes);

        List<Symbol<Character>> rightSideSymbols = new ArrayList<Symbol<Character>>();
        StringBuilder rightSideVariable = new StringBuilder();
        String nextLeftSideVariable = null;
        boolean opened = false;
        for (int i = 0; i < unescapedBnf.length(); ++i) {
            boolean terminalOrVariablePart = false;
            char c = unescapedBnf.charAt(i);
            if (!unescapedIndexes.contains(i)) {
                switch (c) {
                case '<':
                    opened = true;
                    break;
                case '>':
                    rightSideSymbols.add(new Variable<Character>(rightSideVariable.toString()));
                    nextLeftSideVariable = rightSideVariable.toString();
                    StringBuilderUtils.clear(rightSideVariable);
                    opened = false;
                    break;
                case '|':
                    rules.add(new CfgProductionRule<Character>(new Variable<Character>(leftSideVariable),
                            rightSideSymbols));
                    rightSideSymbols.clear();
                    nextLeftSideVariable = null;
                    break;
                case '$':
                    Symbol<Character> epsilon = Symbols.epsilonSymbol();
                    rightSideSymbols.add(epsilon);
                    break;
                case ':':
                case '=':
                    break;
                default:
                    terminalOrVariablePart = true;
                }
            } else {
                terminalOrVariablePart = true;
            }

            if (terminalOrVariablePart) {
                if (opened)
                    rightSideVariable.append(c);
                else {
                    rightSideSymbols.add(new Terminal<Character>(c));
                }
            }
        }

        // pop left side variable
        Validate.isTrue(!rightSideSymbols.isEmpty(), "Right side of BNF rule #" + (ruleNumber + 1)
                + " or left side of BNF rule #" + (ruleNumber + 2) + " is invalid");
        rightSideSymbols.remove(rightSideSymbols.size() - 1);

        rules.add(
                new CfgProductionRule<Character>(new Variable<Character>(leftSideVariable), rightSideSymbols));

        Validate.notNull(nextLeftSideVariable, "Right side of BNF rule #" + (ruleNumber + 1)
                + " or left side of BNF rule #" + (ruleNumber + 2) + " is invalid");
        leftSideVariable = nextLeftSideVariable;
    }

    return rules;
}

From source file:io.tilt.minka.domain.ShardCommand.java

public ShardCommand(final Command command, final NetworkShardID shardId) {
    super();// w w w .  j a va 2  s .  c o  m
    this.command = command;
    Validate.isTrue(
            command == Command.FOLLOWER_DEACTIVATE || command == Command.FOLLOWER_ACTIVATE
                    || command == Command.FOLLOWER_DECOMISSION || command == Command.FOLLOWER_HOARD,
            "this type is inalid for a host");
    this.shardId = shardId;
}

From source file:com.opengamma.analytics.financial.model.option.pricing.tree.NormalBinomialTreeBuilder.java

@Override
protected DoublesPair getCentralNodePair(final double dt, final double sigma, final double forward,
        final double centreLevel) {
    final double sigma2dt = sigma * sigma * dt;
    final double b = 2 * centreLevel;
    final double c = forward * (2 * centreLevel - forward) - sigma2dt;
    final double root = b * b - 4 * c;
    Validate.isTrue(root >= 0, "can't find upper node - root negative");
    final double upper = (b + Math.sqrt(root)) / 2;
    final double lower = 2 * centreLevel - upper;
    return new DoublesPair(lower, upper);
}

From source file:com.evolveum.midpoint.repo.api.query.NAryLogicalFilter.java

public void setFilters(List<QueryFilter> filters) {
    Validate.notNull(filters, "Filter list must not be null.");
    Validate.isTrue(filters.size() >= 2, "You must use two or more filters.");
    this.filters = filters;
}