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

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

Introduction

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

Prototype

public static void noNullElements(Collection collection, String message) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the argument Collection has null elements or is null.

 Validate.noNullElements(myCollection, "The collection must not contain null elements"); 

If the collection is null then the message in the exception is 'The validated object is null'.

Usage

From source file:io.cloudslang.lang.compiler.scorecompiler.ScoreCompilerImpl.java

@Override
public CompilationModellingResult compileSource(Executable executable, Set<Executable> path) {
    List<RuntimeException> exceptions = new ArrayList<>();
    Map<String, Executable> filteredDependencies = new HashMap<>();
    //we handle dependencies only if the file has imports
    boolean hasDependencies = CollectionUtils.isNotEmpty(executable.getExecutableDependencies())
            && executable.getType().equals(SlangTextualKeys.FLOW_TYPE);
    if (hasDependencies) {
        try {// w  ww  .j  a va 2  s  .  co  m
            Validate.notEmpty(path, "Source " + executable.getName()
                    + " has dependencies but no path was given to the compiler");
            Validate.noNullElements(path, "Source " + executable.getName() + " has empty dependencies");
        } catch (RuntimeException ex) {
            exceptions.add(ex);
        }

        //we add the current executable since a dependency can require it
        List<Executable> availableExecutables = new ArrayList<>(path);
        availableExecutables.add(executable);

        try {
            //than we match the references to the actual dependencies
            filteredDependencies = dependenciesHelper.matchReferences(executable, availableExecutables);

            handleOnFailureCustomResults(executable, filteredDependencies);

            List<RuntimeException> errors = compileValidator.validateModelWithDependencies(executable,
                    filteredDependencies);
            exceptions.addAll(errors);
        } catch (RuntimeException ex) {
            exceptions.add(ex);
        }

    }

    try {
        //next we create an execution plan for the required executable
        ExecutionPlan executionPlan = compileToExecutionPlan(executable);

        //and also create execution plans for all other dependencies
        Converter<Executable, ExecutionPlan> converter = new Converter<Executable, ExecutionPlan>() {
            @Override
            public ExecutionPlan convert(Executable compiledExecutable) {
                return compileToExecutionPlan(compiledExecutable);
            }
        };
        Map<String, ExecutionPlan> dependencies = convertMap(filteredDependencies, converter);
        Collection<Executable> executables = new ArrayList<>(filteredDependencies.values());
        executables.add(executable);

        HashSet<String> subflowsUuids = new HashSet<>(dependencies.keySet());
        subflowsUuids.addAll(executable.getExternalExecutableDependencies());
        executionPlan.setSubflowsUUIDs(subflowsUuids);
        CompilationArtifact compilationArtifact = new CompilationArtifact(executionPlan, dependencies,
                executable.getInputs(), getSystemPropertiesFromExecutables(executables));
        return new CompilationModellingResult(compilationArtifact, exceptions);
    } catch (RuntimeException ex) {
        exceptions.add(ex);
    }
    return new CompilationModellingResult(null, exceptions);
}

From source file:com.opengamma.analytics.financial.interestrate.LastTimeCalculator.java

@Override
public Double[] visit(final InstrumentDerivative[] derivative) {
    Validate.notNull(derivative, "derivative");
    Validate.noNullElements(derivative, "derivative");
    final Double[] output = new Double[derivative.length];
    for (int loopderivative = 0; loopderivative < derivative.length; loopderivative++) {
        output[loopderivative] = derivative[loopderivative].accept(this);
    }/*from   ww w .j av a2  s.  co m*/
    return output;
}

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

/**
 * Broadcasts the provided Mojangson String(s) to
 * {@link Player Players} having the provided permission.
 *
 * @param permission a permission required to receive the message(s)
 * @param mojangsons the message(s) to send
 *
 * @see Server#broadcast(String, String)
 *//* ww  w.j a va 2 s  .c  o m*/
public static void broadcast(final String permission, final String... mojangsons) {
    Validate.notEmpty(permission, "The 'permission' argument should not be null nor empty");
    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) {
        for (final Player player : Bukkit.getOnlinePlayers()) {
            if (player.hasPermission(permission)) {
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
                        "tellraw " + player.getName() + ' ' + mojangson);
            }
        }
    }
}

From source file:com.opengamma.financial.convention.StubCalculator.java

/**
 * Calculates the end stub type from a schedule, number of payments per year and the end of month flag.
 * <p>/*from w ww  .ja va  2  s . c  om*/
 * The {@code DateProvider[]} argument allows callers to pass in arrays of any class
 * that implements {@code DateProvider}, such as {@code LocalDate[]}.
 * 
 * @param schedule  the schedule, at least size 2, not null
 * @param paymentsPerYear  the number of payments per year, one, two, three, four, six or twelve
 * @param isEndOfMonthConvention  whether to use end of month rules
 * @return the stub type, not null
 */
public static StubType getEndStubType(final LocalDate[] schedule, final double paymentsPerYear,
        final boolean isEndOfMonthConvention) {
    Validate.notNull(schedule, "schedule");
    Validate.noNullElements(schedule, "schedule");
    Validate.isTrue(paymentsPerYear > 0);
    Validate.isTrue(12 % paymentsPerYear == 0);

    final int months = (int) (12 / paymentsPerYear);
    final int n = schedule.length;
    final LocalDate first = schedule[n - 2];
    final LocalDate second = schedule[n - 1];
    LocalDate date;
    if (isEndOfMonthConvention && first.equals(first.with(lastDayOfMonth()))) {
        date = first.plusMonths(months);
        date = date.with(lastDayOfMonth());
    } else {
        date = first.plusMonths(months);
    }
    if (date.equals(second)) {
        return StubType.NONE;
    }
    if (date.isAfter(second)) {
        return StubType.SHORT_END;
    }
    return StubType.LONG_END;
}

From source file:me.st28.flexseries.flexcore.command.FlexCommand.java

/**
 * Instantiates a FlexCommand that is a base command for a plugin.
 *//*from  w ww.  j  ava 2 s. c  om*/
public FlexCommand(T plugin, String label, List<CommandArgument> arguments, FlexCommandSettings settings) {
    Validate.notNull(plugin, "Plugin cannot be null.");
    Validate.notNull(label, "Label cannot be null.");

    PluginCommand pluginCommand = plugin.getCommand(label);
    if (pluginCommand == null) {
        throw new IllegalArgumentException(
                "Command '" + label + "' is not a registered command for plugin '" + plugin.getName() + "'");
    }

    this.plugin = plugin;
    this.labels.add(label.toLowerCase());
    this.labels.addAll(pluginCommand.getAliases());
    this.parent = null;
    if (arguments != null) {
        Validate.noNullElements(arguments, "Arguments list cannot contain any null arguments.");
        this.arguments.addAll(arguments);
    }

    if (settings == null) {
        this.settings = new FlexCommandSettings();
    } else {
        this.settings = settings;
    }

    if (pluginCommand.getDescription() != null) {
        this.settings.description(pluginCommand.getDescription());
    }
}

From source file:com.opengamma.financial.convention.daycount.AccruedInterestCalculator.java

/**
 * Calculates the accrued interest for a {@code ZonedDateTime}.
 * //from   www  .ja  v a 2 s.c om
 * @param dayCount  the day count convention, not null
 * @param settlementDate  the settlement date, not null
 * @param nominalDates  the nominalDates, not null, no null elements
 * @param coupon  the coupon value
 * @param paymentsPerYear  the number of payments per year, one, two, three, four, six or twelve
 * @param isEndOfMonthConvention  whether to use end of month rules
 * @param exDividendDays the number of ex-dividend days
 * @param index The index of the previous coupon in the nominalDates array
 * @param calendar The working day calendar to be used in calculating ex-dividend dates, not null
 * @return the accrued interest
 */
public static double getAccruedInterest(final DayCount dayCount, final ZonedDateTime settlementDate,
        final ZonedDateTime[] nominalDates, final double coupon, final double paymentsPerYear,
        final boolean isEndOfMonthConvention, final int exDividendDays, final int index,
        final Calendar calendar) {
    Validate.notNull(dayCount, "day-count");
    Validate.notNull(settlementDate, "date");
    Validate.noNullElements(nominalDates, "nominalDates");
    Validate.notNull(calendar, "calendar");
    Validate.isTrue(paymentsPerYear > 0);
    Validate.isTrue(exDividendDays >= 0);
    final int length = nominalDates.length;
    Validate.isTrue(index >= 0 && index < length);
    final double accruedInterest = getAccruedInterest(dayCount, index, length, nominalDates[index],
            settlementDate, nominalDates[index + 1], coupon, paymentsPerYear, isEndOfMonthConvention);
    ZonedDateTime exDividendDate = nominalDates[index + 1];
    for (int i = 0; i < exDividendDays; i++) {
        while (!calendar.isWorkingDay(exDividendDate.toLocalDate())) {
            exDividendDate = exDividendDate.minusDays(1);
        }
        exDividendDate = exDividendDate.minusDays(1);
    }
    if (exDividendDays != 0 && exDividendDate.isBefore(settlementDate)) {
        return accruedInterest - coupon;
    }
    return accruedInterest;
}

From source file:com.commsen.jwebthumb.WebThumbService.java

/**
 * Sends thumbnail requests to webthumb site. For more information see webthumb's request API:
 * http://webthumb.bluga.net/apidoc#request
 * //from   www.ja v a 2s .  co  m
 * @param webThumbRequests list of objects containing the request parameters
 * @return list of jobs
 * @throws WebThumbException if the request fails for whatever reason
 */
public List<WebThumbJob> sendRequest(List<WebThumbRequest> webThumbRequests) throws WebThumbException {
    Validate.notNull(webThumbRequests, "webThumbRequests is null!");
    Validate.notEmpty(webThumbRequests, "webThumbRequests is empty!");
    Validate.noNullElements(webThumbRequests, "webThumbRequests contains null elements!");

    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine("Attempting to send webThumbRequests: " + webThumbRequests);
    }
    WebThumb webThumb = new WebThumb(apikey, webThumbRequests);
    HttpURLConnection connection = sendWebThumb(webThumb);

    try {
        WebThumbResponse webThumbResponse = SimpleXmlSerializer.parseResponse(connection.getInputStream(),
                WebThumbResponse.class);
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Response processed! Returning: " + webThumbResponse.getJobs());
        }
        if (webThumbResponse.getError() != null) {
            throw new WebThumbException("Server side error: " + webThumbResponse.getError().getValue());
        }
        if (webThumbResponse.getErrors() != null) {
            for (WebThumbError webThumbError : webThumbResponse.getErrors()) {
                LOGGER.warning("Server side error: " + webThumbError);
            }
        }
        return webThumbResponse.getJobs();
    } catch (IOException e) {
        throw new WebThumbException("failed to send request", e);
    }
}

From source file:com.afterkraft.kraftrpg.bukkit.events.entity.damage.BukkitInsentientDamageEvent.java

public BukkitInsentientDamageEvent(final Insentient defender, final EntityDamageEvent event,
        final Map<DamageType, Double> customModifiers, final boolean isVaryingEnabled) {
    super(defender);
    Validate.notNull(event, "Cannot associate to a null EntityDamageEvent!");
    Validate.notNull(customModifiers, "Cannot have a null modifier map!");
    Validate.isTrue(!customModifiers.isEmpty(), "Cannot have an empty modifier map!");
    Validate.noNullElements(customModifiers.values(), "Cannot have null modifiers!");
    this.defender = defender;
    this.originals = new HashMap<DamageType, Double>(customModifiers);
    this.modifiers = customModifiers;
    this.isVaryingDamageEnabled = isVaryingEnabled;
    this.cause = VanillaDamageCause.valueOf(event.getCause().name());
    this.bukkitEvent = event;
}

From source file:me.st28.flexseries.flexcore.command.FlexCommand.java

/**
 * @param plugin the plugin that owns the command.
 * @param label the main label of the command
 * @param arguments The arguments for the command. Used to build usage messages for FlexCommands.
 *//*from   w  ww  .j  a v  a2 s  .c om*/
public FlexCommand(T plugin, String label, FlexCommand<T> parent, List<CommandArgument> arguments,
        FlexCommandSettings settings) {
    Validate.notNull(plugin, "Plugin cannot be null.");
    Validate.notNull(label, "Label cannot be null.");

    this.plugin = plugin;
    this.labels.add(label.toLowerCase());
    this.parent = parent;
    if (arguments != null) {
        Validate.noNullElements(arguments, "Arguments list cannot contain any null arguments.");
        this.arguments.addAll(arguments);
    }

    if (settings == null) {
        this.settings = new FlexCommandSettings();
    } else {
        this.settings = settings;
    }
}

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

/**
 * Sends the provided {@link Message Message(s)} to the provided
 * {@link Player}./*from w  w w.  ja  v  a2 s . c o m*/
 *
 * @param to       the player to whom we will send the message(s)
 * @param messages the message(s) to send
 *
 * @see Player#sendMessage(String)
 */
public static void sendMessage(final Player to, final Message... messages) {
    Validate.notNull(to, "The 'to' argument should not be null");
    Validate.notEmpty(messages, "Please provide at least one Message");
    Validate.noNullElements(messages, "The 'messages' argument should not contain null values");
    final String[] mojangsons = new String[messages.length];
    for (int i = 0; i < messages.length; i++) {
        mojangsons[i] = Chat.toMojangson(messages[i]);
    }
    Chat.sendMessage(to, mojangsons);
}