Example usage for java.util ListIterator hasNext

List of usage examples for java.util ListIterator hasNext

Introduction

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

Prototype

boolean hasNext();

Source Link

Document

Returns true if this list iterator has more elements when traversing the list in the forward direction.

Usage

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

@Override
public int getGatedObjects(ImagePlus ip) {
    ArrayList<MicroObject> ImageGatedObjects = new ArrayList<MicroObject>();
    try {//  w w w  .j  a  va  2  s  . c o m

        ArrayList<MicroObject> volumes = (ArrayList) plotvalues.get(1);
        ListIterator<MicroObject> itr = volumes.listIterator();
        while (itr.hasNext()) {
            MicroObject m = itr.next();
            int[] c = new int[2];
            c = m.getBoundsCenter();

            if (ip.getRoi().contains(c[0], c[1])) {
                ImageGatedObjects.add(m);
                m.setGated(true);
            }
        }
    } catch (NullPointerException e) {
        return 0;
    }
    return ImageGatedObjects.size();
}

From source file:adapters.HistogramChartAdapter.java

/**
 * Synchronizes <SPAN CLASS="MATH"><I>x</I></SPAN>-axis ticks to the <SPAN CLASS="MATH"><I>s</I></SPAN>-th histogram bins if the number
 *    of bins is not larger than 10;//from ww  w .  j av a2s.  c o m
 *    otherwise, choose approximately 10 ticks.
 *
 * @param s selects histogram used to define ticks.
 *
 *
 */
public void setTicksSynchro(int s) {
    if (((CustomHistogramDataset) this.dataset.getSeriesCollection()).getBinWidth(s) == -1) {
        DoubleArrayList newTicks = new DoubleArrayList();
        ListIterator binsIter = ((HistogramSeriesCollection) this.dataset).getBins(s).listIterator();

        int i = 0;
        HistogramBin prec = (HistogramBin) binsIter.next();
        double var;
        newTicks.add(prec.getStartBoundary());
        newTicks.add(var = prec.getEndBoundary());
        HistogramBin temp;
        while (binsIter.hasNext()) {
            temp = (HistogramBin) binsIter.next();
            if (temp.getStartBoundary() != var) {
                newTicks.add(var = temp.getStartBoundary());
            } else if (temp.getEndBoundary() != var) {
                newTicks.add(var = temp.getEndBoundary());
            }
        }
        XAxis.setLabels(newTicks.elements());
    } else {
        // set a label-tick for each bin, if num bins is <= 10
        int n = ((HistogramSeriesCollection) this.dataset).getBins(s).size();
        if (n > 10) {
            // number of bins is too large, set ~10 labels-ticks for histogram
            n = 10;
            double[] B = ((HistogramSeriesCollection) this.dataset).getDomainBounds();
            double w = (B[1] - B[0]) / n;
            XAxis.setLabels(w);
        } else {
            XAxis.setLabels(((CustomHistogramDataset) this.dataset.getSeriesCollection()).getBinWidth(s));
        }
    }
}

From source file:bigtweet.BTSim.java

/**
*
* @param na number of agents/*from  w  w  w  .  j av a  2 s  .  com*/
* @param selectingMethod: , last, or first in the list of agents. (or null,
* random, to random)
* @param exceptState agents except of that state, can be null
* @return
*/
public List<UserAgent> getNUsers(int na, String selectingMethod, String exceptState) {
    List<UserAgent> r = new ArrayList<UserAgent>();
    UserAgent aux;
    int added = 0;

    switch (selectingMethod) {
    case "last":
        ListIterator<UserAgent> li = getAgents().listIterator(getAgents().size());
        while (li.hasPrevious() && added < na) {

            aux = li.previous();
            if (exceptState == null || !aux.getState().equals(exceptState)) {
                r.add(aux);
                added++;
            }
        }
        if (added < na) {
            throw new RuntimeException("There is no " + na + " agents to be added.");
        }
        break;
    case "first":
        li = getAgents().listIterator();
        while (li.hasNext() && added < na) {
            aux = li.next();
            if (exceptState == null || !aux.getState().equals(exceptState)) {
                r.add(aux);
                added++;
            }
        }
        if (added < na) {
            throw new RuntimeException("There is no " + na + " agents to be added.");
        }
        break;

    default:
        r = getNRandomUsers(na, exceptState);
    }

    return r;

}

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  w w.  j  av  a  2  s .  c om*/
@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:at.ofai.music.util.WormFileParseException.java

public EventList(EventList e) {
    this();//from ww  w .j a v  a 2s  . com
    ListIterator<Event> it = e.listIterator();
    while (it.hasNext())
        add(it.next());
}

From source file:com.bt.aloha.dialog.state.DialogInfo.java

public void setRouteList(ListIterator<?> recordRouteHeaderIterator, boolean backwards) {
    routeList = new RouteList();
    if (recordRouteHeaderIterator == null)
        return;/*w  w  w  . j av a2s . co  m*/

    if (backwards)
        while (recordRouteHeaderIterator.hasNext())
            recordRouteHeaderIterator.next();

    while (backwards ? recordRouteHeaderIterator.hasPrevious() : recordRouteHeaderIterator.hasNext()) {
        RecordRouteHeader recordRouteHeader = backwards
                ? (RecordRouteHeader) recordRouteHeaderIterator.previous()
                : (RecordRouteHeader) recordRouteHeaderIterator.next();
        Route route = new Route();
        AddressImpl address = (AddressImpl) ((AddressImpl) recordRouteHeader.getAddress()).clone();
        route.setAddress(address);
        NameValueList nameValueList = new NameValueList();
        Iterator<?> paramIterator = recordRouteHeader.getParameterNames();
        while (paramIterator.hasNext()) {
            String paramName = (String) paramIterator.next();
            nameValueList.set(paramName, recordRouteHeader.getParameter(paramName));
        }
        route.setParameters(nameValueList);
        log.debug(String.format("Added route address %s, params %s to route set for dialog %s", address,
                nameValueList.toString(), getId()));
        routeList.add(route);
    }
}

From source file:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java

/**
 * Process Drag&Drop//from w w  w .j a v  a 2  s .  c om
 * @param data
 */
public void processDnD(Object data) {
    log.debug("Playlist DnD");
    // Looking for files to drop.
    if (data instanceof List) {
        List al = (List) data;
        if ((al != null) && (al.size() > 0)) {
            ArrayList fileList = new ArrayList();
            ArrayList folderList = new ArrayList();
            ListIterator li = al.listIterator();
            while (li.hasNext()) {
                File f = (File) li.next();
                if ((f.exists()) && (f.canRead())) {
                    if (f.isFile())
                        fileList.add(f);
                    else if (f.isDirectory())
                        folderList.add(f);
                }
            }
            addFiles(fileList);
            addDirs(folderList);
        }
    } else if (data instanceof String) {
        String files = (String) data;
        if ((files.length() > 0)) {
            ArrayList fileList = new ArrayList();
            ArrayList folderList = new ArrayList();
            StringTokenizer st = new StringTokenizer(files, System.getProperty("line.separator"));
            // Transfer files dropped.
            while (st.hasMoreTokens()) {
                String path = st.nextToken();
                if (path.startsWith("file://")) {
                    path = path.substring(7, path.length());
                    if (path.endsWith("\r"))
                        path = path.substring(0, (path.length() - 1));
                }
                File f = new File(path);
                if ((f.exists()) && (f.canRead())) {
                    if (f.isFile())
                        fileList.add(f);
                    else if (f.isDirectory())
                        folderList.add(f);
                }
            }
            addFiles(fileList);
            addDirs(folderList);
        }
    } else {
        log.info("Unknown dropped objects");
    }
}

From source file:at.ofai.music.util.WormFileParseException.java

public void insert(Event newEvent, boolean uniqueTimes) {
    ListIterator<Event> li = l.listIterator();
    while (li.hasNext()) {
        int sgn = newEvent.compareTo(li.next());
        if (sgn < 0) {
            li.previous();/*from w w  w. ja v  a 2  s .c  om*/
            break;
        } else if (uniqueTimes && (sgn == 0)) {
            li.remove();
            break;
        }
    }
    li.add(newEvent);
}

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

@Override
public XYChartPanel getPanel(int x, int y, int l, int size, String xText, String yText, String lText) {
    String key = x + "_" + y + "_" + l;
    if (isMade(x, y, l, size)) {
        ListIterator<ArrayList> itr = ExplorationItems.listIterator();
        String test;/*ww w  .j  a va  2 s  .c  o m*/
        while (itr.hasNext()) {
            test = itr.next().get(0).toString();
            if (key.equals(test)) {
                return (XYChartPanel) itr.next().get(1);
            }
        }
    }
    return createChartPanel(x, y, l, xText, yText, lText, pointsize, impoverlay, imageGate, imageGateColor);
}

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

@Override
public Gate getGates(int x, int y, int l, int size) {
    String key = x + "_" + y;
    if (isMade(x, y, l, size)) {
        ListIterator<ArrayList> itr = ExplorationItems.listIterator();
        String test;//ww w  .jav  a 2s  .co  m
        while (itr.hasNext()) {
            test = itr.next().get(0).toString();
            if (key.equals(test)) {
                return (Gate) itr.next().get(1);
            }
        }
    }
    return null;
}