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.script.object.TimeIntervals.java

public TimeIntervals translate(int winCount) { //TODO case winCount<0

    //      for (TimeWindow w : history) System.out.println("history0: "+w);
    //      for (TimeWindow w : win) System.out.println("win0: "+w);

    //for (TimeWindow w : history) System.out.println("id="+w.getId());
    TimeIntervals t = new TimeIntervals();
    t.setScale(scale);//from  w  w w.j av a  2 s  .  c om
    LinkedList<TimeWindow> twin = t.getWin();
    if (winCount == 0 || win.size() == 0)
        return t; //or null
    if (winCount > 0) {
        t.winId = winId + win.size();
        int lastId = t.winId - 1 + winCount;
        int maxHistoryId = Math.min(history.getLast().getId(), lastId);
        int i = t.winId;
        if (i <= maxHistoryId) {
            ListIterator<TimeWindow> it = history.listIterator();
            TimeWindow w;
            while (it.hasNext()) {
                w = it.next();
                if (w.getId() == t.winId) {
                    it.previous();
                    break;
                }
            }
            for (; i <= maxHistoryId && it.hasNext(); i++) {
                w = it.next();
                twin.add(w);
                //               System.out.println("Found in history: "+w);
            }
        }
        LinkedList<TimeWindow> newWin = new LinkedList<TimeWindow>();
        generateWindows(scale, (twin.size() > 0 ? twin : win).getLast().getE(), start, end, lastId - i + 1,
                newWin);
        t.indexWindows(t.winId + t.getWin().size(), newWin);
        //         for (TimeWindow w : newWin) System.out.println("New window: "+w);
        t.getWin().addAll(newWin);
        history.addAll(newWin);
    } else {
        t.winId = winId - 1;
        int lastId = t.winId + 1 + winCount;
        int minHistoryId = Math.max(history.getFirst().getId(), lastId);
        int i = t.winId;
        if (i >= minHistoryId) {
            ListIterator<TimeWindow> it = history.listIterator(history.size() - 1);
            TimeWindow w;
            while (it.hasPrevious()) {
                w = it.previous();
                if (w.getId() == t.winId) {
                    it.next();
                    break;
                }
            }
            for (; i >= minHistoryId; i--) {
                w = it.previous();
                twin.addFirst(w);
                //               System.out.println("Found in history: "+w);
            }
        }
        //         System.out.println("winId="+winId+", t.winId="+t.winId+", lastId="+lastId+", i="+i+" minHistoryId="+minHistoryId);
        LinkedList<TimeWindow> newWin = new LinkedList<TimeWindow>();
        generateWindows(scale, (twin.size() > 0 ? twin : win).getFirst().getS(), start, end, lastId - i - 1,
                newWin);
        t.indexWindows(lastId, newWin);
        //         for (TimeWindow w : newWin) System.out.println("New window: "+w);
        t.getWin().addAll(0, newWin);
        history.addAll(0, newWin);
    }

    int translation = 0;
    for (TimeWindow w : t.getWin()) {
        if (winCount > 0) {
            win.removeFirst();
            win.addLast(w);
            translation++;
        } else {
            win.removeLast();
            win.addFirst(w);
            translation--;
        }
    }
    winId = winId + translation;
    t.setTranslation(translation);

    //      for (TimeWindow w : history) System.out.println("history1: "+w);
    //      for (TimeWindow w : win) System.out.println("win1: "+w);
    //      for (TimeWindow w : twin) System.out.println("t.win1: "+w);

    return t;
}

From source file:marytts.unitselection.analysis.ProsodyAnalyzer.java

/**
 * For debugging, generate Praat DurationTier, which can be used for PSOLA-based manipulation in Praat.
 * <p>/*from  w w  w.jav  a 2s . c o m*/
 * Notes:
 * <ul>
 * <li>Initial silence is skipped.</li>
 * <li>Units with zero realized duration are ignored.</li>
 * <li>To avoid gradual interpolation between points, place two points around each unit boundary, separated by
 * <code>MIN_SKIP</code>; this workaround allows one constant factor per unit.</li>
 * </ul>
 * 
 * @param fileName
 *            of the DurationTier to be generated
 * @throws IOException
 */
public void writePraatDurationTier(String fileName) throws IOException {

    // initialize times and values with a size corresponding to two elements (start and end) per unit:
    ArrayList<Double> times = new ArrayList<Double>(units.size() * 2);
    ArrayList<Double> values = new ArrayList<Double>(units.size() * 2);

    final double MIN_SKIP = 1e-15;

    // cumulative time pointer:
    double time = 0;

    // iterate over phones, skipping the initial silence:
    // TODO is this really robust?
    ListIterator<Phone> phoneIterator = phones.listIterator(1);
    while (phoneIterator.hasNext()) {
        Phone phone = phoneIterator.next();

        // process left halfphone unit:
        if (phone.getLeftUnitDuration() > 0) {
            // add point at unit start:
            times.add(time);
            values.add(phone.getLeftDurationFactor());

            // increment time pointer by unit duration:
            time += phone.getLeftUnitDuration();

            // add point at unit end:
            times.add(time - MIN_SKIP);
            values.add(phone.getLeftDurationFactor());
        }
        // process right halfphone unit:
        if (phone.getRightUnitDuration() > 0) {
            // add point at unit start:
            times.add(time);
            values.add(phone.getRightDurationFactor());

            // increment time pointer by unit duration:
            time += phone.getRightUnitDuration();

            // add point at unit end:
            times.add(time - MIN_SKIP);
            values.add(phone.getRightDurationFactor());
        }
    }

    // open file for writing:
    File durationTierFile = new File(fileName);
    PrintWriter out = new PrintWriter(durationTierFile);

    // print header:
    out.println("\"ooTextFile\"");
    out.println("\"DurationTier\"");
    out.println(String.format("0 %f %d", time, times.size()));

    // print points (times and values):
    for (int i = 0; i < times.size(); i++) {
        // Note: time precision should be greater than MIN_SKIP:
        out.println(String.format("%.16f %f", times.get(i), values.get(i)));
    }

    // flush and close:
    out.close();
}

From source file:com.manydesigns.portofino.dispatcher.Dispatcher.java

protected void makePageInstancePath(List<PageInstance> pagePath, ListIterator<String> fragmentsIterator)
        throws Exception {
    PageInstance parentPageInstance = pagePath.get(pagePath.size() - 1);
    File currentDirectory = parentPageInstance.getChildrenDirectory();
    boolean params = !parentPageInstance.getParameters().isEmpty();
    while (fragmentsIterator.hasNext()) {
        String nextFragment = fragmentsIterator.next();
        File childDirectory = new File(currentDirectory, nextFragment);
        if (childDirectory.isDirectory() && !PageInstance.DETAIL.equals(childDirectory.getName())) {
            ChildPage childPage = null;//  www. ja  v  a2s . co  m
            for (ChildPage candidate : parentPageInstance.getLayout().getChildPages()) {
                if (candidate.getName().equals(childDirectory.getName())) {
                    childPage = candidate;
                    break;
                }
            }
            if (childPage == null) {
                throw new PageNotActiveException();
            }

            Page page = DispatcherLogic.getPage(childDirectory);
            Class<? extends PageAction> actionClass = DispatcherLogic.getActionClass(configuration,
                    childDirectory);
            PageInstance pageInstance = new PageInstance(parentPageInstance, childDirectory, page, actionClass);
            pagePath.add(pageInstance);
            makePageInstancePath(pagePath, fragmentsIterator);
            return;
        } else {
            if (!params) {
                currentDirectory = new File(currentDirectory, PageInstance.DETAIL);
                params = true;
            }
            parentPageInstance = parentPageInstance.copy();
            parentPageInstance.getParameters().add(nextFragment);
            pagePath.set(pagePath.size() - 1, parentPageInstance);
        }
    }
}

From source file:com.quigley.filesystem.FilesystemPath.java

public FilesystemPath simplify() {
    List<String> elementsCopy = new ArrayList<String>(elements);
    ListIterator<String> i = elementsCopy.listIterator();
    boolean saw = false;
    while (i.hasNext()) {
        String value = i.next();
        if (value.equals(".")) {
            i.remove();//from  w ww .jav  a2s. co  m
        } else if (value.equals("..")) {
            if (saw) {
                if (i.hasPrevious()) {
                    i.remove();
                    i.previous();
                    i.remove();
                }
            }
        } else {
            saw = true;
        }
    }
    FilesystemPath pathCopy = new FilesystemPath(elementsCopy);
    pathCopy.isAbsolute = isAbsolute;

    return pathCopy;
}

From source file:org.gephi.statistics.plugin.GraphDistance.java

public void execute(HierarchicalGraph hgraph, AttributeModel attributeModel) {
    isCanceled = false;//ww  w .  j ava 2  s  . c o m
    AttributeTable nodeTable = attributeModel.getNodeTable();
    AttributeColumn eccentricityCol = nodeTable.getColumn(ECCENTRICITY);
    AttributeColumn closenessCol = nodeTable.getColumn(CLOSENESS);
    AttributeColumn betweenessCol = nodeTable.getColumn(BETWEENNESS);
    if (eccentricityCol == null) {
        eccentricityCol = nodeTable.addColumn(ECCENTRICITY, "Eccentricity", AttributeType.DOUBLE,
                AttributeOrigin.COMPUTED, new Double(0));
    }
    if (closenessCol == null) {
        closenessCol = nodeTable.addColumn(CLOSENESS, "Closeness Centrality", AttributeType.DOUBLE,
                AttributeOrigin.COMPUTED, new Double(0));
    }
    if (betweenessCol == null) {
        betweenessCol = nodeTable.addColumn(BETWEENNESS, "Betweenness Centrality", AttributeType.DOUBLE,
                AttributeOrigin.COMPUTED, new Double(0));
    }

    hgraph.readLock();

    N = hgraph.getNodeCount();

    betweenness = new double[N];
    eccentricity = new double[N];
    closeness = new double[N];
    diameter = 0;
    avgDist = 0;
    shortestPaths = 0;
    radius = Integer.MAX_VALUE;
    HashMap<Node, Integer> indicies = new HashMap<Node, Integer>();
    int index = 0;
    for (Node s : hgraph.getNodes()) {
        indicies.put(s, index);
        index++;
    }

    Progress.start(progress, hgraph.getNodeCount());
    int count = 0;
    for (Node s : hgraph.getNodes()) {
        Stack<Node> S = new Stack<Node>();

        LinkedList<Node>[] P = new LinkedList[N];
        double[] theta = new double[N];
        int[] d = new int[N];
        for (int j = 0; j < N; j++) {
            P[j] = new LinkedList<Node>();
            theta[j] = 0;
            d[j] = -1;
        }

        int s_index = indicies.get(s);

        theta[s_index] = 1;
        d[s_index] = 0;

        LinkedList<Node> Q = new LinkedList<Node>();
        Q.addLast(s);
        while (!Q.isEmpty()) {
            Node v = Q.removeFirst();
            S.push(v);
            int v_index = indicies.get(v);

            EdgeIterable edgeIter = null;
            if (isDirected) {
                edgeIter = ((HierarchicalDirectedGraph) hgraph).getOutEdgesAndMetaOutEdges(v);
            } else {
                edgeIter = hgraph.getEdgesAndMetaEdges(v);
            }

            for (Edge edge : edgeIter) {
                Node reachable = hgraph.getOpposite(v, edge);

                int r_index = indicies.get(reachable);
                if (d[r_index] < 0) {
                    Q.addLast(reachable);
                    d[r_index] = d[v_index] + 1;
                }
                if (d[r_index] == (d[v_index] + 1)) {
                    theta[r_index] = theta[r_index] + theta[v_index];
                    P[r_index].addLast(v);
                }
            }
        }
        double reachable = 0;
        for (int i = 0; i < N; i++) {
            if (d[i] > 0) {
                avgDist += d[i];
                eccentricity[s_index] = (int) Math.max(eccentricity[s_index], d[i]);
                closeness[s_index] += d[i];
                diameter = Math.max(diameter, d[i]);
                reachable++;
            }
        }

        radius = (int) Math.min(eccentricity[s_index], radius);

        if (reachable != 0) {
            closeness[s_index] /= reachable;
        }

        shortestPaths += reachable;

        double[] delta = new double[N];
        while (!S.empty()) {
            Node w = S.pop();
            int w_index = indicies.get(w);
            ListIterator<Node> iter1 = P[w_index].listIterator();
            while (iter1.hasNext()) {
                Node u = iter1.next();
                int u_index = indicies.get(u);
                delta[u_index] += (theta[u_index] / theta[w_index]) * (1 + delta[w_index]);
            }
            if (w != s) {
                betweenness[w_index] += delta[w_index];
            }
        }
        count++;
        if (isCanceled) {
            hgraph.readUnlockAll();
            return;
        }
        Progress.progress(progress, count);
    }

    avgDist /= shortestPaths;//mN * (mN - 1.0f);

    for (Node s : hgraph.getNodes()) {
        AttributeRow row = (AttributeRow) s.getNodeData().getAttributes();
        int s_index = indicies.get(s);

        if (!isDirected) {
            betweenness[s_index] /= 2;
        }
        if (isNormalized) {
            closeness[s_index] = (closeness[s_index] == 0) ? 0 : 1.0 / closeness[s_index];
            betweenness[s_index] /= isDirected ? (N - 1) * (N - 2) : (N - 1) * (N - 2) / 2;
        }
        row.setValue(eccentricityCol, eccentricity[s_index]);
        row.setValue(closenessCol, closeness[s_index]);
        row.setValue(betweenessCol, betweenness[s_index]);
    }
    hgraph.readUnlock();
}

From source file:net.flamefeed.ftb.modpackupdater.FileOperator.java

/**
 * Goes through every file in the deleteQueue and removes it from the file system
 *///from   ww w.j a va2s  .co m

public void executeDeleteQueue() {
    ListIterator<String> deleteQueueIterator = deleteQueue.listIterator();

    while (deleteQueueIterator.hasNext()) {
        new File(pathMinecraft + "/" + deleteQueueIterator.next()).delete();
    }
}

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

public void roiCreated(ImagePlus ip) {
    //if(impoverlay.equals(ip)){
    ImageGateOverlay.clear();/* ww  w .  java2 s . c  om*/
    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])) {
            ImageGateOverlay.add(m);
        }
        //}
    }
    //System.out.println("PROFILING: XYChartPanel... image gate, found " + ImageGateOverlay.size() + " volumes in region");
    //process(xValues,yValues,lValues,xValuesText,yValuesText,lValuesText);

    //System.out.println("PROFILING: XYChartPanel... image gate processed and updated.");
    notifiyUpdatePlotWindowListeners();
}

From source file:org.powertac.officecomplexcustomer.appliances.Appliance.java

/**
 * This is the function utilized to show the information regarding the
 * appliance in question, its variables values etc.
 * //from   w ww  .j  a  v a 2 s .c o  m
 * @return
 */
public void showStatus() {
    // Printing base variables
    log.debug("Name = " + name);
    log.debug("Member Of = " + applianceOf.toString());
    log.debug("Saturation = " + saturation);
    log.debug("Power = " + power);
    log.debug("Cycle Duration = " + cycleDuration);

    // Printing Weekly Function Vector and Load
    log.debug("Weekly Operation Vector and Load = ");
    for (int i = 0; i < OfficeComplexConstants.DAYS_OF_COMPETITION
            + OfficeComplexConstants.DAYS_OF_BOOTSTRAP; i++) {
        log.debug("Day " + i);
        ListIterator<Boolean> iter = weeklyOperation.get(i).listIterator();
        ListIterator<Integer> iter2 = weeklyLoadVector.get(i).listIterator();
        for (int j = 0; j < OfficeComplexConstants.QUARTERS_OF_DAY; j++)
            log.debug("Quarter " + j + " = " + iter.next() + "   Load = " + iter2.next());
    }
}

From source file:edu.oregonstate.eecs.mcplan.sim.OptionSimulator.java

@Override
public void takeAction(final JointAction<Option<S, A>> j) {
    action_count_ += 1;//from  w w w .j  a va  2  s.com
    //      System.out.println( "Setting option " + o + " for player " + turn_ );

    // Find all options that terminated
    final ArrayList<Option<S, A>> term = new ArrayList<Option<S, A>>();
    for (int i = 0; i < turn_.size(); ++i) {
        assert (active_.get(i) == null);
        term.add(terminated_.get(i));
        terminated_.set(i, null);
    }
    pushFrame(turn_, term);

    // Activate new options
    for (int i = 0; i < turn_.size(); ++i) {
        assert (j.get(i) != null);
        final Option<S, A> o = j.get(i);
        active_.set(i, o);
        o.start(base_.state(), base_.t());
    }

    assert (history_.size() == action_count_); // TODO: Debugging

    // Take actions according to active options until one or more
    // options terminates.
    final long told = base_.t();
    final long tnew = told;
    while (true) {
        final S s = base_.state();
        if (base_.isTerminalState()) {
            return;
        }

        // See if any options terminate
        final ListIterator<Option<S, A>> check_itr = active_.listIterator();
        final TIntArrayList next_turn = new TIntArrayList();
        while (check_itr.hasNext()) {
            final Option<S, A> ocheck = check_itr.next();
            if (terminate(s, base_.t(), ocheck)) {
                //               System.out.println( "! Option " + (check_itr.previousIndex()) + " terminated" );
                check_itr.set(null);
                final int pidx = check_itr.previousIndex();
                terminated_.set(pidx, ocheck);
                next_turn.add(pidx);
            }
        }

        // If they do, wait for new options
        if (!next_turn.isEmpty()) {
            turn_ = next_turn;
            return;
        }

        // Construct a JointAction over primitive actions and execute it
        final JointAction.Builder<A> ab = new JointAction.Builder<A>(Nplayers_);
        for (int i = 0; i < Nplayers_; ++i) {
            final Option<S, A> o = active_.get(i);
            assert (o != null);
            o.setState(s, base_.t());
            ab.a(i, o.getAction());
        }
        base_.takeAction(ab.finish());

        //         System.out.println( "Take action " + base_.getTurn() + " " + a );
        history_.peek().steps += 1;
        // TODO: Give pi its reward
        // pi.actionResult( ??? );
    }
}

From source file:edu.iu.daal_linreg.LinRegDaalCollectiveMapper.java

private NumericTable getNumericTableHDFS(DaalContext daal_Context, Configuration conf, String inputFiles,
        int vectorSize, int numRows) throws IOException {
    Path inputFilePaths = new Path(inputFiles);
    List<String> inputFileList = new LinkedList<>();

    try {/*w ww  .jav a  2s.c  o m*/
        FileSystem fs = inputFilePaths.getFileSystem(conf);
        RemoteIterator<LocatedFileStatus> iterator = fs.listFiles(inputFilePaths, true);

        while (iterator.hasNext()) {
            String name = iterator.next().getPath().toUri().toString();
            inputFileList.add(name);
        }

    } catch (IOException e) {
        LOG.error("Fail to get test files", e);
    }
    int dataSize = vectorSize * numRows;
    // float[] data = new float[dataSize];
    double[] data = new double[dataSize];
    long[] dims = { numRows, vectorSize };
    int index = 0;

    FSDataInputStream in = null;

    //loop over all the files in the list
    ListIterator<String> file_itr = inputFileList.listIterator();
    while (file_itr.hasNext()) {
        String file_name = file_itr.next();
        LOG.info("read in file name: " + file_name);

        Path file_path = new Path(file_name);
        try {

            FileSystem fs = file_path.getFileSystem(conf);
            in = fs.open(file_path);

        } catch (Exception e) {
            LOG.error("Fail to open file " + e.toString());
            return null;
        }

        //read file content
        while (true) {
            String line = in.readLine();
            if (line == null)
                break;

            String[] lineData = line.split(",");

            for (int t = 0; t < vectorSize; t++) {
                if (index < dataSize) {
                    // data[index] = Float.parseFloat(lineData[t]);
                    data[index] = Double.parseDouble(lineData[t]);
                    index++;
                } else {
                    LOG.error("Incorrect size of file: dataSize: " + dataSize + "; index val: " + index);
                    return null;
                }

            }
        }

        in.close();

    }

    if (index != dataSize) {
        LOG.error("Incorrect total size of file: dataSize: " + dataSize + "; index val: " + index);
        return null;
    }
    //debug check the vals of data
    // for(int p=0;p<60;p++)
    //     LOG.info("data at: " + p + " is: " + data[p]);

    NumericTable predictionData = new HomogenNumericTable(daal_Context, data, vectorSize, numRows);
    return predictionData;

}