Example usage for java.util.concurrent CopyOnWriteArrayList listIterator

List of usage examples for java.util.concurrent CopyOnWriteArrayList listIterator

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList listIterator.

Prototype

public ListIterator<E> listIterator() 

Source Link

Document

The returned iterator provides a snapshot of the state of the list when the iterator was constructed.

Usage

From source file:codeswarm.code_swarm.java

/**
 * TODO This could be made to look a lot better.
 *///from w ww .  j  ava 2 s .co m
public void drawPopular() {
    CopyOnWriteArrayList<FileNode> al = new CopyOnWriteArrayList<FileNode>();
    noStroke();
    textFont(font);
    textAlign(RIGHT, TOP);
    fill(255, 200);
    text("Popular Nodes (touches):", width - 120, 0);
    for (int i = 0; i < nodes.size(); i++) {
        FileNode fn = nodes.get(i);
        if (fn.qualifies()) {
            // Insertion Sort
            if (al.size() > 0) {
                int j = 0;
                for (; j < al.size(); j++) {
                    if (fn.compareTo(al.get(j)) <= 0) {
                        continue;
                    } else {
                        break;
                    }
                }
                al.add(j, fn);
            } else {
                al.add(fn);
            }
        }
    }

    int i = 1;
    ListIterator<FileNode> it = al.listIterator();
    while (it.hasNext()) {
        FileNode n = it.next();
        // Limit to the top 10.
        if (i <= 10) {
            text(n.getName() + "  (" + n.getTouches() + ")", width - 100, 10 * i++);
        } else if (i > 10) {
            break;
        }
    }
}

From source file:org.github.gitswarm.GitSwarm.java

/**
 * TODO This could be made to look a lot better.
 *//*from  w w w. j  av a  2  s .c o  m*/
private void drawPopular() {
    CopyOnWriteArrayList<FileNode> al = new CopyOnWriteArrayList<>();
    noStroke();
    textFont(font);
    textAlign(RIGHT, TOP);
    fill(fontColor, 200);
    text("Popular Nodes (touches):", width - 120, 0);
    for (FileNode fn : nodes.values()) {
        if (fn.qualifies()) {
            // Insertion Sort
            if (al.size() > 0) {
                int j = 0;
                for (; j < al.size(); j++) {
                    if (fn.compareTo(al.get(j)) > 0) {
                        break;
                    }
                }
                al.add(j, fn);
            } else {
                al.add(fn);
            }
        }
    }

    int i = 1;
    ListIterator<FileNode> it = al.listIterator();
    while (it.hasNext()) {
        FileNode n = it.next();
        // Limit to the top 10.
        if (i <= 10) {
            text(n.getName() + "  (" + n.getTouches() + ")", width - 100, 10 * i++);
        } else if (i > 10) {
            break;
        }
    }
}