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

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

Introduction

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

Prototype

public static <T> T notNull(final T object, final String message, final Object... values) 

Source Link

Document

Validate that the specified argument is not null ; otherwise throwing an exception with the specified message.

Usage

From source file:edu.sabanciuniv.sentilab.utils.extensions.IterablesExtensions.java

/**
 * Calculates the sum of a given iterable of {@link Number} type items.
 * @param iterable the {@link Iterable} of {@link Number} type items whose sum is desired.
 * @return the {@link Double} value with the sum.
 *//*w ww .ja v a  2  s .c  om*/
public static <I extends Number> double sum(Iterable<I> iterable) {
    Validate.notNull(iterable, CannedMessages.NULL_ARGUMENT, "iterable");

    double s = 0;
    for (I item : iterable) {
        s += item.doubleValue();
    }

    return s;
}

From source file:edu.sabanciuniv.sentilab.utils.extensions.MapsExtensions.java

/**
 * Increments the value of a given key in a map.
 * @param map the {@link Map} to use./*w  w  w  .j a v a2  s  . c  om*/
 * @param key the key to look for.
 * @param by the value to increment by.
 * @param add a {@link Boolean} flag indicating whether to add the key if it doesn't exist or not.
 * @return the map that was passed in.
 */
public static <K> Map<K, Double> increment(Map<K, Double> map, K key, Double by, boolean add) {
    Validate.notNull(map, CannedMessages.NULL_ARGUMENT, "map");

    Double value = map.get(key);
    if (value == null && add) {
        value = 0.0;
    }

    if (value != null) {
        map.put(key, value + by);
    }

    return map;
}

From source file:eu.ubipol.opinionmining.database_engine.DatabaseAdapter.java

public DatabaseAdapter(AspectLexicon lexicon) {
    Validate.notNull(lexicon, CannedMessages.NULL_ARGUMENT, "lexicon");
    this.lexicon = lexicon;
}

From source file:com.premiumminds.billy.core.util.BillyValidator.java

public static <T> T mandatory(T o, String fieldName) {
    Validate.notNull(o, BillyValidator.instance.localizer.getString("invalid.mandatory", fieldName), o);
    return o;/*w  w  w .  ja  v a2 s. co  m*/
}