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

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

Introduction

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

Prototype

public static void allElementsOfType(Collection collection, Class clazz) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the argument collection is null or has elements that are not of type clazz or a subclass.

Usage

From source file:hudson.plugins.clearcase.ucm.UcmSaveChangeLogAction.java

public void saveChangeLog(File changeLogFile, List<? extends Entry> entries)
        throws IOException, InterruptedException {
    Validate.allElementsOfType(entries, UcmActivity.class);
    @SuppressWarnings("unchecked")
    List<UcmActivity> ucmEntries = (List<UcmActivity>) entries;
    FileOutputStream fileOutputStream = new FileOutputStream(changeLogFile);
    UcmChangeLogSet.saveToChangeLog(fileOutputStream, ucmEntries);
    fileOutputStream.close();/*w  ww .j a v  a2 s. c o  m*/
}

From source file:net.iglyduck.utils.sqlbuilder.TempTable.java

protected TempTable from(Object item) {
    Validate.notNull(item);/*  ww  w.  j a  v a2s .c  o  m*/
    Validate.isTrue(item instanceof WrapTable || item instanceof JoinUnit);

    if (froms == null) {
        froms = new ArrayList<Object>();
    }

    if (item instanceof WrapTable) {
        Validate.allElementsOfType(froms, WrapTable.class);
    } else if (item instanceof JoinUnit) {
        Validate.isTrue(froms.isEmpty());
    }

    froms.add(item);
    return this;
}

From source file:org.eclipse.jubula.communication.Communicator.java

/**
 * Use this constructor if the instance should act as a server. run() will start a thread accepting connections.
 * //from  w  w  w  .  j a  v  a  2 s  .  c  om
 * @param port the port to use, must not be negative, if port is zero, any
 *             free port will be used, query the opened port with getLocalPort()
 * @param cl class loader to get the command object
 * @param responseToInitializer Mapping from client type to connection 
 *                              initializer. Connections initiated by client
 *                              types not contained within this mapping will
 *                              be initialized in the default manner. May
 *                              be <code>null</code>.
 * @throws AssertException if port is negative or factory is null.
 * @throws IOException if the given port can not used
 * @throws SecurityException if the security manager does not allow connections.
 */
public Communicator(int port, ClassLoader cl, Map responseToInitializer)
        throws IOException, SecurityException, AssertException {

    super();
    // check parameter
    Assert.verify(port >= 0, "port must not be negativ"); //$NON-NLS-1$
    Assert.verify(cl != null, "no class loader for creation of command " + //$NON-NLS-1$
            "object available"); //$NON-NLS-1$
    // create a server socket
    m_serverSocket = new DefaultServerSocket(port);
    m_serverSocket.setSoTimeout(0);

    // store the opened socket to LOCAL Port
    m_localPort = m_serverSocket.getLocalPort();
    m_classLoader = cl;

    m_responseToInitializer = new HashMap();
    if (responseToInitializer != null) {
        m_responseToInitializer.putAll(responseToInitializer);
    }

    Validate.allElementsOfType(m_responseToInitializer.keySet(), String.class);
    Validate.allElementsOfType(m_responseToInitializer.values(), IConnectionInitializer.class);

    init();
}

From source file:org.eclipse.jubula.communication.internal.Communicator.java

/**
 * Use this constructor if the instance should act as a server. run() will start a thread accepting connections.
 * /*from  w w w . java  2  s.  co  m*/
 * @param port the port to use, must not be negative, if port is zero, any
 *             free port will be used, query the opened port with getLocalPort()
 * @param cl class loader to get the command object
 * @param responseToInitializer Mapping from client type to connection 
 *                              initializer. Connections initiated by client
 *                              types not contained within this mapping will
 *                              be initialized in the default manner. May
 *                              be <code>null</code>.
 * @throws AssertException if port is negative or factory is null.
 * @throws IOException if the given port can not used
 * @throws SecurityException if the security manager does not allow connections.
 */
public Communicator(int port, ClassLoader cl, Map responseToInitializer)
        throws IOException, SecurityException, AssertException {

    super();
    // check parameter
    Assert.verify(port >= 0, "port must not be negativ"); //$NON-NLS-1$
    Assert.verify(cl != null, "no class loader for creation of command " + //$NON-NLS-1$
            "object available"); //$NON-NLS-1$
    // create a server socket
    m_serverSocket = new DefaultServerSocket(port);
    m_serverSocket.setSoTimeout(INFINITE);

    // store the opened socket to LOCAL Port
    m_localPort = m_serverSocket.getLocalPort();
    m_classLoader = cl;

    m_responseToInitializer = new HashMap();
    if (responseToInitializer != null) {
        m_responseToInitializer.putAll(responseToInitializer);
    }

    Validate.allElementsOfType(m_responseToInitializer.keySet(), String.class);
    Validate.allElementsOfType(m_responseToInitializer.values(), IConnectionInitializer.class);

    init();
}

From source file:org.eclipse.jubula.tools.internal.xml.businessmodell.CompSystem.java

/**
 * //  w ww .j  av a  2s .  c  om
 * @param componentClassName The FQN (fully qualified name) of the 
 *                           supported class for the Component. 
 * @param availableComponents Components through which to search.
 * @return The Component from the provided collection that supports the
 *         given class name, or <code>null</code> if no such Component
 *         is found.
 */
public static String getComponentType(String componentClassName, Collection<Component> availableComponents) {

    Validate.notNull(componentClassName);
    Validate.allElementsOfType(availableComponents, Component.class);

    for (Component currentComp : availableComponents) {
        if (currentComp instanceof ConcreteComponent
                && componentClassName.equals(((ConcreteComponent) currentComp).getComponentClass().getName())) {

            return currentComp.getType();
        }
    }

    return null;
}

From source file:org.eclipse.jubula.tools.xml.businessmodell.CompSystem.java

/**
 * /*from w ww .  ja v a  2  s.c om*/
 * @param componentClassName The FQN (fully qualified name) of the 
 *                           supported class for the Component. 
 * @param availableComponents Components through which to search.
 * @return The Component from the provided collection that supports the
 *         given class name, or <code>null</code> if no such Component
 *         is found.
 */
public static String getComponentType(String componentClassName, Collection availableComponents) {

    Validate.notNull(componentClassName);
    Validate.allElementsOfType(availableComponents, Component.class);

    for (Iterator compIter = availableComponents.iterator(); compIter.hasNext();) {
        Component currentComp = (Component) compIter.next();
        if (currentComp instanceof ConcreteComponent
                && componentClassName.equals(((ConcreteComponent) currentComp).getComponentClass())) {

            return currentComp.getType();
        }
    }

    return null;
}