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.nexmo.client.verify.endpoints.VerifyEndpointTest.java

private static void assertContainsParam(List<NameValuePair> params, String key, String value) {
    NameValuePair item = new BasicNameValuePair(key, value);
    assertTrue("" + params + " should contain " + item, params.contains(item));
}

From source file:org.transdroid.search.barcode.GoogleWebSearchBarcodeResolver.java

private static String stripGarbage(JSONArray results, String barcode) throws JSONException {

    String good = " abcdefghijklmnopqrstuvwxyz";
    final int MAX_TITLE_CONSIDER = 4;
    final int MAX_MISSING = 1;
    final int MIN_TITLE_CONSIDER = 2;

    // First gather the titles for the first MAX_TITLE_CONSIDER results
    List<String> titles = new ArrayList<String>();
    for (int i = 0; i < results.length() && i < MAX_TITLE_CONSIDER; i++) {

        String title = results.getJSONObject(i).getString("titleNoFormatting");

        // Make string lowercase first
        title = title.toLowerCase();//from   w  w w .  jav  a 2 s .  c o m

        // Remove the barcode number if it's there
        title = title.replace(barcode, "");

        // Remove unwanted words and HTML special chars
        for (String rem : new String[] { "dvd", "blu-ray", "bluray", "&amp;", "&quot;", "&apos;", "&lt;",
                "&gt;" }) {
            title = title.replace(rem, "");
        }

        // Remove all non-alphanumeric (and space) characters
        String result = "";
        for (int j = 0; j < title.length(); j++) {
            if (good.indexOf(title.charAt(j)) >= 0)
                result += title.charAt(j);
        }

        // Remove double spaces
        while (result.contains("  ")) {
            result = result.replace("  ", " ");
        }

        titles.add(result);

    }

    // Only retain the words that are missing in at most one of the search result titles
    List<String> allWords = new ArrayList<String>();
    for (String title : titles) {
        for (String word : Arrays.asList(title.split(" "))) {
            if (!allWords.contains(word)) {
                allWords.add(word);
            }
        }
    }
    List<String> remainingWords = new ArrayList<String>();
    int allowMissing = Math.min(MAX_MISSING, Math.max(titles.size() - MIN_TITLE_CONSIDER, 0));
    for (String word : allWords) {

        int missing = 0;
        for (String title : titles) {
            if (!title.contains(word)) {
                // The word is not contained in this result title
                missing++;
                if (missing > allowMissing) {
                    // Already misssing more than once, no need to look further
                    break;
                }
            }
        }
        if (missing <= allowMissing) {
            // The word was only missing at most once, so we keep it
            remainingWords.add(word);
        }
    }

    // Now the query is the concatenation of the words remaining; with spaces in between
    String query = "";
    for (String word : remainingWords) {
        query += " " + word;
    }
    return query.length() > 0 ? query.substring(1) : null;

}

From source file:org.jspringbot.keyword.expression.ELUtils.java

public static boolean in(String... strs) {
    List<String> list = Arrays.asList(strs).subList(1, strs.length);

    return list.contains(strs[0]);
}

From source file:Main.java

/**
 * Returns {@code true} iff the node has the attribute {@code attributeName} with a value that
 * matches one of {@code attributeValues}.
 *///from  w  ww .ja va  2  s .c o  m
static boolean nodeMatchesAttributeFilter(final Node node, final String attributeName,
        final List<String> attributeValues) {
    if (attributeName == null || attributeValues == null) {
        return true;
    }

    final NamedNodeMap attrMap = node.getAttributes();
    if (attrMap != null) {
        Node attrNode = attrMap.getNamedItem(attributeName);
        if (attrNode != null && attributeValues.contains(attrNode.getNodeValue())) {
            return true;
        }
    }

    return false;
}

From source file:com.ijuru.kumva.Meaning.java

/**
 * Parses a CSV list of flag names into a bit field
 * @param str the CSV string/*  w  w  w  .j  a  v  a 2  s  .c o m*/
 * @return the bit field
 */
public static int parseFlags(String str) {
    if (StringUtils.isEmpty(str))
        return 0;

    List<String> flagStrs = Utils.parseCSV(str);
    if (flagStrs.size() == 0)
        return 0;

    // Build bit field
    int flags = 0;
    for (int f = 0; f < flagNames.length; f++) {
        String flagName = flagNames[f];
        if (flagStrs.contains(flagName)) {
            flags |= (1 << f);
        }
    }

    return flags;
}

From source file:Main.java

/**
 * Returns a name for a new dictionary based on import URI.
 *///from ww w .ja  v a 2  s  . c om
static String generateDictionaryNameByUri(Uri importUri, List<String> dictionaryNameList) {
    String name = importUri.getLastPathSegment();

    // Strip extension
    {
        int index = name.lastIndexOf('.');
        if (index > 0) {
            // Keep file path beginning with '.'.
            name = name.substring(0, index);
        }
    }

    if (!dictionaryNameList.contains(name)) {
        // No-dupped dictionary name.
        return name;
    }

    // The names extracted from uri is dupped. So look for alternative names by adding
    // number suffix, such as "pathname (1)".
    int suffix = 1;
    while (true) {
        String candidate = name + " (" + suffix + ")";
        if (!dictionaryNameList.contains(candidate)) {
            return candidate;
        }
        // The limit of the number of dictionaries is much smaller than Integer.MAX_VALUE,
        // so this while loop should stop eventually.
        ++suffix;
    }
}

From source file:AmazonKinesisFirehoseToS3Sample.java

/**
 * Method to create delivery stream for S3 destination configuration.
 *
 * @throws Exception// w  w w  . j a va2s .c o m
 */
private static void createDeliveryStream() throws Exception {

    boolean deliveryStreamExists = false;

    LOG.info("Checking if " + deliveryStreamName + " already exits");
    List<String> deliveryStreamNames = listDeliveryStreams();
    if (deliveryStreamNames != null && deliveryStreamNames.contains(deliveryStreamName)) {
        deliveryStreamExists = true;
        LOG.info("DeliveryStream " + deliveryStreamName
                + " already exists. Not creating the new delivery stream");
    } else {
        LOG.info("DeliveryStream " + deliveryStreamName + " does not exist");
    }

    if (!deliveryStreamExists) {
        // Create deliveryStream
        CreateDeliveryStreamRequest createDeliveryStreamRequest = new CreateDeliveryStreamRequest();
        createDeliveryStreamRequest.setDeliveryStreamName(deliveryStreamName);

        S3DestinationConfiguration s3DestinationConfiguration = new S3DestinationConfiguration();
        s3DestinationConfiguration.setBucketARN(s3BucketARN);
        s3DestinationConfiguration.setPrefix(s3ObjectPrefix);
        // Could also specify GZIP or ZIP
        s3DestinationConfiguration.setCompressionFormat(CompressionFormat.UNCOMPRESSED);

        // Encryption configuration is optional
        EncryptionConfiguration encryptionConfiguration = new EncryptionConfiguration();
        if (!StringUtils.isNullOrEmpty(s3DestinationAWSKMSKeyId)) {
            encryptionConfiguration.setKMSEncryptionConfig(
                    new KMSEncryptionConfig().withAWSKMSKeyARN(s3DestinationAWSKMSKeyId));
        } else {
            encryptionConfiguration.setNoEncryptionConfig(NoEncryptionConfig.NoEncryption);
        }
        s3DestinationConfiguration.setEncryptionConfiguration(encryptionConfiguration);

        BufferingHints bufferingHints = null;
        if (s3DestinationSizeInMBs != null || s3DestinationIntervalInSeconds != null) {
            bufferingHints = new BufferingHints();
            bufferingHints.setSizeInMBs(s3DestinationSizeInMBs);
            bufferingHints.setIntervalInSeconds(s3DestinationIntervalInSeconds);
        }
        s3DestinationConfiguration.setBufferingHints(bufferingHints);

        // Create and set IAM role so that firehose service has access to the S3Buckets to put data 
        // and KMS keys (if provided) to encrypt data. Please check the trustPolicyDocument.json and 
        // permissionsPolicyDocument.json files for the trust and permissions policies set for the role.
        String iamRoleArn = createIamRole(s3ObjectPrefix);
        s3DestinationConfiguration.setRoleARN(iamRoleArn);

        createDeliveryStreamRequest.setS3DestinationConfiguration(s3DestinationConfiguration);

        firehoseClient.createDeliveryStream(createDeliveryStreamRequest);

        // The Delivery Stream is now being created.
        LOG.info("Creating DeliveryStream : " + deliveryStreamName);
        waitForDeliveryStreamToBecomeAvailable(deliveryStreamName);
    }
}

From source file:br.com.diegosilva.jsfcomponents.util.Utils.java

public static boolean isLastItemInList(List list, Object o) {
    return list.contains(o) && !(list.indexOf(o) < list.size() - 1);
}

From source file:main.StratioENEI.java

private static float calculate(float[][] custos, int cidadeInicial, int cidadeFinal, List<String> ordem) {

    // System.out.printf("%d -> %d\n", cidadeInicial, cidadeFinal);
    ordem.clear();/*from  ww  w. j  a v  a 2  s .c om*/
    ordem.add(0, String.valueOf(cidadeInicial));
    ordem.add(1, String.valueOf(cidadeFinal));
    int i;
    for (i = 0; i < custos.length; i++) {
        if (ordem.contains(String.valueOf(i))) {
            continue;
        }
        float minimo = Float.MAX_VALUE;
        int idxMin = 1;
        //   System.out.println(i);
        for (int j = 1; j < ordem.size(); j++) {
            //     System.out.printf(">%d|%d\n>>B4: %s\n",i, j, ordem);
            ordem.add(j, String.valueOf(i));
            //      System.out.printf(">>After: %s\n", ordem);
            float value = calcCost(ordem, custos);
            //  System.out.println("Value: "+value);
            ordem.remove(j);

            if (value < minimo) {
                minimo = value;
                idxMin = j;
            }
        }
        ordem.add(idxMin, String.valueOf(i));
        //    System.out.println(ordem);
    }
    return calcCost(ordem, custos);
}

From source file:org.wso2.security.tools.advisorytool.utils.Util.java

/**
 * Generate the product and version string for a given kernel version.
 *
 * @param kernelVersion/*from   w  ww  .  ja v  a 2  s. c om*/
 * @return list of product and version strings (e.g., WSO2 API Manager 2.1.0)
 */
public static List<String> getApplicableProductsForAKernel(String kernelVersion) {
    List<String> applicableProductAndVersionStringList = new ArrayList<>();

    for (Product product : ProductDataHolder.getInstance().getProductList()) {
        for (Version version : product.getVersionList()) {
            if (version.getKernelVersionNumber().equals(kernelVersion) && !applicableProductAndVersionStringList
                    .contains(product.getName() + " " + version.getVersionNumber())) {
                applicableProductAndVersionStringList.add(product.getName() + " " + version.getVersionNumber());

                if (logger.isDebugEnabled()) {
                    logger.debug(
                            "Product Version String : " + product.getName() + " " + version.getVersionNumber());
                }
            }
        }
    }
    return applicableProductAndVersionStringList;
}