Example usage for java.util ArrayList removeAll

List of usage examples for java.util ArrayList removeAll

Introduction

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

Prototype

public boolean removeAll(Collection<?> c) 

Source Link

Document

Removes from this list all of its elements that are contained in the specified collection.

Usage

From source file:com.globalsight.everest.webapp.pagehandler.edit.inctxrv.EditorPageHandler.java

private void nextPage(EditorState p_state, HttpSession p_session, boolean p_fromActivity,
        boolean isContextReview) throws EnvoyServletException {
    ArrayList<EditorState.PagePair> pages = p_state.getPages();
    pages = (ArrayList<EditorState.PagePair>) getPagePairList(p_session, pages);
    if (isContextReview) {
        pages.removeAll(getRemovePages(pages));
    }//from  w ww.  ja va 2 s .  com
    int i_index = pages.indexOf(p_state.getCurrentPage());

    if (p_fromActivity) {
        boolean foundNonempty = false;
        boolean allEmptyAfter = true;

        while (i_index >= 0 && i_index < (pages.size() - 1)) {
            ++i_index;

            EditorState.PagePair pp = (EditorState.PagePair) pages.get(i_index);

            if (!foundNonempty) {
                p_state.setCurrentPage(pp);
                p_state.setIsFirstPage(false);
                p_state.setIsLastPage(i_index == (pages.size() - 1));

                initState(p_state, p_session);

                if (p_state.getUserIsPm() && s_pmCanEditTargetPages) {
                    if (EditorHelper.pmCanEditCurrentPage(p_state)) {
                        p_state.setReadOnly(false);
                        p_state.setAllowEditAll(true);
                        p_state.setEditAllState(EDIT_ALL);
                    } else {
                        p_state.setReadOnly(true);
                    }
                }
                foundNonempty = true;
                continue;
            }

            if (foundNonempty && allEmptyAfter) {
                allEmptyAfter = false;
                break;
            }

        }
        if (foundNonempty && allEmptyAfter) {
            p_state.setIsLastPage(true);
        }
    }

    else {
        if (i_index >= 0 && i_index < (pages.size() - 1)) {
            ++i_index;

            p_state.setCurrentPage((EditorState.PagePair) pages.get(i_index));

            p_state.setIsFirstPage(false);
            p_state.setIsLastPage(i_index == (pages.size() - 1));

            initState(p_state, p_session);

            if (p_state.getUserIsPm() && s_pmCanEditTargetPages) {
                if (EditorHelper.pmCanEditCurrentPage(p_state)) {
                    p_state.setReadOnly(false);
                    p_state.setAllowEditAll(true);
                    p_state.setEditAllState(EDIT_ALL);
                } else {
                    p_state.setReadOnly(true);
                }
            }
        }
    }

}

From source file:com.smartmobilesoftware.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) {
        logDebug("moreSkus: Building SKUs List");
        for (String sku : moreSkus) {
            logDebug("moreSkus: " + sku);
            if (!skuList.contains(sku)) {
                skuList.add(sku);/*from w w  w .  j  a v a2  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 SKUs into slices of maximum 20 entries before querying them to prevent 
    // "Input Error: skusBundle array associated with key ITEM_ID_LIST cannot contain more than 20 items."
    while (skuList.size() > 0) {
        ArrayList<String> skuSubList = new ArrayList<String>(skuList.subList(0, Math.min(19, skuList.size())));
        skuList.removeAll(skuSubList);

        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuSubList);
        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 ERR_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:org.envirocar.app.json.TrackEncoder.java

/**
 * resolve all not obfuscated measurements of a track.
 * /*from   w w w  .ja va2  s  . c om*/
 * This returns all measurements, if obfuscation is disabled. Otherwise
 * measurements within the first and last minute and those within the start/end
 * radius of 250 m are ignored (only if they are in the beginning/end of the track).
 * 
 * @param track
 * @return
 */
public List<Measurement> getNonObfuscatedMeasurements(Track track, boolean obfuscate) {
    List<Measurement> measurements = track.getMeasurements();

    if (obfuscate) {
        boolean wasAtLeastOneTimeNotObfuscated = false;
        ArrayList<Measurement> privateCandidates = new ArrayList<Measurement>();
        ArrayList<Measurement> nonPrivateMeasurements = new ArrayList<Measurement>();
        for (Measurement measurement : measurements) {
            try {
                /*
                 * ignore early and late
                 */
                if (isTemporalObfuscationCandidate(measurement, track)) {
                    continue;
                }

                /*
                 * ignore distance
                 */
                if (isSpatialObfuscationCandidate(measurement, track)) {
                    if (wasAtLeastOneTimeNotObfuscated) {
                        privateCandidates.add(measurement);
                        nonPrivateMeasurements.add(measurement);
                    }
                    continue;
                }

                /*
                 * we may have found obfuscation candidates in the middle of the track
                 * (may cross start or end point) in a PRIOR iteration
                 * of this loop. these candidates can be removed now as we are again
                 * out of obfuscation scope
                 */
                if (wasAtLeastOneTimeNotObfuscated) {
                    privateCandidates.clear();
                } else {
                    wasAtLeastOneTimeNotObfuscated = true;
                }

                nonPrivateMeasurements.add(measurement);
            } catch (MeasurementsException e) {
                logger.warn(e.getMessage(), e);
            }

        }
        /*
         * the private candidates which have made it until here
         * shall be ignored
         */
        nonPrivateMeasurements.removeAll(privateCandidates);
        return nonPrivateMeasurements;
    }

    return measurements;
}

From source file:utils.DBManager.java

public int updateGroup(int group, String newTitle, List<Integer> users, int owner, boolean chiuso,
        boolean privato) throws SQLException {
    int rowChanged;
    String sql = "UPDATE groups SET groupname = ? WHERE groupid = ?";
    PreparedStatement stm = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
    stm.setString(1, newTitle);/*from w ww. j  av  a 2 s .  com*/
    stm.setInt(2, group);
    stm.executeUpdate();

    stm.close();

    sql = "UPDATE groups SET private = ? WHERE groupid = ?";
    stm = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
    int priv = calculatePrivateColumnInt(chiuso, privato);
    stm.setInt(1, priv);
    stm.setInt(2, group);
    stm.executeUpdate();

    stm.close();

    ArrayList<Integer> usersInDb = getAllUserIDs();
    PreparedStatement stm2;

    String sql2;
    for (int id : users) {
        //int id = getIdFromUser(user);
        if (!isPending(id, group) && !isKicked(id, group) && !isInGroup(id, group)) {
            sql2 = "INSERT INTO user_groups(userid,groupid,status) VALUES (?,?,2)";
            stm2 = con.prepareStatement(sql2);
            stm2.setInt(1, id);
            stm2.setInt(2, group);
            stm2.executeUpdate();
            stm2.close();
        } else if (isKicked(id, group)) {
            sql2 = "UPDATE user_groups SET status = 2 WHERE groupid = ? AND userid = ?";
            stm2 = con.prepareStatement(sql2);
            stm2.setInt(1, group);
            stm2.setInt(2, id);
            stm2.executeUpdate();
            stm2.close();
        }
    }

    usersInDb.removeAll(users);

    for (int id : usersInDb) {
        sql2 = "UPDATE user_groups SET status = 1 WHERE groupid = ? AND userid = ?";
        stm2 = con.prepareStatement(sql2);
        stm2.setInt(1, group);
        stm2.setInt(2, id);
        stm2.executeUpdate();
        stm2.close();
    }

    String sql4 = "UPDATE user_groups SET status = 0 WHERE groupid = ? AND userid = ?";
    PreparedStatement stm4 = con.prepareStatement(sql4);
    stm4.setInt(1, group);
    stm4.setInt(2, owner);
    rowChanged = stm4.executeUpdate();
    stm4.close();
    return rowChanged;

}

From source file:ro.nextreports.designer.querybuilder.RuntimeParametersPanel.java

@SuppressWarnings("unchecked")
private void initParameterValue(JComponent component, Object value, String paramName,
        List<Serializable> defaultValues) {
    if (value == null) {
        return;//ww  w .ja  v  a  2 s.c o  m
    }
    if (component instanceof JTextField) {
        ((JTextField) component).setText(value.toString());
    } else if (component instanceof JComboBox) {
        JComboBox combo = ((JComboBox) component);
        List<IdName> values = (List<IdName>) value;
        combo.removeAllItems();
        combo.addItem("-- " + I18NSupport.getString("parameter.value.select") + " --");
        for (int j = 0, len = values.size(); j < len; j++) {
            combo.addItem(values.get(j));
        }
        Object old = parametersValues.get(paramName);
        if (old != null) {
            combo.setSelectedItem(old);
        } else if ((defaultValues != null) && (defaultValues.size() > 0)) {
            Serializable id = defaultValues.get(0);
            if (id instanceof IdName) {
                id = ((IdName) id).getId();
            }
            combo.setSelectedItem(findIdName(combo.getModel(), id));
        }
    } else if (component instanceof ListSelectionPanel) {
        ListSelectionPanel lsp = (ListSelectionPanel) component;
        DefaultListModel model = new DefaultListModel();
        if (value != null) {
            List<IdName> values = (List<IdName>) value;
            for (int j = 0, len = values.size(); j < len; j++) {
                model.addElement(values.get(j));
            }
        }
        ArrayList srcList = new ArrayList(Arrays.asList(model.toArray()));

        Object old = parametersValues.get(paramName);
        Object[] selected = new Object[0];
        if (old != null) {
            selected = (Object[]) old;
        } else if ((defaultValues != null) && (defaultValues.size() > 0)) {
            selected = new Object[defaultValues.size()];
            for (int k = 0, len = selected.length; k < len; k++) {
                Serializable id = defaultValues.get(k);
                if (id instanceof IdName) {
                    id = ((IdName) id).getId();
                }
                IdName in = findIdName(srcList, id);
                selected[k] = in;
            }
        }
        List dstList = Arrays.asList(selected);

        if (!srcList.containsAll(dstList)) {
            dstList = new ArrayList();
            parametersValues.put(paramName, null);
        } else {
            srcList.removeAll(dstList);
        }
        if ((dstList.size() == 1) && ParameterUtil.NULL.equals(dstList.get(0))) {
            dstList = new ArrayList();
        }
        lsp.setLists(srcList, dstList);

    } else if (component instanceof ListAddPanel) {
        ListAddPanel lap = (ListAddPanel) component;
        DefaultListModel model = new DefaultListModel();
        if (value != null) {
            List<Object> values = (List<Object>) value;
            for (int j = 0, len = values.size(); j < len; j++) {
                model.addElement(values.get(j));
            }
        }
        ArrayList srcList = new ArrayList(Arrays.asList(model.toArray()));

        Object old = parametersValues.get(paramName);
        Object[] selected = new Object[0];
        if (old != null) {
            selected = (Object[]) old;
        } else if ((defaultValues != null) && (defaultValues.size() > 0)) {
            selected = new Object[defaultValues.size()];
            for (int k = 0, len = selected.length; k < len; k++) {
                Serializable id = defaultValues.get(k);
                if (id instanceof IdName) {
                    id = ((IdName) id).getId();
                }
                selected[k] = id;
            }
        }
        List dstList = Arrays.asList(selected);
        if (!srcList.containsAll(dstList)) {
            dstList = new ArrayList();
            parametersValues.put(paramName, null);
        } else {
            srcList.removeAll(dstList);
        }
        if ((dstList.size() == 1) && ParameterUtil.NULL.equals(dstList.get(0))) {
            dstList = new ArrayList();
        }

        lap.setElements(dstList);
    } else if (component instanceof JDateTimePicker) {
        ((JDateTimePicker) component).setDate((Date) value);
    } else if (component instanceof JXDatePicker) {
        ((JXDatePicker) component).setDate((Date) value);
    } else if (component instanceof JCheckBox) {
        ((JCheckBox) component).setSelected((Boolean) value);
    }
}

From source file:org.drools.semantics.builder.model.inference.DelegateInferenceStrategy.java

private void addSubConceptsToModel(OWLOntology ontoDescr, OntoModel model) {

    Map<String, Collection<String>> supers = new HashMap<String, Collection<String>>();

    String thing = ontoDescr.getOWLOntologyManager().getOWLDataFactory().getOWLThing().getIRI()
            .toQuotedString();/*from ww w. ja va2s.  c om*/
    supers.put(thing, Collections.EMPTY_SET);

    for (OWLSubClassOfAxiom ax : ontoDescr.getAxioms(AxiomType.SUBCLASS_OF)) {
        processSubConceptAxiom(ax.getSubClass(), ax.getSuperClass(), supers, thing);
    }
    for (OWLEquivalentClassesAxiom ax : ontoDescr.getAxioms(AxiomType.EQUIVALENT_CLASSES)) {
        processSubConceptAxiom(ax.getClassExpressionsAsList().get(0),
                filterAliases(ax.getClassExpressionsAsList().get(1)), supers, thing);
    }

    for (OWLClassExpression delegator : aliases.keySet()) {
        if (!delegator.isAnonymous()) {
            addSuper(delegator.asOWLClass().getIRI().toQuotedString(), thing, supers);
        }
    }

    for (OWLClassExpression delegator : aliases.keySet()) {
        if (!delegator.isAnonymous()) {
            OWLClassExpression delegate = aliases.get(delegator);
            String sub = delegate.asOWLClass().getIRI().toQuotedString();
            String sup = delegator.asOWLClass().getIRI().toQuotedString();
            conceptCache.get(sub).getEquivalentConcepts().add(conceptCache.get(sup));
            addSuper(sub, sup, supers);
        }
    }

    HierarchySorter<String> sorter = new HierarchySorter<String>();
    List<String> sortedCons = sorter.sort(supers);

    ArrayList missing = new ArrayList(conceptCache.keySet());
    missing.removeAll(supers.keySet());

    LinkedHashMap<String, Concept> sortedCache = new LinkedHashMap<String, Concept>();
    for (String con : sortedCons) {
        sortedCache.put(con, conceptCache.get(con));
    }
    conceptCache.clear();
    conceptCache = sortedCache;

    reduceTransitiveInheritance(sortedCache, supers);

    for (String con : supers.keySet()) {
        Collection<String> parents = supers.get(con);
        for (String sup : parents) {
            SubConceptOf subConceptOf = new SubConceptOf(con, sup);
            model.addSubConceptOf(subConceptOf);
            conceptCache.get(subConceptOf.getSubject())
                    .addSuperConcept(conceptCache.get(subConceptOf.getObject()));
        }
    }
}

From source file:pltag.parser.ParsingTask.java

/**
 * //w w w.j a  v a 2s  .  com
 * @param shadowtree
 * @param rootnode
 * @param tree
 * @param coveredNodes < shadownodeInt, treeNodeInt>
 * @return
 */
@SuppressWarnings("unchecked") //at cast for clone().
private ArrayList<Byte> checkTreeEquivalence(ShadowStringTree shadowtree, Integer rootnode, StringTree tree,
        Map<Integer, Integer> coveredNodes) {
    ArrayList<Byte> pattern = new ArrayList<Byte>();
    //int index = Integer.parseInt(shadowtree.getLowerIndex(rootnode));
    //       go through tree and see whether all nodes in shadow tree have same index
    //(same category, same nodetype, same parents not regarding adjunction trees)
    // have to go through in tree order to do this correctly.
    if (coveredNodes == null) {
        return null;
    }
    for (Integer shadowId : shadowtree.getShadowSourceTreesRootList()) {
        if (coveredNodes.containsKey(shadowId) && tree.getLowerIndex(coveredNodes.get(shadowId)) != -1) {
            // get the updated index of the root's lowerIndex
            byte index = shadowtree.getLowerIndex(shadowId);
            pattern.add(index);
        }
    }
    //Pattern p = Pattern.compile(pattern);
    // check that there are no leftover-nodes in shadow tree with that index
    ArrayList<Integer> allCoveredTest = (ArrayList<Integer>) shadowtree.getTreeOrigIndex().getNodes().clone();
    allCoveredTest.removeAll(coveredNodes.keySet());
    for (Integer node : allCoveredTest) {
        if ((shadowtree.getLowerIndex(node) > -1
                && StringTreeAnalysis.matches(pattern, shadowtree.getLowerIndex(node))
                || (shadowtree.getUpperIndex(node) > -1
                        && StringTreeAnalysis.matches(pattern, shadowtree.getUpperIndex(node))))) {
            return null;
        }
    }

    return pattern;
}

From source file:com.globalsight.everest.tda.TdaHelper.java

private void sortMatchList(ArrayList matchList) {
    for (int i = 0; i < matchList.size() - 1; i++) {
        LeverageTDAResult tdaResult1 = (LeverageTDAResult) matchList.get(i);

        for (int j = i + 1; j < matchList.size(); j++) {
            LeverageTDAResult tdaResult2 = (LeverageTDAResult) matchList.get(j);

            if (PecentToInt(tdaResult1.getMatchPercent()) < PecentToInt(tdaResult2.getMatchPercent())) {
                LeverageTDAResult temp = tdaResult1;
                tdaResult1 = tdaResult2;
                tdaResult2 = temp;/*from   ww  w.  jav a 2 s .co  m*/
            }

            tdaResult1.setOrderNum(TmCoreManager.LM_ORDER_NUM_START_TDA + i);
            tdaResult2.setOrderNum(TmCoreManager.LM_ORDER_NUM_START_TDA + j);
            matchList.set(i, tdaResult1);
            matchList.set(j, tdaResult2);
        }
    }

    // remember the segment whose match percent and match content is all
    // same
    ArrayList<LeverageTDAResult> sameArray = new ArrayList<LeverageTDAResult>();

    for (int i = 0; i < matchList.size() - 1; i++) {
        LeverageTDAResult tdaResult1 = (LeverageTDAResult) matchList.get(i);

        for (int j = i + 1; j < matchList.size(); j++) {
            LeverageTDAResult tdaResult2 = (LeverageTDAResult) matchList.get(j);

            if (PecentToInt(tdaResult1.getMatchPercent()) == PecentToInt(tdaResult2.getMatchPercent())
                    && tdaResult1.getResultText().equals(tdaResult2.getResultText())) {
                if (!sameArray.contains(tdaResult2)) {
                    sameArray.add(tdaResult2);
                }
            }
        }
    }

    matchList.removeAll(sameArray);
}

From source file:org.apache.hadoop.hbase.regionserver.Store.java

StoreFile completeCompaction(final Collection<StoreFile> compactedFiles, final StoreFile.Writer compactedFile)
        throws IOException {
    // 1. Moving the new files into place -- if there is a new file (may not
    // be if all cells were expired or deleted).
    StoreFile result = null;//from  w  ww .jav a  2 s  .  c o m
    if (compactedFile != null) {
        validateStoreFile(compactedFile.getPath());
        // Move the file into the right spot
        Path origPath = compactedFile.getPath();
        Path destPath = new Path(homedir, origPath.getName());
        LOG.info("Renaming compacted file at " + origPath + " to " + destPath);
        if (!HBaseFileSystem.renameDirForFileSystem(fs, origPath, destPath)) {
            LOG.error("Failed move of compacted file " + origPath + " to " + destPath);
            throw new IOException("Failed move of compacted file " + origPath + " to " + destPath);
        }
        result = new StoreFile(this.fs, destPath, this.conf, this.cacheConf, this.family.getBloomFilterType(),
                this.dataBlockEncoder, isAssistant());
        passSchemaMetricsTo(result);
        result.createReader();
    }
    try {
        this.lock.writeLock().lock();
        try {
            // Change this.storefiles so it reflects new state but do not
            // delete old store files until we have sent out notification of
            // change in case old files are still being accessed by outstanding
            // scanners.
            ArrayList<StoreFile> newStoreFiles = Lists.newArrayList(storefiles);
            newStoreFiles.removeAll(compactedFiles);
            filesCompacting.removeAll(compactedFiles); // safe bc: lock.writeLock()

            // If a StoreFile result, move it into place.  May be null.
            if (result != null) {
                newStoreFiles.add(result);
            }

            this.storefiles = sortAndClone(newStoreFiles);
        } finally {
            // We need the lock, as long as we are updating the storefiles
            // or changing the memstore. Let us release it before calling
            // notifyChangeReadersObservers. See HBASE-4485 for a possible
            // deadlock scenario that could have happened if continue to hold
            // the lock.
            this.lock.writeLock().unlock();
        }

        // Tell observers that list of StoreFiles has changed.
        notifyChangedReadersObservers();

        // let the archive util decide if we should archive or delete the files
        LOG.debug("Removing store files after compaction...");
        HFileArchiver.archiveStoreFiles(this.conf, this.fs, this.region, this.family.getName(), compactedFiles);

    } catch (IOException e) {
        e = RemoteExceptionHandler.checkIOException(e);
        LOG.error("Failed replacing compacted files in " + this + ". Compacted file is "
                + (result == null ? "none" : result.toString()) + ".  Files replaced "
                + compactedFiles.toString() + " some of which may have been already removed", e);
    }

    // 4. Compute new store size
    this.storeSize = 0L;
    this.totalUncompressedBytes = 0L;
    for (StoreFile hsf : this.storefiles) {
        StoreFile.Reader r = hsf.getReader();
        if (r == null) {
            LOG.warn("StoreFile " + hsf + " has a null Reader");
            continue;
        }
        this.storeSize += r.length();
        this.totalUncompressedBytes += r.getTotalUncompressedBytes();
    }
    return result;
}

From source file:br.unicamp.cst.behavior.bn.Behavior.java

/**
 *  Checks if there is a current behavior proposition in working storage that is using the resources this behavior needs
 * @return if there is conflict of resources
 *//*from ww  w  .  j  a  v  a2 s  .  com*/
private boolean resourceConflict() {//TODO must develop this idea further
    boolean resourceConflict = false;
    ArrayList<MemoryObject> allOfType = new ArrayList<MemoryObject>();

    if (ws != null)
        allOfType.addAll(ws.getAllOfType("BEHAVIOR_PROPOSITION"));

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

    if (allOfType != null) {

        for (MemoryObject bp : allOfType) {
            try {
                JSONObject jsonBp = new JSONObject(bp.getI());
                //System.out.println("=======> bp.getInfo(): "+bp.getInfo());
                boolean performed = jsonBp.getBoolean("PERFORMED");
                if (!performed) {//otherwise it is not consuming those resources

                    JSONArray resourceList = jsonBp.getJSONArray("RESOURCELIST");

                    for (int i = 0; i < resourceList.length(); i++) {
                        usedResources.add(resourceList.getString(i));
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
    //      System.out.println("%%% usedResources: "+usedResources);
    //      System.out.println("%%% getResourceList: "+getResourceList());
    int sizeBefore = usedResources.size();
    usedResources.removeAll(this.getResourceList());
    int sizeLater = usedResources.size();

    if (sizeLater != sizeBefore) {
        resourceConflict = true;
        //         System.out.println("%%%%%%%%%%%%%%%%%%%%% There was a conflict here");
    }

    return resourceConflict;
}