Example usage for java.util List contains

List of usage examples for java.util List contains

Introduction

In this page you can find the example usage for java.util List contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:Main.java

public static List getDifferenceOfTwoList(List originList, List targetList) {
    List diff = new ArrayList();
    for (Iterator it = originList.iterator(); it.hasNext();) {
        Object obj = it.next();//from   w  ww  .  j  a  v  a 2s . co  m
        if (!targetList.contains(obj)) {
            diff.add(obj);
        }
    }
    return diff;
}

From source file:Main.java

public static <T> List<T> intersection(final List<T> list1, final List<T> list2) {
    final List<T> result = new ArrayList<T>();

    for (final T e : list1) {
        if (list2.contains(e)) {
            result.add(e);/*w ww .ja v  a  2  s. co  m*/
        }
    }

    return result;
}

From source file:Main.java

public static String findBestFlashModeMatch(Camera.Parameters params, String... modes) {
    String match = null;/*  w  w  w.  j a v  a2s .c om*/

    List<String> flashModes = params.getSupportedFlashModes();

    if (flashModes != null) {
        for (String mode : modes) {
            if (flashModes.contains(mode)) {
                match = mode;
                break;
            }
        }
    }

    return (match);
}

From source file:Main.java

/**
 * Adds the element parameter only if it isn't inside yet.
 *
 * @param aList/*from  w ww  . ja v  a  2  s.c om*/
 *         The {@link List} to fill.
 * @param element
 *         The element to add to the aList parameter.
 */
public static void addWhenNecessary(List aList, Object element) {
    if (aList == null) {
        aList = new ArrayList();
        aList.add(element);
        return;
    }

    if (!aList.contains(element)) {
        aList.add(element);
    }
}

From source file:ReflectionHelper.java

/**
 * Checks whether the specified class parameter is an instance of a collection class.
 *
 * @param clazz <code>Class</code> to check.
 *
 * @return <code>true</code> is <code>clazz</code> is instance of a collection class, <code>false</code> otherwise.
 *//* ww w  . ja va2  s  . c o m*/
private static boolean isIterableClass(Class<?> clazz) {
    List<Class<?>> classes = new ArrayList<Class<?>>();
    computeClassHierarchy(clazz, classes);
    return classes.contains(Iterable.class);
}

From source file:Main.java

public static List<Integer> randomChoose(int total, int selectedCount) {
    Random random = new Random();
    List<Integer> resultList = new ArrayList<Integer>();
    while (resultList.size() < selectedCount) {
        Integer randomNum = random.nextInt(total) + 1;
        if (!resultList.contains(randomNum)) {
            resultList.add(randomNum);//from   w w w  . j  av  a 2  s. co  m
        }
    }
    return resultList;
}

From source file:com.baifendian.swordfish.execserver.utils.EnvHelper.java

/**
 * //from w w  w .ja va 2  s .c om
 *
 * @param execLocalPath
 * @param proxyUser
 * @param logger
 * @throws IOException
 */
public static void workDirAndUserCreate(String execLocalPath, String proxyUser, Logger logger)
        throws IOException {
    // , 
    File execLocalPathFile = new File(execLocalPath);

    if (execLocalPathFile.exists()) {
        FileUtils.forceDelete(execLocalPathFile);
    }

    // 
    FileUtils.forceMkdir(execLocalPathFile);

    // proxyUser ?, ?
    List<String> osUserList = OsUtil.getUserList();

    // ?, 
    if (!osUserList.contains(proxyUser)) {
        String userGroup = OsUtil.getGroup();
        if (StringUtils.isNotEmpty(userGroup)) {
            logger.info("create os user:{}", proxyUser);

            String cmd = String.format("sudo useradd -g %s %s", userGroup, proxyUser);

            logger.info("exec cmd: {}", cmd);

            OsUtil.exeCmd(cmd);
        }
    }
}

From source file:Main.java

public static <T> void add(final List<T> toList, final List<T> fromList) {

    if (toList == null || fromList == null) {
        return;//from  w w  w .  ja  va  2  s.c o m
    }

    for (T t : fromList) {
        if (!toList.contains(t)) {
            toList.add(t);
        }
    }
}

From source file:com.adaptris.core.services.jdbc.JdbcBatchingDataCaptureService.java

protected static long rowsUpdated(int[] rc) throws SQLException {
    List<Integer> result = Arrays.asList(ArrayUtils.toObject(rc));
    if (result.contains(Statement.EXECUTE_FAILED)) {
        throw new SQLException("Batch Execution Failed.");
    }//  ww  w .  j av  a 2 s . co  m
    return result.stream().filter(e -> !(e == Statement.SUCCESS_NO_INFO)).mapToLong(i -> i).sum();
}

From source file:Main.java

public static <T extends Comparable<? super T>> List<List<T>> getAllCombinations(final List<T> pList,
        final int pSize) {
    assert (pSize < pList.size());
    final List<List<T>> result = new ArrayList<List<T>>();

    if (pSize == 0) {
        result.add(new ArrayList<T>());
        return result;
    }/*from ww  w  .  j  a  v a2s  .com*/

    final List<List<T>> combinations = getAllCombinations(pList, pSize - 1);
    for (final List<T> combination : combinations) {
        for (final T element : pList) {
            if (combination.contains(element)) {
                continue;
            }

            final List<T> list = new ArrayList<T>();
            list.addAll(combination);

            if (list.contains(element)) {
                continue;
            }

            list.add(element);
            Collections.sort(list);

            if (result.contains(list)) {
                continue;
            }

            result.add(list);
        }
    }

    return result;
}