Example usage for java.util ArrayList contains

List of usage examples for java.util ArrayList contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:com.tealeaf.NativeShim.java

public int[] reportGlError(int errorCode) {
    Settings settings = context.getSettings();
    String glErrorStr = settings.getString("gl_errors", "NONE");
    String errorCodeStr = Integer.toString(errorCode);

    ArrayList<String> glErrorList = null;
    if (glErrorStr.equals("NONE")) {
        glErrorList = new ArrayList<String>();
    } else {/*from  w ww.  ja v  a2s. c o  m*/
        glErrorList = new ArrayList<String>(Arrays.asList(glErrorStr.split(",")));
    }

    int[] glErrorInts = new int[glErrorList.size()];

    if (glErrorList.contains(errorCodeStr)) {
        //create the return array, do not log as this error has been seen
        for (int i = 0; i < glErrorInts.length; i++) {
            glErrorInts[i] = Integer.parseInt(glErrorList.get(i));
        }

    } else {
        //create the return array and log
        glErrorList.add(errorCodeStr);

        //build the settings string
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < glErrorList.size(); i++) {
            stringBuilder.append(glErrorList.get(i));
            if (i != glErrorList.size() - 1) {
                stringBuilder.append(",");
            }
        }

        //save the new errors
        settings.setString("gl_errors", stringBuilder.toString());

        //log the error
        String errorString = "GL ERROR: " + errorCodeStr;
        if (context.getOptions().isDevelop()) {
            logger.log(errorString);
        } else {
            remoteLogger.sendGLErrorEvent(context, errorString);
        }

        //create the return array
        for (int i = 0; i < glErrorInts.length; i++) {
            glErrorInts[i] = Integer.parseInt(glErrorList.get(i));
        }
    }

    return glErrorInts;
}

From source file:com.kyleshaver.minuteofangle.util.IabHelper.java

int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
            throws RemoteException, JSONException {
        logDebug("Querying SKU details.");
        ArrayList<String> skuList = new ArrayList<String>();
        skuList.addAll(inv.getAllOwnedSkus(itemType));
        if (moreSkus != null) {
            for (String sku : moreSkus) {
                if (!skuList.contains(sku)) {
                    skuList.add(sku);// w  ww  .  j av a  2  s . c o  m
                }
            }
        }

        if (skuList.size() == 0) {
            logDebug("queryPrices: nothing to do because there are no SKUs.");
            return BILLING_RESPONSE_RESULT_OK;
        }

        // Split the sku list in blocks of no more than 20 elements.
        ArrayList<ArrayList<String>> packs = new ArrayList<ArrayList<String>>();
        ArrayList<String> tempList;
        int n = skuList.size() / 20;
        int mod = skuList.size() % 20;
        for (int i = 0; i < n; i++) {
            tempList = new ArrayList<String>();
            for (String s : skuList.subList(i * 20, i * 20 + 20)) {
                tempList.add(s);
            }
            packs.add(tempList);
        }
        if (mod != 0) {
            tempList = new ArrayList<String>();
            for (String s : skuList.subList(n * 20, n * 20 + mod)) {
                tempList.add(s);
            }
            packs.add(tempList);
        }

        for (ArrayList<String> skuPartList : packs) {
            Bundle querySkus = new Bundle();
            querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList);
            Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);

            if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
                int response = getResponseCodeFromBundle(skuDetails);
                if (response != BILLING_RESPONSE_RESULT_OK) {
                    logDebug("getSkuDetails() failed: " + getResponseDesc(response));
                    return response;
                } else {
                    logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
                    return IABHELPER_BAD_RESPONSE;
                }
            }

            ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

            for (String thisResponse : responseList) {
                SkuDetails d = new SkuDetails(itemType, thisResponse);
                logDebug("Got sku details: " + d);
                inv.addSkuDetails(d);
            }
        }

        return BILLING_RESPONSE_RESULT_OK;
    }

From source file:de.geithonline.abattlwp.billinghelper.IabHelper.java

int querySkuDetails(final String itemType, final Inventory inv, final List<String> moreSkus)
        throws RemoteException, JSONException {
    logDebug("Querying SKU details.");
    final ArrayList<String> skuList = new ArrayList<String>();
    skuList.addAll(inv.getAllOwnedSkus(itemType));
    if (moreSkus != null) {
        for (final String sku : moreSkus) {
            if (!skuList.contains(sku)) {
                skuList.add(sku);/*from w w  w  . j  ava2 s  . c o  m*/
            }
        }
    }

    if (skuList.size() == 0) {
        logDebug("queryPrices: nothing to do because there are no SKUs.");
        return BILLING_RESPONSE_RESULT_OK;
    }

    final Bundle querySkus = new Bundle();
    querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);
    final Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);

    if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
        final int response = getResponseCodeFromBundle(skuDetails);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logDebug("getSkuDetails() failed: " + getResponseDesc(response));
            return response;
        } else {
            logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
            return IABHELPER_BAD_RESPONSE;
        }
    }

    final ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

    for (final String thisResponse : responseList) {
        final SkuDetails d = new SkuDetails(itemType, thisResponse);
        logDebug("Got sku details: " + d);
        inv.addSkuDetails(d);
    }
    return BILLING_RESPONSE_RESULT_OK;
}

From source file:com.kylinolap.common.persistence.HBaseResourceStore.java

@Override
protected ArrayList<String> listResourcesImpl(String resPath) throws IOException {
    assert resPath.startsWith("/");
    String lookForPrefix = resPath.endsWith("/") ? resPath : resPath + "/";
    byte[] startRow = Bytes.toBytes(lookForPrefix);
    byte[] endRow = Bytes.toBytes(lookForPrefix);
    endRow[endRow.length - 1]++;//from   w  w  w .ja  v  a2  s .  c  o m

    ArrayList<String> result = new ArrayList<String>();

    for (Entry<String, String> entry : tableNameMap.entrySet()) {
        String pathPrefix = entry.getKey();
        String tableName = entry.getValue();

        if ((pathPrefix.startsWith(lookForPrefix) || lookForPrefix.startsWith(pathPrefix)) == false)
            continue;

        HTableInterface table = getConnection().getTable(tableName);

        Scan scan = new Scan(startRow, endRow);
        scan.setFilter(new KeyOnlyFilter());
        try {
            ResultScanner scanner = table.getScanner(scan);
            for (Result r : scanner) {
                String path = Bytes.toString(r.getRow());
                assert path.startsWith(lookForPrefix);
                int cut = path.indexOf('/', lookForPrefix.length());
                String child = cut < 0 ? path : path.substring(0, cut);
                if (result.contains(child) == false)
                    result.add(child);
            }
        } finally {
            IOUtils.closeQuietly(table);
        }
    }
    // return null to indicate not a folder
    return result.isEmpty() ? null : result;
}

From source file:com.jaspersoft.jasperserver.api.engine.scheduling.hibernate.HibernateReportJobsPersistenceService.java

private void foundInvalidID(List<ReportJobIdHolder> expectedIDs, List actualIDs)
        throws ReportJobNotFoundException {
    if (actualIDs == null)
        throw new ReportJobNotFoundException(expectedIDs.get(0).getId());
    ArrayList<Long> foundIDList = new ArrayList<Long>();
    for (Object persistentJob : actualIDs)
        foundIDList.add(((PersistentReportJob) persistentJob).getId());
    for (ReportJobIdHolder expectedID : expectedIDs) {
        if (!foundIDList.contains(expectedID.getId()))
            throw new ReportJobNotFoundException(expectedID.getId());
    }/*  ww  w. j  a v  a2 s .  com*/
}

From source file:at.ait.dme.yuma.suite.apps.map.server.geo.GeocoderServiceImpl.java

private SemanticTag[] parseGeonamesResponse(CharSequence xml) throws Exception {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(new ByteArrayInputStream(xml.toString().getBytes("UTF-8")));

    ArrayList<SemanticTag> tags = new ArrayList<SemanticTag>();
    NodeList nodes = doc.getElementsByTagName("geoname");

    NodeList children;//ww  w .  j ava2 s.c  om
    ArrayList<String> countries = new ArrayList<String>();
    for (int i = 0; i < nodes.getLength(); i++) {
        String toponymName = null;
        String geonameId = null;
        String country = null;
        String lat = null;
        String lon = null;
        children = nodes.item(i).getChildNodes();
        for (int j = 0; j < children.getLength(); j++) {
            Node child = children.item(j);
            if (child.getNodeName().equals("toponymName")) {
                toponymName = child.getTextContent();
            } else if (child.getNodeName().equals("geonameId")) {
                geonameId = child.getTextContent();
            } else if (child.getNodeName().equals("countryName")) {
                // Store country --> we'll retrieve their geonameIds later, too!
                country = child.getTextContent();
                if (!countries.contains(country))
                    countries.add(country);
            } else if (child.getNodeName().equals("lat")) {
                lat = child.getTextContent();
            } else if (child.getNodeName().equals("lng")) {
                lon = child.getTextContent();
            }
        }
        if (toponymName != null && country != null && geonameId != null && lat != null && lon != null)
            tags.add(new SemanticTag(toponymName, getAlternativePlacenames(toponymName), "Place", "en",
                    toponymName + ", " + country + " (city) \nLatitude: " + lat + " \nLongitude: " + lon,
                    GEONAMES_URI_TEMPLATE.replace("@id@", geonameId)));
    }

    for (SemanticTag countryTag : getCountries(countries)) {
        tags.add(0, countryTag);
    }

    return tags.toArray(new SemanticTag[tags.size()]);
}

From source file:de.biomedical_imaging.ij.steger.LineDetector.java

private Junctions fixJunctions(Lines lines, Junctions junctions) {
    /*/* w w w  .  jav a2s.c  o  m*/
     * For some reason, the x and y coordinates are permuted
     */
    for (Junction junction : junctions) {
        float help = junction.x;
        junction.x = junction.y;
        junction.y = help;
    }

    Junctions newJunctions = new Junctions(junctions.getFrame());
    ArrayList<Point2D.Float> processedJunctions = new ArrayList<Point2D.Float>();
    for (int i = 0; i < junctions.size(); i++) {
        Junction junc = junctions.get(i);
        Line mainLine = null;
        int mainLineIndex = -1;
        int mainLinePos = -1;
        ArrayList<Line> secondaryLines = new ArrayList<Line>();
        ArrayList<Integer> secondaryLineIndex = new ArrayList<Integer>();
        ArrayList<Integer> secondaryLinePos = new ArrayList<Integer>();

        //Verarbeite jede Junction-Position nur einmal.
        if (!processedJunctions.contains(new Point2D.Float(junc.x, junc.y))) { //processed[(int)junc.x][(int)junc.y]==0

            processedJunctions.add(new Point2D.Float(junc.x, junc.y));

            /*
             * Finde die Sekundrlinien und Hauptlinien
             */
            for (int j = 0; j < lines.size(); j++) {
                Line l = lines.get(j);

                double[] mindist = minDistance(l, junc.x, junc.y);
                if (mindist[0] < 0.1) { //Wenn der Punkt auf der Linie liegt, analysiere genauer

                    if (mindist[1] == 0 || mindist[1] == (l.num - 1)) { //Wenn der Junction-Point am Ende oder am Anfang liegt, ist es sekundre Linie.
                        secondaryLines.add(l);
                        secondaryLineIndex.add(j);
                        secondaryLinePos.add((int) mindist[1]);
                    } else { // Wenn er innerhalb der Linie liegt, ist dies die Hauptlinie.

                        if (mainLine != null) {
                            if (mainLine.getID() == l.getID()) {
                                continue;
                            }
                            log("h, zwei Hauptlininen geht nich..." + mainLine.getID() + " x " + junc.x
                                    + " y " + junc.y);
                            log("h, zwei Hauptlininen geht nich..." + l.getID() + " x " + junc.x + " y "
                                    + junc.y);
                        }
                        mainLine = l;
                        mainLineIndex = j;
                        mainLinePos = (int) mindist[1];

                    }
                }
            }
            if (mainLine != null) {
                for (int j = 0; j < secondaryLines.size(); j++) {
                    Junction newJunc = new Junction();
                    newJunc.cont1 = mainLineIndex;
                    newJunc.cont2 = secondaryLineIndex.get(j);
                    newJunc.x = junc.x;
                    newJunc.y = junc.y;
                    newJunc.pos = mainLinePos;
                    //lines.get(newJunc.cont1).setContourClass(reconstructContourClass(lines.get(newJunc.cont1), mainLinePos));
                    //lines.get(newJunc.cont2).setContourClass(reconstructContourClass(lines.get(newJunc.cont2), secondaryLinePos.get(j)));
                    newJunctions.add(newJunc);
                    log("NewJunc Mainline: " + lines.get(newJunc.cont1).getID() + "-"
                            + lines.get(newJunc.cont2).getID() + " pos " + newJunc.pos + " num "
                            + lines.get(newJunc.cont1).num);

                }
            } else {
                //In manchen Fllen gibt es keine Hauptlinie... (bug im Algorithmus, ich bin aber nicht fhig ihn zu finden=.
                HashSet<Integer> uniqueIDs = new HashSet<Integer>();
                ArrayList<Line> uniqueLines = new ArrayList<Line>();
                ArrayList<Integer> uniqueLineIndex = new ArrayList<Integer>();
                ArrayList<Integer> uniqueLinePos = new ArrayList<Integer>();
                for (int j = 0; j < secondaryLines.size(); j++) {
                    if (!uniqueIDs.contains(secondaryLines.get(j).getID())) {
                        uniqueIDs.add(secondaryLines.get(j).getID());
                        uniqueLines.add(secondaryLines.get(j));
                        uniqueLineIndex.add(secondaryLineIndex.get(j));
                        uniqueLinePos.add(secondaryLinePos.get(j));

                    }

                }
                for (int j = 0; j < uniqueLines.size(); j++) {
                    for (int k = j + 1; k < uniqueLines.size(); k++) {
                        Junction newJunc = new Junction();
                        newJunc.cont1 = uniqueLineIndex.get(j);
                        newJunc.cont2 = uniqueLineIndex.get(k);
                        newJunc.x = junc.x;
                        newJunc.y = junc.y;
                        newJunc.pos = uniqueLinePos.get(j);
                        newJunctions.add(newJunc);
                        log("NewJunc Second: " + lines.get(newJunc.cont1).getID() + "-"
                                + lines.get(newJunc.cont2).getID() + " pos " + newJunc.pos + " num "
                                + lines.get(newJunc.cont1).num);

                        //lines.get(newJunc.cont1).setContourClass(reconstructContourClass(lines.get(newJunc.cont1), uniqueLinePos.get(j)));
                        //lines.get(newJunc.cont2).setContourClass(reconstructContourClass(lines.get(newJunc.cont2), uniqueLinePos.get(k)));
                        alreadyProcessedJunctionPoints.add(newJunctions.size() - 1);

                    }
                }
            }

        }
    }
    return newJunctions;

}

From source file:org.apache.taverna.scufl2.api.common.Scufl2Tools.java

/**
 * Return list of nested workflows for processor as configured in given
 * profile.//from w  ww .  j  a  v a2s. c  om
 * <p>
 * A nested workflow is an activity bound to the processor with the
 * configurable type equal to {@value #NESTED_WORKFLOW}.
 * <p>
 * This method returns a list of 0 or more workflows, as every matching
 * {@link ProcessorBinding} and every matching {@link Configuration} for the
 * bound activity is considered. Normally there will only be a single nested
 * workflow, in which case the
 * {@link #nestedWorkflowForProcessor(Processor, Profile)} method should be
 * used instead.
 * <p>
 * Note that even if several bindings/configurations map to the same
 * workflow, each workflow is only included once in the list. Nested
 * workflow configurations that are incomplete or which #workflow can't be
 * found within the workflow bundle of the profile will be silently ignored.
 * 
 * @throws NullPointerException
 *             if the given profile does not have a parent
 * @throws IllegalStateException
 *             if a nested workflow configuration is invalid
 * 
 * @param processor
 *            Processor which might have a nested workflow
 * @param profile
 *            Profile to look for nested workflow activity/configuration.
 *            The profile must have a {@link WorkflowBundle} set as its
 *            {@link Profile#setParent(WorkflowBundle)}.
 * @return List of configured nested workflows for processor
 */
public List<Workflow> nestedWorkflowsForProcessor(Processor processor, Profile profile) {
    WorkflowBundle bundle = profile.getParent();
    if (bundle == null)
        throw new NullPointerException("Parent must be set for " + profile);
    ArrayList<Workflow> workflows = new ArrayList<>();
    for (ProcessorBinding binding : processorBindingsForProcessor(processor, profile)) {
        if (!binding.getBoundActivity().getType().equals(NESTED_WORKFLOW))
            continue;
        for (Configuration c : configurationsFor(binding.getBoundActivity(), profile)) {
            JsonNode nested = c.getJson().get("nestedWorkflow");
            Workflow wf = bundle.getWorkflows().getByName(nested.asText());
            if (wf != null && !workflows.contains(wf))
                workflows.add(wf);
        }
    }
    return workflows;
}

From source file:geva.Mapper.ContextFreeGrammar.java

/** Returns the calculated recursive nature of the Rule passed as argument,
 * and updates its minimum mapping depth (minimumDepth)
 * @param visitedRules list of visited rules
 * @param currentRule current rule visited
 * @return if the rule is recursive//from w w  w  .j  a  v a2 s.c  o  m
 */
boolean isRecursive(ArrayList<Rule> visitedRules, Rule currentRule) {
    Production tempProd;
    Iterator<Symbol> symbIt;
    Iterator<Production> prodIt;
    Symbol tempSymbol;
    Rule definingRule;

    if (visitedRules.size() == 0) {
        prodIt = currentRule.iterator();
    } else {
        prodIt = visitedRules.get(visitedRules.size() - 1).iterator();
    }

    // Check if this is a recursive call to a previously visited rule
    if (visitedRules.contains(findRule(currentRule.getLHS()))) {
        currentRule.setRecursive(true);
        return true;
    }

    // Go through each production in the rule
    while (prodIt.hasNext()) {
        tempProd = prodIt.next();
        symbIt = tempProd.iterator();
        while (symbIt.hasNext()) {
            tempSymbol = symbIt.next();
            if (tempSymbol.getType() == Enums.SymbolType.NTSymbol) {
                definingRule = findRule(tempSymbol);
                if (definingRule != null) {
                    if (!visitedRules.contains(definingRule)) {
                        visitedRules.add(definingRule);
                        if (isRecursive(visitedRules, currentRule)) {
                            tempProd.setRecursive(true);
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}

From source file:com.jzboy.couchdb.DatabaseDocUpdateTest.java

@Test
public void testFlushBulkUpdatesCache() throws Exception {
    instance.setBulkUpdatesLimit(1000);/* w w  w.j av  a2s.co  m*/
    ArrayList<String> uuids = instance.getServer().nextUUIDs(2);
    final String json1 = "{\"field1\":\"value1\",\"field2\":2}";
    final String json2 = "{\"field1\":\"value2\",\"field2\":3}";
    Document doc1 = new Document(uuids.get(0), null, json1);
    Document doc2 = new Document(uuids.get(1), null, json2);
    assertEquals("Number of documents in bulk cache not as expected", 0, instance.numDocsPendingBulkUpdate());
    instance.saveInBulk(doc1);
    instance.saveInBulk(doc2);
    assertEquals("Number of documents in bulk cache not as expected", 2, instance.numDocsPendingBulkUpdate());

    ArrayList<JsonNode> report = instance.flushBulkUpdatesCache(false, true);
    assertEquals("Documents not flushed from bulk cache following call to flush", 0,
            instance.numDocsPendingBulkUpdate());
    for (JsonNode resDoc : report) {
        assertTrue("Results of flushBulkUpdatesCache did not contain a saved document's ID",
                uuids.contains(resDoc.get("id").getTextValue()));
    }
}