Java List Contain containsOnly(List elements, Class clazz)

Here you can find the source of containsOnly(List elements, Class clazz)

Description

contains Only

License

Open Source License

Declaration

public static boolean containsOnly(List elements, Class clazz) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from   w ww . j  a  v  a2 s .co  m*/
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Zend Technologies
 *******************************************************************************/

import java.util.Iterator;
import java.util.List;

public class Main {
    public static boolean containsOnly(List elements, Class clazz) {
        if (elements.isEmpty())
            return false;
        for (Iterator iter = elements.iterator(); iter.hasNext();) {
            // if (!clazz.isAssignableFrom(iter.next().getClass()))
            if (!clazz.isAssignableFrom(iter.next().getClass()))
                return false;
        }
        return true;
    }
}

Related

  1. containsItems(List smallerList, List largerList)
  2. containsNonPositives(List vals)
  3. containsNull(List list)
  4. containsNullElement(List source)
  5. containsOneEqualElem(List first, List second)
  6. containsOnlyEmptyValues(List list)
  7. containsOnlyNulls(List list)
  8. containsOnlySequentialNumbers(List values)
  9. containsOrIsEmpty(List list, Object item)