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:net.jodah.failsafe.internal.actions.DoThrowAction.java

DoThrowAction(ActionRegistry<R>.Expectation expectation, String name, Throwable... throwables) {
    super(expectation, name);
    Validate.notNull(throwables, "invalid null throwables");
    Validate.noNullElements(throwables, "invalid null throwable");
    this.arguments = Arrays.asList(throwables);
    this.throwables = Stream.of(throwables).collect(Collectors.toCollection(LinkedList::new));
    this.current = Collections.synchronizedList(new LinkedList<>(this.throwables));
}

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

public HolidaySourceCalendarAdapter(final HolidaySource holidaySource, final Region[] regions) {
    Validate.notNull(regions, "Region set is null");
    Validate.notNull(holidaySource, "holiday source is null");
    Validate.noNullElements(regions, "Region set has null elements");
    _holidaySource = holidaySource;//from   ww  w.  j av a2s.c o m
    _regions = Sets.newHashSet(regions);
    _type = HolidayType.BANK;
}

From source file:com.galeoconsulting.leonardinius.api.impl.ChainingClassLoader.java

public ChainingClassLoader(ClassLoader... classLoaders) {
    Validate.noNullElements(classLoaders, "ClassLoader arguments cannot be null");
    this.classLoaders = ImmutableList
            .of(new LinkedHashSet<ClassLoader>(Arrays.asList(classLoaders)).toArray(new ClassLoader[0]));
}

From source file:com.opengamma.analytics.financial.var.parametric.VaRCovarianceMatrixCalculator.java

@Override
public Map<Integer, ParametricVaRDataBundle> evaluate(final SensitivityAndReturnDataBundle... data) {
    Validate.notNull(data, "data");
    Validate.notEmpty(data, "data");
    Validate.noNullElements(data, "data");
    List<String> firstOrderNames = null;
    final List<Double> firstOrderSensitivity = new ArrayList<>();
    final List<DoubleTimeSeries<?>> firstOrderTimeSeries = new ArrayList<>();
    final List<DoubleTimeSeries<?>> secondOrderTimeSeries = new ArrayList<>();
    List<String> secondOrderNames = null;
    for (final SensitivityAndReturnDataBundle dataForSensitivity : data) {
        final Sensitivity<?> sensitivity = dataForSensitivity.getSensitivity();
        final String identifier = sensitivity.getIdentifier();
        if (sensitivity.getOrder() == 1) {
            final UnderlyingType type = sensitivity.getUnderlyingTypes().get(0);
            final String name = identifier + "_" + type;
            if (firstOrderNames == null) {
                firstOrderNames = new ArrayList<>();
            }// w w  w  .  j av a2  s.  c  o m
            if (!firstOrderNames.contains(name)) {
                firstOrderNames.add(name);
                firstOrderSensitivity.add(dataForSensitivity.getValue());
                firstOrderTimeSeries.add(dataForSensitivity.getReturnTimeSeriesForUnderlying(type));
            } else {
                final int index = firstOrderNames.indexOf(name);
                firstOrderSensitivity.set(index,
                        firstOrderSensitivity.get(index) + dataForSensitivity.getValue());
            }
        } else if (sensitivity.getOrder() == 2) {
            if (secondOrderNames == null) {
                secondOrderNames = new ArrayList<>();
            }
            if (sensitivity.getUnderlying() instanceof NthOrderUnderlying) {
                final UnderlyingType type = sensitivity.getUnderlyingTypes().get(0);
                final String name = identifier + "_" + type;
                if (!secondOrderNames.contains(name)) {
                    secondOrderNames.add(name);
                    secondOrderTimeSeries.add(dataForSensitivity.getReturnTimeSeriesForUnderlying(type));
                }
            } else if (sensitivity.getUnderlying() instanceof MixedOrderUnderlying) {
                final UnderlyingType type1 = sensitivity.getUnderlyingTypes().get(0);
                final UnderlyingType type2 = sensitivity.getUnderlyingTypes().get(1);
                final String name1 = identifier + "_" + type1;
                final String name2 = identifier + "_" + type2;
                if (!secondOrderNames.contains(name1)) {
                    secondOrderNames.add(name1);
                    secondOrderTimeSeries.add(dataForSensitivity.getReturnTimeSeriesForUnderlying(type1));
                }
                if (!secondOrderNames.contains(name2)) {
                    secondOrderNames.add(name2);
                    secondOrderTimeSeries.add(dataForSensitivity.getReturnTimeSeriesForUnderlying(type2));
                }
            }
        } else {
            throw new IllegalArgumentException("Can only handle first and second order sensitivities");
        }
    }
    final Map<Integer, ParametricVaRDataBundle> result = new HashMap<>();
    DoubleMatrix2D firstOrderCovarianceMatrix = null;
    DoubleMatrix1D firstOrderSensitivityMatrix = null;
    DoubleMatrix2D secondOrderCovarianceMatrix = null;
    DoubleMatrix2D secondOrderSensitivityMatrix = null;
    if (firstOrderNames != null) {
        firstOrderCovarianceMatrix = _calculator.evaluate(firstOrderTimeSeries.toArray(EMPTY));
        firstOrderSensitivityMatrix = new DoubleMatrix1D(
                firstOrderSensitivity.toArray(new Double[firstOrderSensitivity.size()]));
        result.put(1, new ParametricVaRDataBundle(firstOrderNames, firstOrderSensitivityMatrix,
                firstOrderCovarianceMatrix, 1));
    }
    if (secondOrderNames != null) {
        final int n = secondOrderNames.size();
        final double[][] secondOrderSensitivities = new double[n][n];
        for (final SensitivityAndReturnDataBundle bundle : data) {
            final Sensitivity<?> sensitivity = bundle.getSensitivity();
            final String identifier = sensitivity.getIdentifier();
            if (sensitivity.getOrder() == 2) {
                if (sensitivity.getUnderlying() instanceof NthOrderUnderlying) {
                    final UnderlyingType type = sensitivity.getUnderlyingTypes().get(0);
                    final String name = identifier + "_" + type;
                    final int index = secondOrderNames.indexOf(name);
                    secondOrderSensitivities[index][index] += bundle.getValue();
                } else if (sensitivity.getUnderlying() instanceof MixedOrderUnderlying) {
                    final UnderlyingType type1 = sensitivity.getUnderlyingTypes().get(0);
                    final UnderlyingType type2 = sensitivity.getUnderlyingTypes().get(1);
                    final String name1 = identifier + "_" + type1;
                    final String name2 = identifier + "_" + type2;
                    final int index1 = secondOrderNames.indexOf(name1);
                    final int index2 = secondOrderNames.indexOf(name2);
                    secondOrderSensitivities[index1][index2] += bundle.getValue();
                    secondOrderSensitivities[index2][index1] = secondOrderSensitivities[index1][index2];
                }
            }
        }
        secondOrderCovarianceMatrix = _calculator.evaluate(secondOrderTimeSeries.toArray(EMPTY));
        secondOrderSensitivityMatrix = new DoubleMatrix2D(secondOrderSensitivities);
        result.put(2, new ParametricVaRDataBundle(secondOrderNames, secondOrderSensitivityMatrix,
                secondOrderCovarianceMatrix, 2));
    }
    return result;
}

From source file:net.daboross.bukkitdev.skywars.game.ArenaGame.java

public ArenaGame(SkyArena arena, int id, UUID[] originalPlayers) {
    Validate.notNull(arena, "Arena cannot be null");
    Validate.noNullElements(originalPlayers, "No players can be null");
    this.arena = arena;
    this.id = id;
    this.alivePlayers = new ArrayList<>(Arrays.asList(originalPlayers));
    this.deadPlayers = new ArrayList<>(originalPlayers.length);
    int maxTeamNumber = arena.getNumTeams();
    if (arena.getTeamSize() > 1) { // if teams are enabled (there is more than one person per team)
        numTeams = maxTeamNumber > alivePlayers.size() ? alivePlayers.size() : maxTeamNumber;

        this.teamsEnabled = true;
        this.playerTeams = new HashMap<>(alivePlayers.size());
        this.teams = new Team[numTeams];
        for (int i = 0; i < numTeams; i++) {
            teams[i] = new Team(i, String.valueOf(i + 1));
        }//from   ww  w .j  a va2 s.c o  m
        int nextTeam = 0;
        for (UUID uuid : alivePlayers) {
            playerTeams.put(uuid, nextTeam);
            this.teams[nextTeam].addPlayer(uuid);
            nextTeam += 1;
            if (nextTeam >= numTeams) {
                nextTeam = 0;
            }
        }
    } else {
        playerTeams = null;
        teams = null;
        teamsEnabled = false;
        numTeams = -1;
    }
}

From source file:net.jodah.failsafe.internal.actions.DoThrowAction.java

DoThrowAction(ActionRegistry<R>.Expectation expectation, String name,
        Class<? extends Throwable>... throwables) {
    super(expectation, name);
    Validate.notNull(throwables, "invalid null throwables");
    Validate.noNullElements(throwables, "invalid null throwable");
    this.arguments = Arrays.asList(throwables);
    this.throwables = Stream.of(throwables).map(t -> ThrowableSupport.instantiate(controller, t))
            .collect(Collectors.toCollection(LinkedList::new));
    this.current = Collections.synchronizedList(new LinkedList<>(this.throwables));
}

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

/**
 * Sends the provided Mojangson String(s) to the provided
 * {@link Player}.//from w w w.ja  va  2 s . c o 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:net.femtoparsec.jwhois.gui.JWhoIsGUIModel.java

public JWhoIsGUIModel(GenericWhoIs<S> whoIs, JResultGUIFactory<S> jResultGUIFactory,
        Set<Source> proposedSources, Set<Source> selectedSources) {
    Validate.notNull(whoIs, "whoIs");
    Validate.notNull(jResultGUIFactory, "jResultGUIFactory");
    Validate.noNullElements(proposedSources, "proposedSources");
    Validate.notEmpty(proposedSources, "proposedSources");

    Validate.noNullElements(selectedSources, "selectedSources");

    this.whoIs = whoIs;
    this.proxy = null;
    this.jResultGUIFactory = jResultGUIFactory;
    this.preferredFormat = Format.RPSL;
    this.sources = new HashSet<Source>(proposedSources);
    this.selectedSources = new HashSet<Source>(CollectionUtils.intersection(proposedSources, selectedSources));
}

From source file:com.opengamma.analytics.financial.riskfactor.TaylorExpansionMultiplierCalculator.java

public static DoubleTimeSeries<?> getTimeSeries(final Map<UnderlyingType, DoubleTimeSeries<?>> underlyingData,
        final Underlying underlying) {
    Validate.notNull(underlying, "underlying");
    Validate.notNull(underlyingData, "underlying data");
    Validate.notEmpty(underlyingData, "underlying data");
    Validate.noNullElements(underlyingData.keySet(), "underlying data keys");
    Validate.noNullElements(underlyingData.values(), "underlying data values");
    if (underlying instanceof NthOrderUnderlying) {
        final NthOrderUnderlying nthOrder = (NthOrderUnderlying) underlying;
        final int n = nthOrder.getOrder();
        if (n == 0) {
            throw new UnsupportedOperationException();
        }//from   ww w  .  j  a  v  a  2 s. c  o  m
        final UnderlyingType type = nthOrder.getUnderlying();
        Validate.isTrue(underlyingData.containsKey(type));
        DoubleTimeSeries<?> ts = underlyingData.get(type);
        ts = ts.power(n);
        return ts.multiply(getMultiplier(underlying));
    } else if (underlying instanceof MixedOrderUnderlying) {
        final MixedOrderUnderlying mixedOrder = (MixedOrderUnderlying) underlying;
        DoubleTimeSeries<?> result = null;
        DoubleTimeSeries<?> multiplier = null;
        int size = 0;
        for (final NthOrderUnderlying underlyingOrder : mixedOrder.getUnderlyingOrders()) {
            if (result == null) {
                result = getTimeSeries(underlyingData, underlyingOrder);
                size = result.size();
            } else {
                multiplier = getTimeSeries(underlyingData, underlyingOrder);
                if (multiplier.size() != size) {
                    throw new IllegalArgumentException("Time series in map were not the same length");
                }
                result = result.multiply(multiplier);
                if (result.size() != size) {
                    throw new IllegalArgumentException("Time series in map did not contain the same times");
                }
            }
        }
        return result;
    }
    throw new IllegalArgumentException(
            "Order was neither NthOrderUnderlying nor MixedOrderUnderlying: have " + underlying.getClass());
}

From source file:net.femtoparsec.jwhois.impl.AbstractProvider.java

/**
 * Create a provider/*  w  ww . j a v  a2s  .c  o  m*/
 * @param name the name of the provider
 * @param resultFormat the format of the WhoIs results return by this provider
 * @param handleProxy true if the provider can handle proxy
 * @param providedSources the list of sources this provider can provide
 */
public AbstractProvider(String name, Format resultFormat, boolean handleProxy, Source... providedSources) {
    Validate.noNullElements(providedSources, "providedSources");

    Set<Source> set = new HashSet<Source>();
    Collections.addAll(set, providedSources);

    this.handleProxy = handleProxy;
    this.providedSources = set;
    this.resultFormat = resultFormat;
    this.name = name;
}