Example usage for java.util ListIterator remove

List of usage examples for java.util ListIterator remove

Introduction

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

Prototype

void remove();

Source Link

Document

Removes from the list the last element that was returned by #next or #previous (optional operation).

Usage

From source file:Main.java

public static <T> Iterator<T> getReverseIterator(final ListIterator<T> iter) {
    return new Iterator<T>() {
        public boolean hasNext() {
            return iter.hasPrevious();
        }//  ww w .ja  v a 2  s . c o m

        public T next() {
            return iter.previous();
        }

        public void remove() {
            iter.remove();
        }
    };
}

From source file:org.graphwalker.io.common.Util.java

static public void filterBlockedElements(List<Context> executionContexts) {
    for (Context context : executionContexts) {
        Model model = new Model(context.getModel());
        List<Edge> edges = model.getEdges();
        List<Vertex> vertices = model.getVertices();

        ListIterator<Edge> e_it = edges.listIterator();
        while (e_it.hasNext()) {
            Edge edge = e_it.next();/*from   w w  w . j a v  a2  s. co  m*/
            if (edge.hasProperty("blocked") && (boolean) edge.getProperty("blocked")) {
                e_it.remove();
            }
        }
        ListIterator<Vertex> v_it = vertices.listIterator();
        while (v_it.hasNext()) {
            Vertex vertex = v_it.next();
            if (vertex.hasProperty("blocked") && (boolean) vertex.getProperty("blocked")) {
                e_it = edges.listIterator();
                while (e_it.hasNext()) {
                    Edge e = e_it.next();
                    if (e.getSourceVertex() == vertex) {
                        e_it.remove();
                    } else if (e.getTargetVertex() == vertex) {
                        e_it.remove();
                    }
                }
                v_it.remove();
            }
        }
        context.setModel(model.build());
    }
}

From source file:Main.java

public static <T> Iterable<T> reverse(final List<T> list) {
    return new Iterable<T>() {
        public Iterator<T> iterator() {
            final ListIterator<T> listIterator = list.listIterator(list.size());

            return new Iterator<T>() {
                public boolean hasNext() {
                    return listIterator.hasPrevious();
                }/*from   w w w  .j  a va 2  s. c  o  m*/

                public T next() {
                    return listIterator.previous();
                }

                public void remove() {
                    listIterator.remove();
                }
            };
        }
    };
}

From source file:Main.java

public static <E> Iterable<E> reverse(final List<E> list) {
    return new Iterable<E>() {
        @Override//  w w  w.  j a  v  a  2s .c o m
        public Iterator<E> iterator() {
            final ListIterator<E> it = list.listIterator(list.size());

            return new Iterator<E>() {
                @Override
                public boolean hasNext() {
                    return it.hasPrevious();
                }

                @Override
                public E next() {
                    return it.previous();
                }

                @Override
                public void remove() {
                    it.remove();
                }
            };
        }
    };
}

From source file:cascading.ComparePlatformsTest.java

private static void createComparisons(String comparison, File lhsRoot, File rhsRoot, TestSuite suite) {
    LOG.info("comparing directory: {}, with: {}", lhsRoot, rhsRoot);

    LinkedList<File> lhsFiles = new LinkedList<File>(
            FileUtils.listFiles(lhsRoot, new RegexFileFilter("^[\\w-]+"), TrueFileFilter.INSTANCE));
    LinkedList<File> rhsFiles = new LinkedList<File>();

    LOG.info("found lhs files: {}", lhsFiles.size());

    int rootLength = lhsRoot.toString().length() + 1;

    ListIterator<File> iterator = lhsFiles.listIterator();
    while (iterator.hasNext()) {
        File localFile = iterator.next();
        File file = new File(rhsRoot, localFile.toString().substring(rootLength));

        if (localFile.toString().endsWith(NONDETERMINISTIC))
            iterator.remove();
        else if (file.exists())
            rhsFiles.add(file);//from   w w  w.j ava 2s .co  m
        else
            iterator.remove();
    }

    LOG.info("running {} comparisons", lhsFiles.size());

    for (int i = 0; i < lhsFiles.size(); i++) {
        File localFile = lhsFiles.get(i);
        File hadoopFile = rhsFiles.get(i);

        suite.addTest(new CompareTestCase(comparison, localFile, hadoopFile));
    }
}

From source file:gov.nih.nci.protexpress.util.ManageProtAppInputOutputHelper.java

/**
 * Removes the invalid items (inputs/outputs with blank name, filename and notes) from the list.
 *
 * @param lst the list of inputs/outputs.
 *//*  ww w . ja v a  2  s  .  c o  m*/
public static void removeInvalidItems(List<InputOutputObject> lst) {
    ListIterator<InputOutputObject> listIter = lst.listIterator();
    while (listIter.hasNext()) {
        InputOutputObject ioObject = listIter.next();
        if (StringUtils.isBlank(ioObject.getName()) && StringUtils.isBlank(ioObject.getDataFileURL())
                && StringUtils.isBlank(ioObject.getNotes())) {
            listIter.remove();
        }
    }
}

From source file:exm.stc.ic.ICUtil.java

public static void removeDuplicates(List<Var> varList) {
    ListIterator<Var> it = varList.listIterator();
    HashSet<Var> alreadySeen = new HashSet<Var>();
    while (it.hasNext()) {
        Var v = it.next();// w  w w.  ja  v a  2 s  . co m
        if (alreadySeen.contains(v)) {
            it.remove();
        } else {
            alreadySeen.add(v);
        }
    }
}

From source file:exm.stc.ic.ICUtil.java

/**
 * Replace the current instruction with the provided sequence
 * After this is done, next() will return the instruction after
 * the inserted sequence/*from   w ww . j a v a  2s.c om*/
 */
public static void replaceInsts(Block block, ListIterator<Statement> it,
        List<? extends Statement> replacements) {
    for (Statement stmt : replacements) {
        stmt.setParent(block);
    }
    if (replacements.size() == 1) {
        it.set(replacements.get(0));
    } else if (replacements.size() == 0) {
        it.remove();
    } else {
        it.set(replacements.get(0));
        List<? extends Statement> rest = replacements.subList(1, replacements.size());
        for (Statement newInst : rest) {
            it.add(newInst);
        }
    }
}

From source file:com.twitter.hraven.etl.FileLister.java

/**
 * prunes the given list/array of files based on their sizes
 *
 * @param maxFileSize -max #bytes to be stored in an hbase cell
 * @param origList - input list of files to be processed
 * @param hdfs - filesystem to be looked at
 * @param inputPath - root dir of the path containing history files
 * @return - pruned array of FileStatus of files to be processed
 *//*from   w w  w . j  a  va2 s  . c o m*/
static FileStatus[] pruneFileListBySize(long maxFileSize, FileStatus[] origList, FileSystem hdfs,
        Path inputPath) {
    LOG.info("Pruning orig list  of size " + origList.length + " for source" + inputPath.toUri());

    long fileSize = 0L;
    List<FileStatus> prunedFileList = new ArrayList<FileStatus>();

    Set<String> toBeRemovedJobId = new HashSet<String>();
    for (int i = 0; i < origList.length; i++) {
        fileSize = origList[i].getLen();

        // check if hbase can store this file if yes, consider it for processing
        if (fileSize <= maxFileSize) {
            prunedFileList.add(origList[i]);
        } else {
            Path hugeFile = origList[i].getPath();
            LOG.info("In getListFilesToProcess filesize " + fileSize + " has exceeded maxFileSize "
                    + maxFileSize + " for " + hugeFile.toUri());

            // note the job id so that we can remove the other file (job conf or job history)
            toBeRemovedJobId.add(getJobIdFromPath(hugeFile));
        }
    }
    if (prunedFileList.size() == 0) {
        LOG.info("Found no files worth processing. Returning 0 sized array");
        return new FileStatus[0];
    }

    String jobId = null;
    ListIterator<FileStatus> it = prunedFileList.listIterator();
    while (it.hasNext()) {
        if (toBeRemovedJobId.size() == 0) {
            // no files to remove
            break;
        }
        Path curFile = it.next().getPath();
        jobId = getJobIdFromPath(curFile);
        if (toBeRemovedJobId.contains(jobId)) {
            LOG.info("Removing from prunedList " + curFile.toUri());
            it.remove();
            /*
             * removing the job id from the hash set since there would be only
             * one file with this job id in the prunedList, the other file with
             * this job id was huge and was already moved out
             */
            toBeRemovedJobId.remove(jobId);
        }
    }
    return prunedFileList.toArray(new FileStatus[prunedFileList.size()]);
}

From source file:exm.stc.ic.ICUtil.java

public static void replaceVarsInList(Map<Var, Arg> replacements, List<Var> vars, boolean removeDupes,
        boolean removeMapped) {
    // Remove new duplicates
    ArrayList<Var> alreadySeen = null;
    if (removeDupes) {
        alreadySeen = new ArrayList<Var>(vars.size());
    }//from   w  w  w  . j a va  2 s  .  c o m

    ListIterator<Var> it = vars.listIterator();
    while (it.hasNext()) {
        Var v = it.next();
        if (replacements.containsKey(v)) {
            Arg oa = replacements.get(v);
            if (oa.isVar()) {
                if (removeDupes && alreadySeen.contains(oa.getVar())) {
                    it.remove();
                } else {
                    it.set(oa.getVar());
                    if (removeDupes) {
                        alreadySeen.add(oa.getVar());
                    }
                }
            }
        } else {
            if (removeDupes) {
                if (alreadySeen.contains(v)) {
                    it.remove();
                } else {
                    alreadySeen.add(v);
                }
            }
        }
    }
}