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.edgenius.wiki.gwt.server.SpaceControllerImpl.java

public BlogMetaList updateLinkedBlog(String spaceUname, ArrayList<BlogMeta> blogs) {
    BlogMetaList list = new BlogMetaList();

    Space space = spaceService.getSpaceByUname(spaceUname);
    List<BlogMeta> exists = space.getSetting().getLinkedMetas();
    if (exists != null) {
        List<BlogMeta> needRemove = new ArrayList<BlogMeta>();
        //check if anyone removed or updated
        for (BlogMeta exist : exists) {
            if (blogs != null) {
                if (blogs.contains(exist)) {
                    //already exist, then don't do anything -- ???
                    blogs.remove(exist);
                } else {
                    //it is not inside list, so remove existing one.
                    needRemove.add(exist);
                }/* w  ww  .  ja  v  a 2 s.c om*/
            } else {
                //remove all existing
                needRemove.add(exist);
            }

        }
        //the reason that don't call disconnectFromSpace() within above looping, as it will cause ConcurrenceModification exception
        //as disconnectFromSpace() also update list from space.getSetting().getLinkedMetas()
        if (needRemove.size() > 0) {
            for (BlogMeta blogMeta : needRemove) {
                blogSyncService.disconnectFromSpace(spaceUname, blogMeta.getKey());
            }
        }

    }
    if (blogs != null) {
        for (BlogMeta blog : blogs) {
            if (!blogSyncService.verifyBlog(blog)) {
                blog.setError(messageService.getMessage("err.invalid.blog.info"));
                list.errorMsg = messageService.getMessage("err.invalid.blog.info");
            } else {
                //stop create space!
                try {
                    blogSyncService.linkToSpace(blog, spaceUname);
                } catch (BlogSyncException e) {
                    log.error("Update blog failed " + blog, e);
                    blog.setError(messageService.getMessage("err.invalid.blog.info"));
                    list.errorMsg = messageService.getMessage("err.invalid.blog.info");
                }
            }
        }
    }

    //get from space, rather than from input parameter as some blog may not success saved.
    Collection<BlogMeta> blogMetas = SpaceUtil.getSpaceLinkMetaToModel(space);
    if (blogMetas != null)
        list.blogList = new ArrayList<BlogMeta>(blogMetas);
    return list;

}

From source file:pl.selvin.android.syncframework.content.TableInfo.java

public void GetChanges(SQLiteDatabase db, JsonGenerator gen, ArrayList<TableInfo> notifyTableInfo)
        throws IOException {
    String[] cols = new String[columns.length + 3];
    int i = 0;/*w  w  w.  j av  a 2 s .c o  m*/
    for (; i < columns.length; i++)
        cols[i] = columns[i].name;
    cols[i] = _.uri;
    cols[i + 1] = _.tempId;
    cols[i + 2] = _.isDeleted;
    Cursor c = db.query(name, cols, _.isDirtyP, new String[] { "1" }, null, null, null);
    //to fix startPos  > actual rows for large cursors db operations should be done after cursor is closed ...
    final ArrayList<OperationHolder> operations = new ArrayList<OperationHolder>();
    if (c.moveToFirst()) {
        if (!notifyTableInfo.contains(this))
            notifyTableInfo.add(this);
        do {

            gen.writeStartObject();
            gen.writeObjectFieldStart(_.__metadata);
            gen.writeBooleanField(_.isDirty, true);
            gen.writeStringField(_.type, scope_name);
            //Log.d("before", scope_name + ":" + c.getLong(i + 3));
            String uri = c.getString(i);
            //Log.d("after", scope_name + ":" + c.getLong(i + 3));
            if (uri == null) {
                gen.writeStringField(_.tempId, c.getString(i + 1));
            } else {
                gen.writeStringField(_.uri, uri);
                final ContentValues update = new ContentValues(1);
                update.put(_.isDirty, 0);
                operations.add(new OperationHolder(name, OperationHolder.UPDATE, update, uri));
            }
            boolean isDeleted = c.getInt(i + 2) == 1;
            if (isDeleted) {
                gen.writeBooleanField(_.isDeleted, true);
                gen.writeEndObject();// meta
                operations.add(new OperationHolder(name, OperationHolder.DELETE, null, uri));
            } else {
                gen.writeEndObject();// meta
                for (i = 0; i < columns.length; i++) {
                    if (columns[i].nullable && c.isNull(i)) {
                        gen.writeNullField(columns[i].name);
                    } else {
                        switch (columns[i].type) {
                        case ColumnType.BLOB:
                            gen.writeBinaryField(columns[i].name, c.getBlob(i));
                            break;
                        case ColumnType.BOOLEAN:
                            gen.writeBooleanField(columns[i].name, c.getLong(i) == 1);
                            break;
                        case ColumnType.INTEGER:
                            gen.writeNumberField(columns[i].name, c.getLong(i));
                            break;
                        case ColumnType.DATETIME:
                            try {
                                gen.writeStringField(columns[i].name,
                                        String.format(msdate, sdf.parse(c.getString(i)).getTime()));
                            } catch (Exception e) {
                                if (BuildConfig.DEBUG) {
                                    Log.e("ListSync", e.getLocalizedMessage());
                                }
                            }
                            break;
                        case ColumnType.NUMERIC:
                            gen.writeNumberField(columns[i].name, c.getDouble(i));
                            break;
                        default:
                            gen.writeStringField(columns[i].name, c.getString(i));
                            break;
                        }
                    }
                }
            }
            gen.writeEndObject(); // end of row
        } while (c.moveToNext());
    }
    c.close();
    for (OperationHolder operation : operations)
        operation.execute(db);
}

From source file:gwap.rest.PastTerminaSessionBean.java

private void addToJSONArray(JSONArray owns, JSONArray foreigns, ArrayList<String> ownTagNames,
        int[] minMaxAppearences, String queryName, String matchType) {
    Query q = entityManager.createNamedQuery(queryName);
    q.setParameter("resourceId", term.getId());
    //   q.setMaxResults(5);
    List<BackstageAnswer> correctTags = q.getResultList();

    for (BackstageAnswer b : correctTags) {
        JSONObject ob = wrapUpJson(b, matchType);

        minMaxAppearences[0] = Math.min(minMaxAppearences[0], b.getAppearence());
        minMaxAppearences[1] = Math.max(minMaxAppearences[1], b.getAppearence());
        boolean own = ownTagNames.contains(b.getTerm());
        if (filter(b, own, matchType)) {
            if (own) {
                if (owns.size() < maxOwns) {
                    owns.add(ob);//ww  w.  j ava 2 s  .  c  o  m
                }
            } else {
                if (foreigns.size() < maxForeigns) {
                    foreigns.add(ob);
                }
            }
        }
    }
}

From source file:lfsom.visualization.clustering.LFSKMeans.java

/** Take random points from the input data as centroids. */
private void initClustersRandomlyOnInstances() {
    ArrayList<double[]> usedInstances = new ArrayList<double[]>();
    RandomGenerator rg = new JDKRandomGenerator();
    // FIXME: this is for testing purposes only
    rg.setSeed(RANDOM_SEED);/*from  w  w w. ja  v  a2s.  c  o m*/
    // for each cluster
    for (int clusterIndex = 0; clusterIndex < k; clusterIndex++) {
        // draw a random input
        double[] centroid = data[rg.nextInt(data.length - 1)].clone();
        while (usedInstances.contains(centroid)) {
            centroid = data[rg.nextInt(data.length - 1)].clone();
        }
        usedInstances.add(centroid);
        clusters[clusterIndex] = new LFSCluster(centroid);
    }
}

From source file:com.etcc.csc.presentation.action.payment.InitializePaymentAction.java

private void processVea(PaymentContext paymentContext, AccountLoginDTO accountLoginDTO, String docType,
        long docId) throws Exception {
    Invoice[] distinctLicPlates = paymentContext.getDistinctLicPlates();
    PaymentInterface pi = (PaymentInterface) DelegateFactory.create(DelegateEnum.PAYMENT_DELEGATE);
    ArrayList veaEligibleLicPlates = new ArrayList();
    if (!ArrayUtils.isEmpty(distinctLicPlates)) {
        for (Invoice invoice : distinctLicPlates) {
            if (pi.veaExists(new BigDecimal(docId), docType, accountLoginDTO.getDbSessionId(),
                    accountLoginDTO.getLastLoginIp(), accountLoginDTO.getLoginId(), invoice.getLicPlateNumber(),
                    invoice.getLicPlateState())) {
                veaEligibleLicPlates.add(invoice.getLicPlateNumber() + invoice.getLicPlateState());
            }/*from   ww  w.j  a v a 2 s.co m*/
        }
    }

    Invoice[] invoices = paymentContext.getInvoices();
    for (int i = 0; !ArrayUtils.isEmpty(invoices) && i < invoices.length; i++) {
        invoices[i].setVeaEligible(veaEligibleLicPlates
                .contains(invoices[i].getLicPlateNumber() + invoices[i].getLicPlateState()));
    }
}

From source file:javaapplication2.Mundo.java

public void dibujarCamino(ArrayList<Integer> estadosVisitados) {
    String[][] camino = new String[this.filas][this.columnas];
    for (int i = 0; i < this.filas; i++) {
        for (int j = 0; j < this.columnas; j++) {
            if (estados[i][j].isEsObstaculo()) {
                camino[i][j] = "\u2248"; //
            } else if (estados[i][j].isEsFinal()) {
                camino[i][j] = "F";
            } else if (estados[i][j].isEsInicial()) {
                camino[i][j] = "I";
            } else {
                camino[i][j] = "\u25A1";
            }//  www .  j  a v  a2 s.  com
            if (estadosVisitados.contains(this.estados[i][j].getNumero()) && !estados[i][j].isEsInicial()
                    && !estados[i][j].isEsFinal()) {
                camino[i][j] = "\u25A0";
            }
        }
    }
    String toString = "";
    for (int i = 0; i < this.filas; i++) {
        for (int j = 0; j < this.columnas; j++) {

            toString = toString + camino[i][j] + " ";

        }
        toString = toString + "\n";
    }
    System.out.println(toString);
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java

@Override
public ArrayList<String> getAttributesColumnsHeaders() {
    ArrayList<String> attColumnsHeaders = new ArrayList<>();
    for (MulticastDemand mDemand : getVisibleElementsInTable())
        for (Map.Entry<String, String> entry : mDemand.getAttributes().entrySet())
            if (attColumnsHeaders.contains(entry.getKey()) == false)
                attColumnsHeaders.add(entry.getKey());
    return attColumnsHeaders;
}

From source file:dom.rootlocus.utils.Utils.java

/**
 * method that adds a value to the correct serie
 *
 * @param roots: an array of values for a specific k value.
 * @param series:an arrayList on which series of values are stored.
 *//*from  w  w  w  .  j a v a2s  .  com*/
public void addValuetoSerie(Complex[] roots, List<List<Complex>> series) {

    if (series.get(0).isEmpty()) {
        for (int i = 0; i < roots.length; i++) {
            series.get(i).add(roots[i]);
        }

    } else {

        ArrayList seriesAdded = new ArrayList();
        int lastValue = series.get(0).size() - 1;
        for (int i = 0; i < roots.length; i++) {
            double distance = 0; //minimum distance between one value of the serie and the current root
            int serieToadd = 0;//serie in which the root is going to be added
            Complex sol = roots[i];
            for (int j = 0; j < series.size(); j++) {
                double module = getModule(substractComplex(series.get(j).get(lastValue), sol));
                if (j == 0) {
                    distance = module;
                } else if (module <= distance && !seriesAdded.contains(j)) {
                    serieToadd = j;
                    distance = module;
                }
            }
            seriesAdded.add(serieToadd);
            series.get(serieToadd).add(sol);
        }
    }
}

From source file:com.ge.research.semtk.sparqlX.parallel.SparqlParallelQueries.java

public JSONObject returnFusedResults() throws Throwable, Exception {
    // Make sure that all the queries returned successfully, else rethrow whatever exception occurred
    for (SparqlSubquery subquery : subqueries) {
        Throwable t = subquery.getException();
        if (t != null) {
            throw t;
        }/*  ww w.ja v  a 2s .  com*/
    }

    // Collect all the vars from the subqueries into a multiset so we will know which vars are unique and won't need to be renamed
    HashMultiset<String> multiSet = HashMultiset.create();
    for (SparqlSubquery subquery : subqueries) {
        ArrayList<String> columnsInResponse = subquery.getColumnNamesInResponse();
        multiSet.addAll(columnsInResponse);
    }

    // Build unique var names from the columns to return and the subqueries' suffixes
    JSONArray vars = new JSONArray();
    Set<String> distinctVars = new LinkedHashSet<>();
    for (SparqlSubquery subquery : subqueries) {
        String suffix = subquery.getResultsColumnNameSuffix();
        ArrayList<String> columnsInResponse = subquery.getColumnNamesInResponse();
        for (String column : columnsToReturn) {
            if (columnsInResponse.contains(column)) {
                if (multiSet.count(column) == 1) {
                    distinctVars.add(column);
                } else if (columnsToFuseOn.contains(column)) {
                    distinctVars.add(column);
                } else {
                    distinctVars.add(column + suffix);
                }
            }
        }
    }
    for (String var : distinctVars) {
        vars.add(var);
    }

    // Collect the distinct bindings from the subqueries into sets by the columns to fuse on.
    Map<String/*fusedCols*/, Map<String/*suffix*/, Set<Pair<SparqlSubquery/*subquery*/, ArrayList<String>/*binding*/>>>> fusedColsToBindings = new LinkedHashMap<>();
    StringBuilder sb = new StringBuilder();
    for (SparqlSubquery subquery : subqueries) {
        // Get the subquery's bindings
        String suffix = subquery.getResultsColumnNameSuffix();
        Table resultsTable = subquery.getResponseTable();
        if ((resultsTable != null) && (resultsTable.getNumRows() != 0)) {
            System.out.println("Query " + suffix + " has " + resultsTable.getNumRows() + " rows");
            ArrayList<String> columnsInResponse = subquery.getColumnNamesInResponse();
            for (ArrayList<String> row : resultsTable.getRows()) {
                // Compose the lookup key from the columns to fuse on
                sb.setLength(0);
                for (String column : columnsToFuseOn) {
                    if (columnsInResponse.contains(column)) {
                        String value = (String) row.get(resultsTable.getColumnIndex(column));
                        if (sb.length() > 0)
                            sb.append("\t");
                        sb.append(value);
                    }
                }
                String fusedCols = sb.toString();

                // Add the binding to the set of distinct bindings for the same fusedCols and same suffix
                Map<String/*suffix*/, Set<Pair<SparqlSubquery/*subquery*/, ArrayList<String>/*binding*/>>> suffixToBindings = fusedColsToBindings
                        .get(fusedCols);
                if (suffixToBindings == null) {
                    suffixToBindings = new LinkedHashMap<>();
                    fusedColsToBindings.put(fusedCols, suffixToBindings);
                }
                Set<Pair<SparqlSubquery/*subquery*/, ArrayList<String>/*binding*/>> distinctBindings = suffixToBindings
                        .get(suffix);
                if (distinctBindings == null) {
                    distinctBindings = new LinkedHashSet<>();
                    suffixToBindings.put(suffix, distinctBindings);
                }
                distinctBindings.add(new Pair<>(subquery, row));
            }
        } else {
            System.out.println("Query " + suffix + " has 0 rows");
        }
    }
    //System.out.println ("XXXXXXXXXXXXXXXXXXXXXXXXXXX  GOT HERE  XXXXXXXXXXXXXXXXXXXXX");

    // Build the array of output bindings with unique var names
    int numOutputBindings = 0;
    //JsonArrayBuilder outputBindings = Json.createArrayBuilder();
    JSONArray outputBindings = new JSONArray();
    ArrayList<ArrayList<String>> outputRows = new ArrayList<ArrayList<String>>();
    ArrayList<String> outputColumnNames = new ArrayList<String>();
    for (Map<String/*suffix*/, Set<Pair<SparqlSubquery/*subquery*/, ArrayList<String>/*binding*/>>> suffixToBindings : fusedColsToBindings
            .values()) {
        // Collect each subquery's set of distinct bindings for the same fusedCols
        List<Set<Pair<SparqlSubquery/*subquery*/, ArrayList<String>/*binding*/>>> fusedColsBindings = new ArrayList<>();
        for (SparqlSubquery subquery : subqueries) {
            String suffix = subquery.getResultsColumnNameSuffix();
            Set<Pair<SparqlSubquery/*subquery*/, ArrayList<String>/*binding*/>> distinctBindings = suffixToBindings
                    .get(suffix);
            if (fusedColsBindings != null && distinctBindings != null) {
                fusedColsBindings.add(distinctBindings);
            } else if (!isSubqueryOptional) {
                // Don't output any bindings for this particular fusedCols
                fusedColsBindings = null;
            }
        }

        if (fusedColsBindings != null) {
            // Iterate over every possible list that can be formed by choosing one element from each of the above sets in order
            Set<List<Pair<SparqlSubquery/*subquery*/, ArrayList<String>/*binding*/>>> allFusedColsBindings = Sets
                    .cartesianProduct(fusedColsBindings);
            for (List<Pair<SparqlSubquery/*subquery*/, ArrayList<String>/*binding*/>> fusedColsBinding : allFusedColsBindings) {
                // Create the new output binding
                //JsonObjectBuilder outputBinding = Json.createObjectBuilder();
                ArrayList<String> outputRow = new ArrayList<String>();
                String addedCols = ",";
                for (Pair<SparqlSubquery/*subquery*/, ArrayList<String>> rowPair : fusedColsBinding) {
                    // Add each var to the output binding, uniquified by the subquery's suffix when needed
                    String suffix = rowPair.getFirst().getResultsColumnNameSuffix();
                    ArrayList<String> columnsInResponse = rowPair.getFirst().getColumnNamesInResponse();
                    for (String column : columnsToReturn) {
                        if (columnsInResponse.contains(column)) {
                            if (addedCols.indexOf("," + column + ",") >= 0)
                                continue;
                            String var = rowPair.getSecond()
                                    .get(rowPair.getFirst().getResponseTable().getColumnIndex(column));
                            if (multiSet.count(column) == 1) {
                                outputRow.add(var);
                                addedCols += column + ",";
                                if (numOutputBindings == 0)
                                    outputColumnNames.add(column);
                            } else if (columnsToFuseOn.contains(column)) {
                                outputRow.add(var);
                                addedCols += column + ",";
                                if (numOutputBindings == 0)
                                    outputColumnNames.add(column);
                            } else {
                                outputRow.add(var);
                                addedCols += column + suffix + ",";
                                if (numOutputBindings == 0)
                                    outputColumnNames.add(column + suffix);
                            }
                        }
                    }
                }
                outputRows.add(outputRow);
                numOutputBindings++;
            }
        }
    }
    String[] outputColumnNamesArray = (String[]) outputColumnNames.toArray(new String[0]);
    String[] outputColumnTypes = new String[outputColumnNamesArray.length];
    for (int i = 0; i < outputColumnTypes.length; i++)
        outputColumnTypes[i] = "String";

    Table outputTable = new Table(outputColumnNamesArray, outputColumnTypes, outputRows);

    System.out.println("Fused response has " + numOutputBindings + " results");

    gResultTable = new TableResultSet(true);
    //      System.out.println(outputTable.toCSVString());
    gResultTable.addResults(outputTable);
    return gResultTable.toJson();
}

From source file:com.enonic.vertical.adminweb.handlers.xmlbuilders.SimpleContentXMLBuilder.java

public int[] getDeleteBinaries(ExtendedMap formItems) {
    int versionKey = formItems.getInt("versionkey");
    ArrayList<Integer> keepBinaries = (ArrayList<Integer>) formItems.get("__keepbinaries", null);
    int[] oldBinaries = admin.getBinaryDataKeysByVersion(versionKey);

    ArrayList<Integer> deleted = new ArrayList<Integer>();
    for (int oldBinary : oldBinaries) {
        if (keepBinaries == null || !keepBinaries.contains(oldBinary)) {
            deleted.add(oldBinary);/*from  w w w . ja  v a  2s. co m*/
        }
    }

    int[] deletedArray = new int[deleted.size()];
    int cnt = 0;
    for (Integer i : deleted) {
        deletedArray[cnt++] = i;
    }
    return deletedArray;
}