Example usage for java.util ListIterator next

List of usage examples for java.util ListIterator next

Introduction

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

Prototype

E next();

Source Link

Document

Returns the next element in the list and advances the cursor position.

Usage

From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java

public int getChildCount(Object obj) {
    ListIterator i = getIterator();
    GraphicNode node;/*from   w w w  .j a va  2 s . c o m*/
    GraphicNode ref = null;
    if (obj == getRoot())
        ref = (GraphicNode) getRoot();
    else
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node == obj) {
                ref = node;
                break;
            }
        }
    int count = 0;
    if (ref != null)
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node.getLevel() <= ref.getLevel())
                break;
            else if (node.getLevel() == ref.getLevel() + 1)
                count++;
        }
    return count;
}

From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java

public boolean isLeaf(Object obj) {
    ListIterator i = getIterator();
    GraphicNode node;/*from   w ww  .ja v  a2  s  .  c om*/
    GraphicNode ref = null;
    if (obj == getRoot())
        ref = (GraphicNode) getRoot();
    else
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node == obj) {
                ref = node;
                break;
            }
        }
    if (ref == null)
        return true;
    if (i.hasNext()) {
        node = (GraphicNode) i.next();
        if (node.getLevel() > ref.getLevel())
            return false;
        else
            return true;
    }
    return true;
}

From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java

public Object getChild(Object obj, int index) {
    ListIterator i = getIterator();
    GraphicNode node;/* w  w  w .jav a2s .c o m*/
    GraphicNode ref = null;
    if (obj == getRoot())
        ref = (GraphicNode) getRoot();
    else
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node == obj) {
                ref = node;
                break;
            }
        }
    if (ref == null)
        return null;
    int count = 0;
    while (i.hasNext()) {
        node = (GraphicNode) i.next();
        if (node.getLevel() <= ref.getLevel())
            break;
        else if (node.getLevel() == ref.getLevel() + 1) {
            if (count == index)
                return node;
            count++;
        }
    }
    return null;
}

From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java

public int getIndexOfChild(Object parent, Object child) {
    ListIterator i = getIterator();
    GraphicNode node;/*from   w w  w. j  a  v a2  s . c  o m*/
    GraphicNode ref = null;
    if (parent == getRoot())
        ref = (GraphicNode) getRoot();
    else
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node == parent) {
                ref = node;
                break;
            }
        }
    if (ref == null)
        return -1;
    int count = 0;
    while (i.hasNext()) {
        node = (GraphicNode) i.next();
        if (node.getLevel() <= ref.getLevel())
            break;
        else if (node.getLevel() == ref.getLevel() + 1) {
            if (node == child)
                return count;
            count++;
        }
    }
    return -1;
}

From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java

private void histogramToKMZ(String transportMode, BasicLocation location, List<Double> listWithoutNaN)
        throws IOException {
    String filename = createFilenameFromLocation(location, "_" + transportMode + HISTOGRAM);
    if (filename == null)
        return;//from  w w  w  . j a  va2 s  .  c  o  m

    double[] array = new double[listWithoutNaN.size()];
    int i = 0;
    ListIterator<Double> iter = listWithoutNaN.listIterator();
    while (iter.hasNext()) {
        array[i] = iter.next();
        i++;
    }

    // if no valid travel times exist -> create an empty histogram
    if (array.length == 0) {
        array = new double[1];
        array[0] = 0.0;
    }

    writeChartToKmz(filename, createHistogramChart(transportMode, array), HISTOGRAMWIDTH, HISTOGRAMHEIGHT);
}

From source file:au.edu.ausstage.networks.LookupManager.java

/**
 * A method to take a group of collaborators and output JSON encoded text
 * Unchecked warnings are suppressed due to internal issues with the org.json.simple package
 *
 * @param collaborators the list of collaborators
 * @return              the JSON encoded string
 *///from  w ww .j  a  v a2 s .  c  o  m
@SuppressWarnings("unchecked")
private String createJSONOutput(LinkedList<Collaborator> collaborators) {

    // assume that all sorting and ordering has already been carried out
    // loop through the list of collaborators and add them to the new JSON objects
    ListIterator iterator = collaborators.listIterator(0);

    // declare helper variables
    JSONArray list = new JSONArray();
    JSONObject object = null;
    Collaborator collaborator = null;

    while (iterator.hasNext()) {

        // get the collaborator
        collaborator = (Collaborator) iterator.next();

        // start a new JSON object
        object = new JSONObject();

        // build the object
        object.put("id", collaborator.getId());
        object.put("url", collaborator.getUrl());
        object.put("givenName", collaborator.getGivenName());
        object.put("familyName", collaborator.getFamilyName());
        object.put("name", collaborator.getName());
        object.put("function", collaborator.getFunction());
        object.put("firstDate", collaborator.getFirstDate());
        object.put("lastDate", collaborator.getLastDate());
        object.put("collaborations", new Integer(collaborator.getCollaborations()));

        // add the new object to the array
        list.add(object);
    }

    // return the JSON encoded string
    return list.toString();

}

From source file:com.offbynull.peernetic.playground.chorddht.model.FingerTable.java

/**
 * Searches the finger table for {@code id}.
 * @param id id to search for//from w w w.j  a  v  a2 s .c o m
 * @return {@code true} if found, {@code false} otherwise
 * @throws NullPointerException if any arguments are {@code null}
 * @throws IllegalArgumentException if {@code id} has a different limit bit size than the base pointer's id
 */
public boolean contains(Id id) {
    Validate.notNull(id);
    Validate.isTrue(IdUtils.getBitLength(id) == bitCount);

    ListIterator<InternalEntry> lit = table.listIterator();
    while (lit.hasNext()) {
        InternalEntry ie = lit.next();

        if (ie.pointer.getId().equals(id)) {
            return true;
        }
    }

    return false;
}

From source file:vteaexploration.plottools.panels.XYExplorationPanel.java

@Override
public boolean isMade(int x, int y, int l, int size) {
    ListIterator<ArrayList> itr = ExplorationItems.listIterator();
    String test;//from  w  w  w.  j ava  2  s. c o  m
    String key = x + "_" + y + "_" + l + "_" + size;
    while (itr.hasNext()) {
        test = itr.next().get(0).toString();
        if (key.equals(test)) {
            return true;
        }
    }
    return false;
}

From source file:com.offbynull.peernetic.playground.chorddht.model.FingerTable.java

/**
 * Searches the finger table for the left-most occurrence of {@code ptr}.
 * @param ptr pointer to search for//from w w w .j  a  v a  2 s . c om
 * @return index of occurrence, or -1 if not found
 * @throws NullPointerException if any arguments are {@code null}
 * @throws IllegalArgumentException if {@code ptr}'s id has a different limit bit size than the base pointer's id
 */
public int getMinimumIndex(Pointer ptr) {
    Validate.notNull(ptr);
    Validate.isTrue(IdUtils.getBitLength(ptr.getId()) == bitCount);

    Id id = ptr.getId();
    Validate.isTrue(IdUtils.getBitLength(id) == bitCount);

    ListIterator<InternalEntry> lit = table.listIterator();
    while (lit.hasNext()) {
        InternalEntry ie = lit.next();

        if (ie.pointer.equals(ptr)) {
            return lit.nextIndex() - 1;
        }
    }

    return -1;
}

From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java

/**
 * Call this after changing the rectangle in any way. It removes rectangles
 * of size less than 1, and it also converts "composed" rectangles with
 * only one rectangle to uncomposed; it also updates the polygon.
 *///from w  ww.j a  va 2  s .  c o m
private void simplify() {
    boolean startedComposed = composed;
    if (composed) {
        if (pieces.size() == 0) {
            pieces = null;
            composed = false;
            rect = new Rectangle();
        } else if (pieces.size() == 1) {
            BoundingBox child = (BoundingBox) pieces.getFirst();
            composed = false;
            if (child != null)
                setTo(child);
            else
                pieces.clear();
        } else if (pieces.size() > 1) {
            boolean changed = false;
            ListIterator iter = pieces.listIterator(0);
            while (iter.hasNext())
                if (!(((BoundingBox) iter.next()).area()).greaterThan(0)) {
                    iter.remove();
                    changed = true;
                }
            if (changed)
                simplify();
        }
    }
    if (startedComposed && !composed)
        initPoly();
}