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:jeplus.data.ParameterItem.java

/**
 * Combining the two lists or excluding the second list from the first.
 * @param vals1 The first list// www  .  ja  v a 2 s  .c  om
 * @param vals2 The second list
 * @param op Operation can be either COMBINE or EXCLUDE
 * @return a new list as the combination of the two
 */
private String[] mergeLists(String[] vals1, String[] vals2, int op, boolean allow_duplicates) {
    ArrayList<String> set = new ArrayList(Arrays.asList(vals1));
    if (op == COMBINE) {
        for (int i = 0; i < vals2.length; i++) {
            if (allow_duplicates || !set.contains(vals2[i]))
                set.add(vals2[i]);
        }
    } else {
        for (int i = 0; i < vals2.length; i++) {
            set.remove(vals2[i]);
        }
    }
    return set.toArray(new String[0]);
}

From source file:unalcol.termites.boxplots.BestAgentsPercentageInfoCollected.java

private static ArrayList<Double> getFailureProbs() {
    ArrayList<Double> pfs = new ArrayList<>();
    String sDirectorio = experimentsDir;
    System.out.println("experiments dir" + sDirectorio);
    File f = new File(sDirectorio);
    String extension;//from ww  w.ja  v  a2  s  . c om
    File[] files = f.listFiles();

    for (File file : files) {
        extension = "";
        int i = file.getName().lastIndexOf('.');
        int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\'));
        if (i > p) {
            extension = file.getName().substring(i + 1);
        }

        // System.out.println(file.getName() + "extension" + extension);
        if (file.isFile() && extension.equals("csv") && file.getName().startsWith("experiment")
                && file.getName().contains(mazeMode)) {
            System.out.println(file.getName());
            System.out.println("get: " + file.getName());
            String[] filenamep = file.getName().split(Pattern.quote("+"));
            System.out.println("file" + filenamep[8]);
            int popsize = Integer.valueOf(filenamep[2]);
            double pf = Double.valueOf(filenamep[4]);
            String mode = filenamep[6];
            int maxIter = -1;
            //if (!filenamep[8].isEmpty()) {
            maxIter = Integer.valueOf(filenamep[8]);
            //}
            System.out.println("psize:" + popsize);
            System.out.println("pf:" + pf);
            System.out.println("mode:" + mode);
            System.out.println("maxIter:" + maxIter);

            System.out.println("pf:" + pf);
            if (!pfs.contains(pf)) {
                pfs.add(pf);
            }
        }
    }
    System.out.println("pfs" + pfs);
    return pfs;
}

From source file:android.support.v4.app._ActionBarSherlockTrojanHorse.java

@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
    if (DEBUG)/*  w ww.j  av  a  2 s.com*/
        Log.d(TAG, "[onCreatePanelMenu] featureId: " + featureId + ", menu: " + menu);

    if (featureId == Window.FEATURE_OPTIONS_PANEL) {
        boolean result = onCreateOptionsMenu(menu);
        if (DEBUG)
            Log.d(TAG, "[onCreatePanelMenu] activity create result: " + result);

        MenuInflater inflater = getSupportMenuInflater();
        boolean show = false;
        ArrayList<Fragment> newMenus = null;
        if (mFragments.mActive != null) {
            for (int i = 0; i < mFragments.mAdded.size(); i++) {
                Fragment f = mFragments.mAdded.get(i);
                if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible
                        && f instanceof OnCreateOptionsMenuListener) {
                    show = true;
                    ((OnCreateOptionsMenuListener) f).onCreateOptionsMenu(menu, inflater);
                    if (newMenus == null) {
                        newMenus = new ArrayList<Fragment>();
                    }
                    newMenus.add(f);
                }
            }
        }

        if (mCreatedMenus != null) {
            for (int i = 0; i < mCreatedMenus.size(); i++) {
                Fragment f = mCreatedMenus.get(i);
                if (newMenus == null || !newMenus.contains(f)) {
                    f.onDestroyOptionsMenu();
                }
            }
        }

        mCreatedMenus = newMenus;

        if (DEBUG)
            Log.d(TAG, "[onCreatePanelMenu] fragments create result: " + show);
        result |= show;

        if (DEBUG)
            Log.d(TAG, "[onCreatePanelMenu] returning " + result);
        return result;
    }
    return false;
}

From source file:com.mycompany.parcinghtml.ParsingClassPlayers.java

public void downloadSource() throws SQLException {
    //ds = prepareDataSource();
    String sql = "INSERT INTO PLAYERS(NAME,AGE,HEIGHT,WEIGHT,PLAYERNUM,POSITION,PLAYERID) VALUES(?,?,?,?,?,?,?)";
    ArrayList<String> duplicity = new ArrayList<>();
    int playerID = 1;

    for (int i = 2015; i > 2004; i--) {
        Document doc = null;// w w  w  .ja v a2 s  .  com
        try {
            doc = Jsoup.connect("http://www.hcsparta.cz/soupiska.asp?sezona=" + Integer.toString(i)).get();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        if (doc == null) {
            System.out.println("doc is null");
            return;
        }

        Elements posNum;
        Elements elList;
        posNum = doc.getElementsByAttributeValueContaining("class", "soupiska");
        //elList = doc.getElementsByAttributeValueContaining("id", "soupiska");
        for (int j = 0; j < 3; j++) {
            elList = posNum.get(j).getElementsByAttributeValueContaining("id", "soupiska");

            for (Element item : elList) {
                String[] secondName = item.child(2).text().split(" ");
                if (duplicity.contains(item.child(2).text()))
                    continue;
                duplicity.add(item.child(2).text());
                try (Connection conn = ds.getConnection()) {

                    try (PreparedStatement st = conn.prepareStatement(sql)) {
                        st.setString(1, item.child(2).text());
                        String[] age = item.child(4).text().split(" ");
                        st.setInt(2, Integer.parseInt(age[0]));
                        String[] height = item.child(5).text().split(" ");
                        st.setInt(3, Integer.parseInt(height[0]));
                        String[] weight = item.child(6).text().split(" ");
                        st.setInt(4, Integer.parseInt(weight[0]));

                        try {
                            st.setInt(5, Integer.parseInt(item.child(0).text()));
                        } catch (NumberFormatException ex) {
                            st.setInt(5, 0);
                        }
                        st.setInt(6, j);
                        st.setInt(7, playerID);
                        int addedRows = st.executeUpdate();
                        playerID++;
                    }
                } catch (SQLException ex) {
                    throw new SQLException(ex.getMessage(), ex.fillInStackTrace());
                }

            }
        }

    }

}

From source file:com.onesignal.TrackGooglePurchase.java

private void QueryBoughtItems() {
    if (isWaitingForPurchasesRequest)
        return;//from   w ww  .  ja v  a 2  s  .c o m

    new Thread(new Runnable() {
        public void run() {
            isWaitingForPurchasesRequest = true;
            try {
                if (getPurchasesMethod == null) {
                    getPurchasesMethod = getGetPurchasesMethod(IInAppBillingServiceClass);
                    getPurchasesMethod.setAccessible(true);
                }

                Bundle ownedItems = (Bundle) getPurchasesMethod.invoke(mIInAppBillingService, 3,
                        appContext.getPackageName(), "inapp", null);
                if (ownedItems.getInt("RESPONSE_CODE") == 0) {
                    ArrayList<String> skusToAdd = new ArrayList<String>();
                    ArrayList<String> newPurchaseTokens = new ArrayList<String>();

                    ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                    ArrayList<String> purchaseDataList = ownedItems
                            .getStringArrayList("INAPP_PURCHASE_DATA_LIST");

                    for (int i = 0; i < purchaseDataList.size(); i++) {
                        String purchaseData = purchaseDataList.get(i);
                        String sku = ownedSkus.get(i);
                        JSONObject itemPurchased = new JSONObject(purchaseData);
                        String purchaseToken = itemPurchased.getString("purchaseToken");

                        if (!purchaseTokens.contains(purchaseToken)
                                && !newPurchaseTokens.contains(purchaseToken)) {
                            newPurchaseTokens.add(purchaseToken);
                            skusToAdd.add(sku);
                        }
                    }

                    if (skusToAdd.size() > 0)
                        sendPurchases(skusToAdd, newPurchaseTokens);
                    else if (purchaseDataList.size() == 0) {
                        newAsExisting = false;
                        prefsEditor.putBoolean("ExistingPurchases", false);
                        prefsEditor.commit();
                    }

                    // TODO: Handle very large list. Test for continuationToken != null then call getPurchases again
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
            isWaitingForPurchasesRequest = false;
        }
    }).start();
}

From source file:me.ccrama.redditslide.util.IabHelper.java

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

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

    Bundle querySkus = new Bundle();
    querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);
    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;
        }
    }

    List<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:com.alkacon.opencms.documentcenter.CmsXmlDocumentContent.java

/**
 * Returns a list with all paths to look for a default file. The order is to first
 * look in the folder specified in the property and then in the given startRoot and all
 * parent folder up to the root folder of the document center.<p>
 * /*from w  ww . j  a va 2  s  .  co m*/
 * @param property the name of the property where the name of the folder to search in is defined
 * @param search flag if to search in parent folders too
 * @param searchRoot the directory where to start the search for the default file
 * @return a list with all found paths to look for a default file
 */
private List getFolderList(String property, boolean search, String searchRoot) {

    ArrayList ret = new ArrayList();

    // look for the path defined in the property
    String path = m_cms.property(property, "search", null);
    if (path != null) {
        ret.add(path);
    }

    // if value is not going to be searched return only folder of property
    if (!search) {
        return ret;
    }

    // check if searchRoot ends with slash
    if ((searchRoot != null) && (!searchRoot.endsWith("/"))) {
        searchRoot += "/";
    }

    try {

        // add actual path and all parent paths up to the document center
        boolean next = true;
        String currentPath = searchRoot;
        while ((next) && (currentPath != null)) {
            if (!ret.contains(currentPath)) {
                ret.add(currentPath);
            }

            // check if current folder is already root folder of document center
            CmsResource currentRes = m_cms.getCmsObject().readResource(currentPath);
            if (currentRes.getTypeId() == 260) {
                next = false;
            }

            currentPath = CmsResource.getParentFolder(currentPath);
        }

        // if current resource is not inside a document center only add folder from property
        if (next) {
            ret = new ArrayList();
            if (path != null) {
                ret.add(path);
            }
        }
    } catch (CmsException ex) {
        // do nothing
    }

    return ret;
}

From source file:net.minelord.gui.panes.IRCPane.java

public void updateUserList(int type) {
    sortType = type;/*from   w ww  .j a v  a2s . co  m*/
    switch (sortType) {
    case 0:
        userList.setListData(client.getUserList().toArray());
        break;
    case 1:
        Object[] temp = client.getUserList().toArray();
        Arrays.sort(temp);
        userList.setListData(temp);
        break;
    case 2:
        ArrayList<String> nicks = new ArrayList<String>();
        for (String nick : client.getOps())
            nicks.add(nick);
        for (String nick : client.getHops())
            nicks.add(nick);
        for (String nick : client.getUserList())
            if (!nicks.contains(nick))
                nicks.add(nick);
        userList.setListData(nicks.toArray());
        break;
    case 3:
        userList.setListData(new Object[0]);
        break;
    }
}

From source file:gsn.webservice.standard.GSNWebServiceSkeleton.java

private void updateSelectionValue(HashMap<String, ArrayList<String>> source, ArrayList<String> keys,
        String value) {//from  w w w .j ava 2 s .c om
    if (source == null || keys == null || value == null)
        return;
    for (String key : keys) {
        ArrayList<String> sv = source.get(key);
        if (sv == null) {
            ArrayList<String> values = new ArrayList<String>();
            values.add(value);
            source.put(key, values);
        } else {
            if (!sv.contains(value))
                sv.add(value);
        }
    }
}

From source file:com.hygenics.parser.SpecDumpWithReference.java

/**
 * Runs the Dump/* w  w  w .ja  v  a 2 s .  c o m*/
 */
public void run() {

    if (archive) {
        Archiver zip = new Archiver();
        String[] barr = baseFile.split("\\/");
        String basefile = "";
        for (int i = 0; i > barr.length - 1; i++) {
            basefile += (i == 0) ? barr[i] : "/" + barr[i];
        }
        if (basefile.trim().length() > 0) {
            zip.setBasedirectory(basefile);
            zip.setZipDirectory(basefile + "archive.zip");
            zip.setAvoidanceString(".zip|archive");
            zip.setDelFiles(true);
            zip.run();
        }
    }

    int dumped = 0;
    log.info("Tables Found: " + tables.size());
    ForkJoinPool fjp = new ForkJoinPool(Runtime.getRuntime().availableProcessors());
    boolean checkedTables = (this.tablesMustHave == null);
    for (String tf : tables.keySet()) {
        String[] split = (this.baseschema + "." + tf + "|" + this.baseFile + tf).split("\\|");
        log.info("Dumping for " + split[0]);
        String schema = null;
        try {
            schema = split[0].split("\\.")[0];

            if (!checkedTables) {
                ArrayList<String> mustHaveTemp = (ArrayList<String>) this.tablesMustHave.clone();
                ArrayList<String> existingTables = this.template.getJsonData(
                        "SELECT table_name FROM information_schema.tables WHERE table_schema ILIKE '%" + schema
                                + "%'");
                for (String tdict : existingTables) {

                    String table = Json.parse(tdict).asObject().get("table_name").asString();
                    if (mustHaveTemp.contains(table)) {
                        mustHaveTemp.remove(table);

                        // get count
                        if (this.template.getCount(schema + "." + table) == 0) {
                            try {
                                throw new MissingData(
                                        "Data Missing from Required Table: " + schema + "." + table);
                            } catch (MissingData e) {
                                e.printStackTrace();
                                if (tablesMustHave.contains(table)) {
                                    log.error("Critical Table Missing Data! Terminating!");
                                    System.exit(-1);
                                }
                            }
                        }

                    }
                }

                if (mustHaveTemp.size() > 0) {
                    log.error("Drop Schema " + schema + "  is missing the following tables:\n");
                    for (String table : mustHaveTemp) {
                        log.error(table + "\n");
                    }

                    try {
                        throw new TableMissingException();
                    } catch (TableMissingException e) {
                        e.printStackTrace();
                        System.exit(-1);
                    }
                }
            }

        } catch (IndexOutOfBoundsException e) {
            try {
                throw new SQLMalformedException("FATAL ERROR: Table name " + split[0] + " malformed");
            } catch (SQLMalformedException e2) {
                e2.printStackTrace();
                System.exit(-1);
            }
        }

        log.info("Checking  table: " + split[0] + "&& schema: " + schema);

        if (template.checkTable(split[0], schema)) {
            // check if there are records

            if (template.getCount(schema + "." + split[0].replace(schema + ".", "")) > 0) {
                dumped += 1;
                Set<String> keys = tables.get(tf).keySet();
                String sql;
                String select = "SELECT ";
                String distinct = null;
                String attrs = null;
                String where = null;
                String group = null;
                String order = null;

                /**
                 * SET THE ATTRIBUTES WHICH CAN BE SPECIFIED WITH
                 * distinct-for concacting distinct part of query not0-for
                 * specifiying that the length must be greater than 0 in the
                 * WHERE clause group-for grouping the attribute not
                 * null-for specifying that the attr cannot be null
                 * orderby-for specifying our one order attr
                 */
                for (String k : keys) {
                    if (k.toLowerCase().contains("distinct")) {
                        distinct = (distinct == null)
                                ? "distinct on(" + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                : distinct + "," + tables.get(tf).get(k).replaceAll("\\sas.*", "");
                    }

                    if (k.toLowerCase().contains("group")) {
                        group = (group == null) ? "GROUP BY " + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                : group + "," + tables.get(tf).get(k).replaceAll("\\sas.*", "");
                    }

                    if (k.toLowerCase().contains("not0")) {
                        if (k.contains("not0OR")) {
                            where = (where == null)
                                    ? "WHERE length(" + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                            + ") >0 "
                                    : where + "OR length(" + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                            + ")";
                        } else {
                            where = (where == null)
                                    ? "WHERE length(" + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                            + ") >0 "
                                    : where + "AND length(" + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                            + ")";
                        }
                    }

                    if (k.toLowerCase().contains("notnull")) {
                        if (k.toLowerCase().contains("notnullor")) {
                            where = (where == null)
                                    ? "WHERE " + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                            + " IS NOT NULL"
                                    : where + " OR " + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                            + " IS NOT NULL";
                        } else {
                            where = (where == null)
                                    ? "WHERE " + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                            + " IS NOT NULL"
                                    : where + " AND " + tables.get(tf).get(k).replaceAll("\\sas.*", "")
                                            + " IS NOT NULL";
                        }
                    }

                    if (k.toLowerCase().contains("order")) {
                        if (k.toLowerCase().contains("orderdesc")) {
                            order = (order == null)
                                    ? "ORDER BY " + tables.get(tf).get(k).replaceAll("\\sas.*", "") + " ASC"
                                    : order;
                        } else {
                            order = (order == null)
                                    ? "ORDER BY " + tables.get(tf).get(k).replaceAll("\\sas.*", "") + " DESC"
                                    : order;
                        }
                    }

                    String field = tables.get(tf).get(k);
                    if (k.toLowerCase().contains("attr")) {
                        if (unicoderemove == true) {
                            field = "regexp_replace(trim(replace(regexp_replace(cast(" + field + " as text)"
                                    + ",'[^\\u0020-\\u007e,\\(\\);\\-\\[\\]]+',' '),'" + this.delimiter + "','"
                                    + this.replacedel + "')),'[\\r|\\n]+','   ','gm') as " + field;
                        } else {
                            field = "regexp_replace(trim(replace(cast(" + field + " as text),'" + this.delimiter
                                    + "','" + this.replacedel + "')),'[\\r|\\n]+','   ','gm')";
                        }

                        attrs = (attrs == null) ? field : attrs + "," + field;
                    }
                }

                select = (distinct == null) ? select : select.trim() + " " + distinct.trim() + ")";
                select += " " + attrs.trim();
                select += " FROM " + split[0].trim();
                select = (where == null) ? select : select.trim() + " " + where.trim();
                select = (group == null) ? select : select.trim() + " " + group.trim();
                select = (order == null) ? select : select.trim() + " " + order.trim();

                if (extracondition != null) {
                    select += (select.contains(" WHERE ") == true) ? " AND" + extracondition
                            : " WHERE " + extracondition;
                }

                select = select.trim();

                log.info("Dump Select Command: " + select);

                sql = "COPY  (" + select + ") TO STDOUT WITH DELIMITER '" + delimiter.trim()
                        + "' NULL as '' CSV HEADER";
                fjp.execute(new ToFile(sql, split[1].trim()));

                select = "SELECT ";
                distinct = null;
                attrs = null;
                where = null;
                group = null;
                order = null;
            } else {
                try {

                    throw new NoDataException("WARNING: Table " + split[0] + " has no Data");

                } catch (NoDataException e) {
                    e.printStackTrace();
                    if (tablesMustHave != null && tablesMustHave.contains(split[0])) {
                        log.error("Table is a Must Have Table by has not Data. Terminating!");
                        System.exit(-1);
                    }
                }
            }
        } else {
            try {
                throw new SQLMalformedException("WARNING: Table " + split[0] + " is missing");
            } catch (SQLMalformedException e) {
                e.printStackTrace();
            }
        }
    }

    try {
        fjp.awaitTermination(60000, TimeUnit.MILLISECONDS);
        fjp.shutdown();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (dumped == 0) {
        log.info("No Data Found in any Table");
        System.exit(-1);
    }

}