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:ch.algotrader.dao.security.StockDaoImpl.java

@Override
public List<Stock> findByIndustryGroup(String code) {

    Validate.notEmpty(code, "Code is empty");

    return findCaching("Stock.findByIndustryGroup", QueryType.BY_NAME, new NamedParam("code", code));
}

From source file:com.edmunds.etm.management.api.HostAddress.java

/**
 * Constructor.//from   w  w w .j  a v a  2  s .c  o m
 *
 * @param host the host name or ip address.
 * @param port the port number.
 */
public HostAddress(String host, int port) {
    Validate.notEmpty(host, "host cannot be empty");

    this.host = host;
    this.port = port;
}

From source file:jenkins.plugins.git.MethodUtils.java

/**
 * <p>Retrieves a method whether or not it's accessible. If no such method
 * can be found, return {@code null}.</p>
 *
 * @param cls            The class that will be subjected to the method search
 * @param methodName     The method that we wish to call
 * @param parameterTypes Argument class types
 * @return The method//  w  ww .  ja va2s  .  c o  m
 */
static Method getMethodImpl(final Class<?> cls, final String methodName, final Class<?>... parameterTypes) {
    Validate.notNull(cls, "Null class not allowed.");
    Validate.notEmpty(methodName, "Null or blank methodName not allowed.");

    // fast path, check if directly declared on the class itself
    for (final Method method : cls.getDeclaredMethods()) {
        if (methodName.equals(method.getName()) && Arrays.equals(parameterTypes, method.getParameterTypes())) {
            return method;
        }
    }
    if (!cls.isInterface()) {
        // ok, now check if directly implemented on a superclass
        // Java 8: note that super-interface implementations trump default methods
        for (Class<?> klass = cls.getSuperclass(); klass != null; klass = klass.getSuperclass()) {
            for (final Method method : klass.getDeclaredMethods()) {
                if (methodName.equals(method.getName())
                        && Arrays.equals(parameterTypes, method.getParameterTypes())) {
                    return method;
                }
            }
        }
    }
    // ok, now we are looking for an interface method... the most specific one
    // in the event that we have two unrelated interfaces both declaring a method of the same name
    // we will give up and say we could not find the method (the logic here is that we are primarily
    // checking for overrides, in the event of a Java 8 default method, that default only
    // applies if there is no conflict from an unrelated interface... thus if there are
    // default methods and they are unrelated then they don't exist... if there are multiple unrelated
    // abstract methods... well they won't count as a non-abstract implementation
    Method res = null;
    for (final Class<?> klass : (List<Class<?>>) ClassUtils.getAllInterfaces(cls)) {
        for (final Method method : klass.getDeclaredMethods()) {
            if (methodName.equals(method.getName())
                    && Arrays.equals(parameterTypes, method.getParameterTypes())) {
                if (res == null) {
                    res = method;
                } else {
                    Class<?> c = res.getDeclaringClass();
                    if (c == klass) {
                        // match, ignore
                    } else if (c.isAssignableFrom(klass)) {
                        // this is a more specific match
                        res = method;
                    } else if (!klass.isAssignableFrom(c)) {
                        // multiple overlapping interfaces declare this method and there is no common ancestor
                        return null;

                    }
                }
            }
        }
    }
    return res;
}

From source file:com.edmunds.etm.common.api.AgentInstance.java

/**
 * Constructs a new AgentInstance with the specified parameters.
 *
 * @param id unique agent identifier/*from   w  w  w. j av a 2 s  . c  o m*/
 * @param version application version
 * @param ipAddress ip address of the agent host
 */
public AgentInstance(UUID id, String ipAddress, String version) {
    Validate.notNull(id, "Unique ID is null");
    Validate.notEmpty(ipAddress, "IP address is empty");
    Validate.notEmpty(version, "Agent version is empty");
    this.id = id;
    this.ipAddress = ipAddress;
    this.version = version;
}

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

@Override
public void initialize(SimulationState simState) {
    _simState = simState;//from w  w w .j a  v  a  2s . c om

    // get values from properties file
    String numAgents = _simState.getProperties().getProperty("individual-count");
    Validate.notEmpty(numAgents, "Individual count may not be empty");
    _numAgents = Integer.parseInt(numAgents);

    _locationsFile = _simState.getProperties().getProperty("locations-file");
    Validate.notEmpty(_locationsFile, "Locations file may not be empty");

    _locations = Utils.readPoints(_locationsFile);

    // add the agent count info to root directory
    _simState.setRootDirectory(Reporter.ROOT_DIRECTORY + "agent-count=" + _numAgents + "_");
}

From source file:net.camelpe.extension.camel.spi.CdiRegistry.java

/**
 * @see org.apache.camel.spi.Registry#lookup(java.lang.String)
 *///w w w . ja v a 2 s .  c  o  m
@Override
public Object lookup(final String name) {
    Validate.notEmpty(name, "name");
    getLog().trace("Looking up bean using name = [{}] in CDI registry ...", name);

    final Set<Bean<?>> beans = getDelegate().getBeans(name);
    if (beans.isEmpty()) {
        getLog().debug("Found no bean matching name = [{}] in CDI registry.", name);
        return null;
    }
    if (beans.size() > 1) {
        throw new IllegalStateException(
                "Expected to find exactly one bean having name [" + name + "], but got [" + beans.size() + "]");
    }
    final Bean<?> bean = beans.iterator().next();
    getLog().debug("Found bean [{}] matching name = [{}] in CDI registry.", bean, name);

    final CreationalContext<?> creationalContext = getDelegate().createCreationalContext(null);

    return getDelegate().getReference(bean, bean.getBeanClass(), creationalContext);
}

From source file:io.yields.math.framework.property.SortedProperty.java

@Override
public boolean isValid(List<T> value, FunctionalContext<List<T>> context) {
    Validate.notEmpty(value, "An empty collection cannot be ordered.");
    int sign = increasing ? 1 : -1;
    List<T> sorted = value.stream().sorted((t1, t2) -> sign * t1.compareTo(t2)).collect(Collectors.toList());
    return IntStream.range(0, value.size())
            .allMatch(index -> comparator.compare(sorted.get(index), value.get(index)) == 0);
}

From source file:com.bibisco.manager.LocaleManager.java

public void saveLocale(String pStrLocale) {

    mLog.debug("Start saveLocale(", pStrLocale, ")");

    Validate.notEmpty(pStrLocale, "locale cannot be empty");

    String[] lStrLocaleSplit = pStrLocale.split("_");
    if (lStrLocaleSplit.length != 2) {
        throw new IllegalArgumentException("Not a valid locale");
    }/* www . java  2  s. c  o  m*/

    PropertiesManager.getInstance().updateProperty("locale", pStrLocale);
    mLocale = new Locale(lStrLocaleSplit[0], lStrLocaleSplit[1]);

    mLog.debug("End saveLocale(String)");
}

From source file:ch.algotrader.event.dispatch.ServerToStrategyEventPublisher.java

@Override
public void publishStrategyEvent(final Object event, final String strategyName) {

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

    this.template.convertAndSend(strategyName + ".QUEUE", event);
}

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

/**
 * {@inheritDoc}//from w w  w. j ava2s . co  m
 */
@Override
public <T extends BaseEntityI> Collection<T> lazyLoadCollection(BaseEntityI entity, String context,
        Collection<T> col) {

    Validate.notNull(entity, "Entity is null");
    Validate.notEmpty(context, "Context is empty");
    Validate.notNull(col, "Col is null");

    return HibernateInitializer.INSTANCE.initializeCollection(entity, context, col);

}