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

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

Introduction

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

Prototype

public static void notEmpty(String string, String message) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length).

 Validate.notEmpty(myString, "The string must not be empty"); 

Usage

From source file:com.alibaba.cobar.client.router.config.support.InternalRuleLoader4DefaultInternalRouter.java

public void loadRulesAndEquipRouter(List<InternalRule> rules, DefaultCobarClientInternalRouter router,
        Map<String, Object> functionsMap) {
    if (CollectionUtils.isEmpty(rules)) {
        return;/*from   w  w  w. java  2 s  . c om*/
    }

    for (InternalRule rule : rules) {
        String namespace = StringUtils.trimToEmpty(rule.getNamespace());
        String sqlAction = StringUtils.trimToEmpty(rule.getSqlmap());
        String shardingExpression = StringUtils.trimToEmpty(rule.getShardingExpression());
        String destinations = StringUtils.trimToEmpty(rule.getShards());

        Validate.notEmpty(destinations, "destination shards must be given explicitly.");

        if (StringUtils.isEmpty(namespace) && StringUtils.isEmpty(sqlAction)) {
            throw new IllegalArgumentException("at least one of 'namespace' or 'sqlAction' must be given.");
        }
        if (StringUtils.isNotEmpty(namespace) && StringUtils.isNotEmpty(sqlAction)) {
            throw new IllegalArgumentException(
                    "'namespace' and 'sqlAction' are alternatives, can't guess which one to use if both of them are provided.");
        }

        if (StringUtils.isNotEmpty(namespace)) {
            List<Set<IRoutingRule<IBatisRoutingFact, List<String>>>> ruleSequence = setUpRuleSequenceContainerIfNecessary(
                    router, namespace);

            if (StringUtils.isEmpty(shardingExpression)) {

                ruleSequence.get(3).add(new IBatisNamespaceRule(namespace, destinations));
            } else {
                IBatisNamespaceShardingRule insr = new IBatisNamespaceShardingRule(namespace, destinations,
                        shardingExpression);
                if (MapUtils.isNotEmpty(functionsMap)) {
                    insr.setFunctionMap(functionsMap);
                }
                ruleSequence.get(2).add(insr);
            }
        }
        if (StringUtils.isNotEmpty(sqlAction)) {
            List<Set<IRoutingRule<IBatisRoutingFact, List<String>>>> ruleSequence = setUpRuleSequenceContainerIfNecessary(
                    router, StringUtils.substringBeforeLast(sqlAction, "."));

            if (StringUtils.isEmpty(shardingExpression)) {
                ruleSequence.get(1).add(new IBatisSqlActionRule(sqlAction, destinations));
            } else {
                IBatisSqlActionShardingRule issr = new IBatisSqlActionShardingRule(sqlAction, destinations,
                        shardingExpression);
                if (MapUtils.isNotEmpty(functionsMap)) {
                    issr.setFunctionMap(functionsMap);
                }
                ruleSequence.get(0).add(issr);
            }
        }
    }
}

From source file:ch.algotrader.dao.strategy.MeasurementDaoImpl.java

@Override
public List<Measurement> findMeasurementsByMaxDate(String strategyName, String name, Date maxDateTime) {

    Validate.notEmpty(strategyName, "Strategy name is empty");
    Validate.notEmpty(name, "Name is empty");
    Validate.notNull(maxDateTime, "maxDateTime is null");

    return findCaching("Measurement.findMeasurementsByMaxDate", QueryType.BY_NAME,
            new NamedParam("strategyName", strategyName), new NamedParam("name", name),
            new NamedParam("maxDateTime", maxDateTime));
}

From source file:edu.snu.leader.discrete.simulator.GautraisConflictDecisionCalculator.java

@Override
public void initialize(SimulationState simState) {
    _simState = simState;/*ww  w . j  a  v  a  2 s.  com*/

    // set values from properties
    String tauO = _simState.getProperties().getProperty("tau-o");
    Validate.notEmpty(tauO, "tau-o may not be empty");
    _tauO = Double.parseDouble(tauO);

    String alphaF = _simState.getProperties().getProperty("alpha-f");
    Validate.notEmpty(alphaF, "alpha-f may not be empty");
    _alphaF = Double.parseDouble(alphaF);

    String gammaC = _simState.getProperties().getProperty("gamma-c");
    Validate.notEmpty(gammaC, "gamma-c may not be empty");
    _gammaC = Double.parseDouble(gammaC);

    String epsilonC = _simState.getProperties().getProperty("epsilon-c");
    Validate.notEmpty(epsilonC, "epsilon-c may not be empty");
    _epsilonC = Double.parseDouble(epsilonC);

    String alphaC = _simState.getProperties().getProperty("alpha-c");
    Validate.notEmpty(alphaC, "alpha-c may not be empty");
    _alphaC = Double.parseDouble(alphaC);

    String betaF = _simState.getProperties().getProperty("beta-f");
    Validate.notEmpty(betaF, "beta-f may not be empty");
    _betaF = Double.parseDouble(betaF);

    String defConflictValue = _simState.getProperties().getProperty("default-conflict-value");
    Validate.notEmpty(defConflictValue, "default-conflict-value may not be empty");
    _defaultConflictValue = Double.parseDouble(defConflictValue);

    _destinationSizeRadius = _simState.getDestinationRadius();

    // add gautrais info to root directory path
    _simState.setRootDirectory(Reporter.ROOT_DIRECTORY + "GautraisValues");
}

From source file:ch.algotrader.service.PropertyServiceImpl.java

/**
 * {@inheritDoc}/*from www.j  a  va 2  s .c o m*/
 */
@Override
@Transactional(propagation = Propagation.REQUIRED)
public PropertyHolder addProperty(final long propertyHolderId, final String name, final Object value,
        final boolean persistent) {

    Validate.notEmpty(name, "Name is empty");
    Validate.notNull(value, "Value is null");

    // reattach the propertyHolder
    PropertyHolder propertyHolder = this.propertyHolderDao.load(propertyHolderId);

    Property property = propertyHolder.getProps().get(name);
    if (property == null) {

        // create the property
        property = Property.Factory.newInstance();
        property.setName(name);
        property.setValue(value);
        property.setPersistent(persistent);

        // associate the propertyHolder
        property.setPropertyHolder(propertyHolder);

        this.propertyDao.save(property);

        // reverse-associate the propertyHolder (after property has received an id)
        propertyHolder.getProps().put(name, property);

    } else {

        property.setValue(value);
    }

    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("added property {} value {} to {}", name, value, propertyHolder);
    }

    return propertyHolder;

}

From source file:com.evolveum.midpoint.model.impl.sync.ActionManagerImpl.java

@Override
public Action getActionInstance(String uri) {
    Validate.notEmpty(uri, "Action URI must not be null or empty.");
    Class<T> clazz = actionMap.get(uri);
    if (clazz == null) {
        return null;
    }//from  w  w w  .ja v a 2 s. c o m

    Action action = null;
    try {
        action = clazz.newInstance();
        if (action instanceof BaseAction) {
            BaseAction baseAction = (BaseAction) action;
            baseAction.setClockwork(clockwork);
            baseAction.setExecutor(changeExecutor);
            baseAction.setPrismContext(prismContext);
            baseAction.setAuditService(auditService);
            baseAction.setProvisioningService(provisioningService);
            baseAction.setContextFactory(contextFactory);
            baseAction.setModel(model);
        }
    } catch (Exception ex) {
        LoggingUtils.logException(trace, "Couldn't create action instance", ex);
    }

    return action;
}

From source file:io.dfox.junit.http.api.Path.java

/**
 * @param grouping The group the test belongs to. For JUnit tests, this is the test class name.
 * @param name The name of the test. For JUnit tests, this is the test method name.
 *//*from  w w w .  j a  v a 2 s .  com*/
public Path(final String grouping, final Optional<String> name) {
    Validate.notEmpty(grouping, "grouping cannot be empty");
    Validate.notNull(name, "name cannot be null");

    this.grouping = grouping;
    this.name = name;
}

From source file:ch.algotrader.service.MeasurementServiceImpl.java

/**
 * {@inheritDoc}//  w w  w . ja v  a  2  s  .c  o m
 */
@Override
@Transactional(propagation = Propagation.REQUIRED)
public Measurement createMeasurement(final String strategyName, final String name, final Object value) {

    Validate.notEmpty(strategyName, "Strategy name is empty");
    Validate.notEmpty(name, "Name is empty");
    Validate.notNull(value, "Value is null");

    return createMeasurement(strategyName, name, this.engineManager.getCurrentEPTime(), value);

}

From source file:fr.ribesg.bukkit.api.chat.Chat.java

/**
 * Sends the provided Mojangson String(s) to the provided
 * {@link Player}.// ww w.j  a  v a  2 s.  co  m
 *
 * @param to         the player to whom we will send the message(s)
 * @param mojangsons the message(s) to send
 *
 * @see Player#sendMessage(String)
 */
public static void sendMessage(final Player to, final String... mojangsons) {
    Validate.notNull(to, "The 'to' argument should not be null");
    Validate.notEmpty(mojangsons, "Please provide at least one Mojangson String");
    Validate.noNullElements(mojangsons, "The 'mojangsons' argument should not contain null values");
    for (final String mojangson : mojangsons) {
        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + to.getName() + ' ' + mojangson);
    }
}

From source file:ch.algotrader.dao.security.SecurityDaoImpl.java

@Override
public Security findBySymbol(String symbol) {

    Validate.notEmpty(symbol, "Symbol is empty");

    return findUniqueCaching("Security.findBySymbol", QueryType.BY_NAME, new NamedParam("symbol", symbol));
}

From source file:ch.algotrader.dao.PositionDaoImpl.java

@Override
public <V> List<V> findByStrategy(String strategyName, EntityConverter<Position, V> converter) {

    Validate.notEmpty(strategyName, "Strategy name is empty");

    return find(converter, "Position.findByStrategy", QueryType.BY_NAME,
            new NamedParam("strategyName", strategyName));
}