Example usage for java.util Iterator remove

List of usage examples for java.util Iterator remove

Introduction

In this page you can find the example usage for java.util Iterator remove.

Prototype

default void remove() 

Source Link

Document

Removes from the underlying collection the last element returned by this iterator (optional operation).

Usage

From source file:com.mindquarry.desktop.workspace.ConflictHelper.java

/**
 * Finds all files that will be marked as (content-) conflicted after
 * update./*from  w w  w.  ja v  a 2 s  .  com*/
 */
public static List<Conflict> findIncomingConflicted(List<Status> remoteAndLocalChanges) {
    List<Conflict> conflicts = new ArrayList<Conflict>();
    Iterator<Status> iter = remoteAndLocalChanges.iterator();

    while (iter.hasNext()) {
        Status status = iter.next();

        // local MODIFIED, remote MODIFIED
        if (status.getTextStatus() == StatusKind.modified
                && status.getRepositoryTextStatus() == StatusKind.modified) {
            iter.remove();

            conflicts.add(new ContentConflict(status));
        }
    }
    return conflicts;
}

From source file:com.acmutv.ontoqa.core.parser.SimpleSltagParser.java

private static void handleMultipleCandidates(List<ElementarySltag> candidates, ParserState dashboard) {
    Integer idxPrev = dashboard.getIdxPrev();
    WaitingList wlist = dashboard.getWaitingList();
    Iterator<ElementarySltag> iterCandidates = candidates.iterator();

    while (iterCandidates.hasNext()) {
        Sltag candidate = iterCandidates.next();
        if (candidate.isSentence()) {
            if (candidate.isSentence() && idxPrev == null && candidate.isLeftSub()) { // excludes is (affermative) when we are at the first word.
                LOGGER.debug(//from   ww  w. j a v  a2  s.c o m
                        "Excluded colliding sentence-root candidate (found left-sub at the beginning of the sentence):\n{}",
                        candidate.toPrettyString());
                iterCandidates.remove();
            } else if (candidate.isSentence() && idxPrev != null && !candidate.isLeftSub()) { // excludes is (interrogative) when we are in the middle of the sentence.
                LOGGER.debug(
                        "Excluded colliding sentence-root candidate (found not left-sub within the sentence):\n{}",
                        candidate.toPrettyString());
                iterCandidates.remove();
            }
        } else if (candidate.isAdjunctable()) {
            LOGGER.debug("Colliding candidate (adjunction):\n{}", candidate.toPrettyString());
            if (wlist.isEmpty())
                wlist.add(new ConflictElement());
            wlist.get(wlist.size() - 1).addAdjunction(candidate, idxPrev);
            iterCandidates.remove();
        } else {
            LOGGER.debug("Colliding candidate (substitution):\n{}", candidate.toPrettyString());
            if (wlist.isEmpty())
                wlist.add(new ConflictElement());
            wlist.get(wlist.size() - 1).addSubstitution(candidate, idxPrev);
            iterCandidates.remove();
        }
    }
}

From source file:dk.netarkivet.harvester.harvesting.HarvestDocumentation.java

/**
 * Documents the harvest under the given dir in a packaged metadata arc
 * file in a directory 'metadata' under the current dir.
 * Only documents the files belonging to the given jobID, the rest are
 * moved to oldjobs./*from   ww w.java2  s . c om*/
 *
 * In the current implementation, the documentation consists
 * of CDX indices over all ARC files (with one CDX record per harvested
 * ARC file), plus packaging of log files.
 *
 * If this method finishes without an exception, it is guaranteed that
 * metadata is ready for upload.
 * 
 * TODO Place preharvestmetadata in IngestableFiles-defined area
 * TODO This method may be a good place to copy deduplicate information from the
 * crawl log to the cdx file.
 *
 *@param ingestables Information about the finished crawl (crawldir, jobId, harvestID).
 * 
 * @throws ArgumentNotValid if crawlDir is null or does not exist, or if
 * jobID or harvestID is negative.
 * @throws IOFailure if
 *   - reading ARC files or temporary files fails
 *   - writing a file to arcFilesDir fails
 */
public static void documentHarvest(IngestableFiles ingestables) throws IOFailure {
    ArgumentNotValid.checkNotNull(ingestables, "ingestables");

    File crawlDir = ingestables.getCrawlDir();
    Long jobID = ingestables.getJobId();
    Long harvestID = ingestables.getHarvestID();

    // Prepare metadata-arcfile for ingestion of metadata, and enumerate
    // items to ingest.

    // If metadata-arcfile already exists, we are done
    // See bug 722
    if (ingestables.isMetadataReady()) {
        log.warn("The metadata-file '" + ingestables.getMetadataFile().getAbsolutePath()
                + "' already exists, so we don't make another one!");
        return;
    }
    List<File> filesAddedAndNowDeletable = null;

    try {
        MetadataFileWriter mdfw = null;
        mdfw = ingestables.getMetadataWriter();

        if (mdfw instanceof MetadataFileWriterWarc) {
            // add warc-info record
            ANVLRecord infoPayload = new ANVLRecord(3);
            infoPayload.addLabelValue("software",
                    "NetarchiveSuite/" + dk.netarkivet.common.Constants.getVersionString() + "/"
                            + dk.netarkivet.common.Constants.PROJECT_WEBSITE);
            infoPayload.addLabelValue("ip", SystemUtils.getLocalIP());
            infoPayload.addLabelValue("hostname", SystemUtils.getLocalHostName());
            infoPayload.addLabelValue("conformsTo",
                    "http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf");

            PersistentJobData psj = new PersistentJobData(crawlDir);
            infoPayload.addLabelValue("isPartOf", "" + psj.getJobID());
            MetadataFileWriterWarc mfww = (MetadataFileWriterWarc) mdfw;
            mfww.insertInfoRecord(infoPayload);
        }

        //  Fetch any serialized preharvest metadata objects, if they exists.
        List<MetadataEntry> storedMetadata = getStoredMetadata(crawlDir);
        try {
            for (MetadataEntry m : storedMetadata) {
                mdfw.write(m.getURL(), m.getMimeType(), SystemUtils.getLocalIP(), System.currentTimeMillis(),
                        m.getData());
            }
        } catch (IOException e) {
            log.warn("Unable to write pre-metadata to metadata archivefile", e);
        }

        // Insert the harvestdetails into metadata archivefile.
        filesAddedAndNowDeletable = writeHarvestDetails(jobID, harvestID, crawlDir, mdfw,
                Constants.getHeritrixVersionString());
        // All these files just added to the metadata archivefile can now be deleted 
        // except for the files we need for later processing):
        //  - crawl.log is needed to create domainharvestreport later
        //  - harvestInfo.xml is needed to upload stored data after
        //    crashes/stops on the harvesters
        //  - progress-statistics.log is needed to find out if crawl ended due
        //    to hitting a size limit, or due to other completion

        Iterator<File> iterator = filesAddedAndNowDeletable.iterator();
        while (iterator.hasNext()) {
            File f = iterator.next();
            if (f.getName().equals("crawl.log") || f.getName().equals("harvestInfo.xml")
                    || f.getName().equals("progress-statistics.log")) {
                iterator.remove();
            }
        }

        boolean cdxGenerationSucceeded = false;

        // Try to create CDXes over ARC and WARC files.            
        File arcFilesDir = ingestables.getArcsDir();
        File warcFilesDir = ingestables.getWarcsDir();

        if (arcFilesDir.isDirectory() && FileUtils.hasFiles(arcFilesDir)) {
            addCDXes(ingestables, arcFilesDir, mdfw, ArchiveProfile.ARC_PROFILE);
            cdxGenerationSucceeded = true;
        }
        if (warcFilesDir.isDirectory() && FileUtils.hasFiles(warcFilesDir)) {
            addCDXes(ingestables, warcFilesDir, mdfw, ArchiveProfile.WARC_PROFILE);
            cdxGenerationSucceeded = true;
        }

        if (cdxGenerationSucceeded) {
            // This indicates, that either the files in the arcsdir or in the warcsdir 
            // have now been CDX-processed.
            //
            // TODO refactor, as this call has too many sideeffects
            ingestables.setMetadataGenerationSucceeded(true);
        } else {
            log.warn("Found no archive directory with ARC og WARC files. Looked for dirs '"
                    + arcFilesDir.getAbsolutePath() + "' and '" + warcFilesDir.getAbsolutePath() + "'.");
        }
    } finally {
        // If at this point metadata is not ready, an error occurred.
        if (!ingestables.isMetadataReady()) {
            ingestables.setMetadataGenerationSucceeded(false);
        } else {
            for (File fileAdded : filesAddedAndNowDeletable) {
                FileUtils.remove(fileAdded);
            }
            ingestables.cleanup();
        }
    }
}

From source file:com.baidu.bjf.remoting.protobuf.ProtobufIDLProxy.java

private static CodeDependent hasDependency(List<CodeDependent> cds, Set<String> compiledClass) {
    if (cds.isEmpty()) {
        return null;
    }/*from  w  ww  .  ja v a2  s  . c  o m*/

    Iterator<CodeDependent> iterator = cds.iterator();
    while (iterator.hasNext()) {
        CodeDependent next = iterator.next();
        if (!next.isDepndency()) {
            compiledClass.add(next.name);
            iterator.remove();
            return next;
        } else {
            Set<String> dependencies = next.dependencies;
            if (compiledClass.containsAll(dependencies)) {
                compiledClass.add(next.name);
                iterator.remove();
                return next;
            }
        }
    }

    // if cds is not empty guess there is some message dependency is not
    // available. so error idl protobuf defined?
    if (!cds.isEmpty()) {
        Set<String> guessLoadedClass = new HashSet<String>(compiledClass);
        iterator = cds.iterator();
        while (iterator.hasNext()) {
            guessLoadedClass.add(iterator.next().name);
        }

        // to check while message's dependency is missed
        iterator = cds.iterator();
        while (iterator.hasNext()) {
            CodeDependent next = iterator.next();
            if (!next.isDepndency()) {
                continue;
            }

            if (guessLoadedClass.containsAll(next.dependencies)) {
                continue;
            }

            for (String dependClass : next.dependencies) {
                if (!guessLoadedClass.contains(dependClass)) {
                    throw new RuntimeException("Message '"
                            + StringUtils.removeEnd(next.name, DEFAULT_SUFFIX_CLASSNAME)
                            + "' depend on message '"
                            + StringUtils.removeEnd(dependClass, DEFAULT_SUFFIX_CLASSNAME) + "' is missed");
                }
            }
        }

    }

    return null;
}

From source file:com.acmutv.ontoqa.core.parser.SimpleSltagParserNew.java

private static void handleMultipleCandidates(List<ElementarySltag> candidates, ParserStateNew state) {
    Integer idxPrev = state.getIdxPrev();
    ConflictList conflicts = state.getConflictList();
    Iterator<ElementarySltag> iterCandidates = candidates.iterator();

    while (iterCandidates.hasNext()) {
        Sltag candidate = iterCandidates.next();
        if (candidate.isSentence()) { /* SYNTACTICALLY SOLVABLE CONFLICTS */
            if (idxPrev == null && candidate.isLeftSub()) { // excludes is (affermative) when we are at the first word.
                LOGGER.debug(//from   www .j  av  a 2  s .com
                        "Excluded colliding sentence-root candidate (found left-sub at the beginning of the sentence):\n{}",
                        candidate.toPrettyString());
                iterCandidates.remove();
            } else if (idxPrev != null && !candidate.isLeftSub()) { // excludes is (interrogative) when we are in the middle of the sentence.
                LOGGER.debug(
                        "Excluded colliding sentence-root candidate (found not left-sub within the sentence):\n{}",
                        candidate.toPrettyString());
                iterCandidates.remove();
            }
        } else {
            LOGGER.debug("Colliding candidate:\n{}", candidate.toPrettyString());
            conflicts.add(candidate, idxPrev);
            iterCandidates.remove();
        }
    }
}

From source file:com.icesoft.faces.util.event.servlet.ContextEventRepeater.java

private synchronized static void removeBufferedEvents(final String iceFacesId) {

    synchronized (BUFFERED_CONTEXT_EVENTS) {
        Iterator _bufferedContextEvents = BUFFERED_CONTEXT_EVENTS.iterator();
        while (_bufferedContextEvents.hasNext()) {
            Object event = _bufferedContextEvents.next();
            if ((event instanceof ICEfacesIDRetrievedEvent
                    && ((ICEfacesIDRetrievedEvent) event).getICEfacesID().equals(iceFacesId))
                    || (event instanceof ViewNumberRetrievedEvent
                            && ((ViewNumberRetrievedEvent) event).getICEfacesID().equals(iceFacesId))) {

                _bufferedContextEvents.remove();
            }//from w w  w  . jav a 2s  .  c  o m
        }
    }
}

From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java

public static <T extends Object> void remove(Collection<T> values, Grep<T> grep) {
    if (Argument.isEmpty(values)) {
        return;// w w w .j a  v a  2s  .  c  o  m
    }
    Iterator<T> iterator = values.iterator();
    while (iterator.hasNext()) {
        if (grep.grep(iterator.next())) {
            iterator.remove();
        }
    }
}

From source file:com.vmware.vfabric.ide.eclipse.tcserver.internal.core.TcServerBehaviour.java

public static boolean mergeClasspathIfRequired(List<IRuntimeClasspathEntry> cp, IRuntimeClasspathEntry entry,
        boolean prepend) {
    boolean first = true;
    Iterator<IRuntimeClasspathEntry> iterator = cp.iterator();
    while (iterator.hasNext()) {
        IRuntimeClasspathEntry entry2 = iterator.next();
        if (entry2.getPath().equals(entry.getPath())) {
            if (prepend && !first) {
                // ensure new element is always first
                iterator.remove();
            } else {
                return false;
            }/* w w  w  .  j a  v  a 2  s .c  o  m*/
        }
        first = false;
    }

    if (prepend) {
        cp.add(0, entry);
    } else {
        cp.add(entry);
    }
    return true;
}

From source file:at.bestsolution.persistence.java.Util.java

public static <O> void syncLists(List<O> targetList, List<O> newList) {
    Iterator<O> it = targetList.iterator();
    List<O> removeItems = new ArrayList<O>();
    // remove items not found in new list
    // do not remove immediately because because then to many notifications
    // are regenerated
    while (it.hasNext()) {
        O next = it.next();/*from  w  ww  . j  ava 2s.  co m*/
        if (!newList.contains(next)) {
            removeItems.add(next);
        }
    }

    targetList.removeAll(removeItems);

    // remove all items from the new list already contained
    it = newList.iterator();
    while (it.hasNext()) {
        if (targetList.contains(it.next())) {
            it.remove();
        }
    }

    targetList.addAll(newList);
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

public static void removeFromInstallQueue(SharedPreferences sharedPrefs, ArrayList<String> packageNames) {
    synchronized (sLock) {
        Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
        if (DBG) {
            Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames);
        }//w  w  w.j a  va 2  s.c om
        if (strings != null) {
            Set<String> newStrings = new HashSet<String>(strings);
            Iterator<String> newStringsIter = newStrings.iterator();
            while (newStringsIter.hasNext()) {
                String json = newStringsIter.next();
                try {
                    JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
                    Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);
                    String pn = launchIntent.getPackage();
                    if (pn == null) {
                        pn = launchIntent.getComponent().getPackageName();
                    }
                    if (packageNames.contains(pn)) {
                        newStringsIter.remove();
                    }
                } catch (org.json.JSONException e) {
                    Log.d(TAG, "Exception reading shortcut to remove: " + e);
                } catch (java.net.URISyntaxException e) {
                    Log.d(TAG, "Exception reading shortcut to remove: " + e);
                }
            }
            sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>(newStrings)).commit();
        }
    }
}