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:com.github.dactiv.fear.service.commons.Configs.java

/**
 * ???/*from ww  w  .j a va  2 s . c o m*/
 *
 * @param code   ?
 * @param ignore ?
 *
 * @return key value ? Map ?
 */
public static List<Map<String, Object>> find(String code, List<String> ignore) {
    List<Map<String, Object>> dataDictionaries = configService.getDataDictionaries(code);

    for (Map<String, Object> data : dataDictionaries) {

        String value = Casts.cast(data.get("value"), String.class);

        if (ignore != null && !ignore.contains(value)) {
            String type = data.get("type").toString();
            data.put("value", Casts.cast(value, type));
        }
    }

    return dataDictionaries;
}

From source file:Main.java

public static boolean cheakByPackageName(Context context, String packageName, String sdkVersion) {
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    List<String> pName = new ArrayList<String>();
    List<String> versions = new ArrayList<String>();

    if (pinfo != null) {
        for (int i = 0; i < pinfo.size(); i++) {
            String pn = pinfo.get(i).packageName;
            String appVersion = pinfo.get(i).versionName;
            pName.add(pn);/*ww w.  ja v a 2  s.  c o m*/
            versions.add(appVersion);
        }
    }

    if (!pName.contains(packageName)) {
        return false;
    } else {
        if (!versions.contains(sdkVersion)) {
            return false;
        }

    }
    return true;
}

From source file:com.googlecode.jsonplugin.JSONUtil.java

/**
 * Recursive method to visit all the interfaces of a class (and its superclasses and super-interfaces) if they
 * haven't already been visited./* ww  w. j a v  a2s .c om*/
 * <p/>
 * Always visits itself if it hasn't already been visited
 *
 * @param thisClass      the current class to visit (if not already done so)
 * @param classesVisited classes already visited
 * @param visitor        this vistor is called for each class/interface encountered
 * @return true if recursion can continue, false if it should be aborted
 */
private static boolean visitUniqueInterfaces(Class thisClass, ClassVisitor visitor,
        List<Class> classesVisited) {
    boolean okayToContinue = true;

    if (!classesVisited.contains(thisClass)) {
        classesVisited.add(thisClass);
        okayToContinue = visitor.visit(thisClass);

        if (okayToContinue) {
            Class[] interfaces = thisClass.getInterfaces();
            int index = 0;
            while ((index < interfaces.length) && (okayToContinue)) {
                okayToContinue = visitUniqueInterfaces(interfaces[index++], visitor, classesVisited);
            }

            if (okayToContinue) {
                Class superClass = thisClass.getSuperclass();
                if ((superClass != null) && (!Object.class.equals(superClass))) {
                    okayToContinue = visitUniqueInterfaces(superClass, visitor, classesVisited);
                }
            }
        }
    }
    return okayToContinue;
}

From source file:com.dianping.lion.util.UrlUtils.java

public static List<String> getParameterNames(String url) {
    if (url == null) {
        throw new NullPointerException("Param[url] cannot be null.");
    }/* w  w w  . java2 s . c o m*/
    List<String> parameterNames = new ArrayList<String>();
    String queryString = StringUtils.substringAfter(url, "?");
    if (queryString != null) {
        String[] segments = StringUtils.split(queryString, "&");
        for (String segment : segments) {
            String param = StringUtils.substringBefore(segment, "=");
            if (!parameterNames.contains(param)) {
                parameterNames.add(param);
            }
        }
    }
    return parameterNames;
}

From source file:com.sonatype.security.ldap.api.DeepEqualsBuilder.java

private static void reflectionAppend(Object lhs, Object rhs, Class clazz, EqualsBuilder builder,
        boolean useTransients, String[] excludeFields) {
    while (clazz.getSuperclass() != null) {

        Field[] fields = clazz.getDeclaredFields();
        List excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.EMPTY_LIST;
        AccessibleObject.setAccessible(fields, true);
        for (int i = 0; i < fields.length && builder.isEquals(); i++) {
            Field f = fields[i];/*from w w w. jav  a 2  s . c o m*/
            if (!excludedFieldList.contains(f.getName()) && (f.getName().indexOf('$') == -1)
                    && (useTransients || !Modifier.isTransient(f.getModifiers()))
                    && (!Modifier.isStatic(f.getModifiers()))) {
                try {
                    Object lhsChild = f.get(lhs);
                    Object rhsChild = f.get(rhs);
                    Class testClass = getTestClass(lhsChild, rhsChild);
                    boolean hasEqualsMethod = classHasEqualsMethod(testClass);

                    if (testClass != null && !hasEqualsMethod) {
                        reflectionAppend(lhsChild, rhsChild, testClass, builder, useTransients, excludeFields);
                    } else {
                        builder.append(lhsChild, rhsChild);
                    }
                } catch (IllegalAccessException e) {
                    // this can't happen. Would get a Security exception instead
                    // throw a runtime exception in case the impossible happens.
                    throw new InternalError("Unexpected IllegalAccessException");
                }
            }
        }

        // now for the parent
        clazz = clazz.getSuperclass();
        reflectionAppend(lhs, rhs, clazz, builder, useTransients, excludeFields);
    }
}

From source file:Main.java

/**
 * Returns a List of Lists: all combinations of the elements of the given List.
 * @param maxCombinationSize combinations larger than this value are discarded
 * @param mandatoryItem an item that all returned combinations must contain,
 * or null to leave unspecified//w  w  w.  j ava 2  s . c om
 */
public static <E> List<List<E>> combinations(List<E> original, int maxCombinationSize, E mandatoryItem) {
    List<List<E>> combinations = new ArrayList<>();

    //Combinations are given by the bits of each binary number from 1 to 2^N
    for (int i = 1; i <= ((int) Math.pow(2, original.size()) - 1); i++) {
        List<E> combination = new ArrayList<>();

        for (int j = 0; j < original.size(); j++) {
            if ((i & (int) Math.pow(2, j)) > 0) {
                combination.add(original.get(j));
            }
        }

        if (combination.size() > maxCombinationSize) {
            continue;
        }

        if ((mandatoryItem != null) && !combination.contains(mandatoryItem)) {
            continue;
        }

        combinations.add(combination);
    }

    return combinations;
}

From source file:com.netcrest.pado.tools.pado.util.PadoShellUtil.java

/**
 * Returns a map of <grid-id, List<grid-path> entries extracted from the
 * specified full paths. Duplicate paths are ignored.
 * /*from   w  w w.  j a v a  2 s .  co m*/
 * @param padoShell
 *            PadoShell instance
 * @param fullPaths
 *            An array of full paths.
 * @return Always returns a non-null map.
 */
public final static Map<String, List<String>> getGridPathMap(PadoShell padoShell, String[] fullPaths) {
    Map<String, List<String>> map = new HashMap<String, List<String>>(fullPaths.length, 1f);
    if (fullPaths != null) {
        for (String fullPath : fullPaths) {
            String gridId = SharedCache.getSharedCache().getGridId(fullPath);
            String gridPath = padoShell.getGridPathFromFullPath(fullPath);
            List<String> list = map.get(gridId);
            if (list == null) {
                list = new ArrayList<String>(fullPaths.length);
                map.put(gridId, list);
            }
            if (list.contains(gridPath) == false) {
                list.add(gridPath);
            }
            PadoShell.println("   " + gridId + ": " + gridPath);
        }
    }
    return map;
}

From source file:org.apache.servicemix.camel.nmr.ws.addressing.WSAddressingTest.java

/**
 * Verify presence of expected MAP headers.
 *
 * @param wsaHeaders a list of the wsa:* headers present in the SOAP
 * message//from   w w w  .j  ava 2 s.c om
 * @param parial true if partial response
 * @return null if all expected headers present, otherwise an error string.
 */
protected static String verifyHeaders(List<String> wsaHeaders, boolean partial, boolean requestLeg) {

    String ret = null;
    if (!wsaHeaders.contains(Names.WSA_MESSAGEID_NAME)) {
        ret = "expected MessageID header";
    }
    if (!wsaHeaders.contains(Names.WSA_TO_NAME)) {
        ret = "expected To header";
    }

    if (!(wsaHeaders.contains(Names.WSA_REPLYTO_NAME) || wsaHeaders.contains(Names.WSA_RELATESTO_NAME))) {
        ret = "expected ReplyTo or RelatesTo header";
    }
    if (partial) {
        if (!wsaHeaders.contains(Names.WSA_FROM_NAME)) {
            //ret = "expected From header";
        }
    } else {
        // REVISIT Action missing from full response
        //if (!wsaHeaders.contains(Names.WSA_ACTION_NAME)) {
        //    ret = "expected Action header";
        //}            
    }
    if (requestLeg && !(wsaHeaders.contains(CUSTOMER_NAME.getLocalPart()))) {
        ret = "expected CustomerKey header";
    }
    return ret;
}

From source file:Main.java

public static <T> List<T> intersect(List<T> list1, List<T> list2) {
    List<T> a;/*w  w w  . j a v  a  2  s  .  c  om*/
    List<T> b;
    List<T> intersection;
    if (list1.size() <= list2.size()) {
        a = list1;
        b = list2;
        intersection = new ArrayList<>(list1.size());
    } else {
        a = list2;
        b = list1;
        intersection = new ArrayList<>(list2.size());
    }
    for (T e : a) {
        if (b.contains(e)) {
            intersection.add(e);
        }
    }
    return intersection;
}

From source file:fr.ortolang.diffusion.client.cmd.CheckBagCommand.java

public static List<String> extractOrtolangKeys(String json) {
    Matcher okMatcher = CheckBagCommand.ORTOLANG_KEY_MATCHER.matcher(json);
    List<String> ortolangKeys = new ArrayList<>();
    while (okMatcher.find()) {
        if (!ortolangKeys.contains(okMatcher.group(1))) {
            ortolangKeys.add(okMatcher.group(1));
        }//  w  ww .  j ava  2  s.com
    }
    return ortolangKeys;
}