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:TimestreamsTests.java

/**
 * Creates a HMAC for given parameters and returns a URL with security
 * parameters/*from w ww.j a va  2 s .c o  m*/
 * 
 * @param url
 *            is the URL to add the security parameters to
 * @param params
 *            are all the parameters to hash
 * @param now
 *            is a UTC timestamp
 * @return the URL with security parameters
 */
private String getSecurityString(String url, List<String> params, String now) {
    java.util.Collections.sort(params);
    String toHash = "";
    ListIterator<String> it = params.listIterator();
    while (it.hasNext()) {
        toHash += it.next();
    }
    String hmac = hmacString(toHash, PRIKEY, "HmacSHA256");
    String urlStr = url + "?pubkey=" + PUBKEY + "&now=" + now;
    urlStr += "&hmac=" + hmac;
    return urlStr;
}

From source file:mp.teardrop.SongTimeline.java

/**
 * Remove the song with the given id from the timeline.
 *
 * @param id The MediaStore id of the song to remove.
 *///from www.  jav a  2s  .  c o  m
public void removeSong(long id) {
    synchronized (this) {
        saveActiveSongs();

        ArrayList<Song> songs = mSongs;
        ListIterator<Song> it = songs.listIterator();
        while (it.hasNext()) {
            int i = it.nextIndex();
            if (Song.getId(it.next()) == id) {
                if (i < mCurrentPos)
                    --mCurrentPos;
                it.remove();
            }
        }

        broadcastChangedSongs();
    }

    changed();
}

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

private ScreenOverlayType createHistogram(String transportMode, Map<Id, Double> evacuationTimes)
        throws IOException {

    /*//from w w  w .  j a  v a2s. c o m
     * Remove NaN entries from the List
     */
    List<Double> listWithoutNaN = new ArrayList<Double>();
    for (Double d : evacuationTimes.values())
        if (!d.isNaN())
            listWithoutNaN.add(d);

    /*
     * If trip with significant to high evacuation times should be cut off
     */
    if (limitMaxEvacuationTime) {
        double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor;
        ListIterator<Double> iter = listWithoutNaN.listIterator();
        while (iter.hasNext()) {
            double value = iter.next();
            if (value > cutOffValue)
                iter.remove();
        }
    }

    double[] array = new double[listWithoutNaN.size()];
    int i = 0;
    for (double d : listWithoutNaN)
        array[i++] = d;

    JFreeChart chart = createHistogramChart(transportMode, array);
    BufferedImage chartImage = chart.createBufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT);
    BufferedImage image = new BufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT,
            BufferedImage.TYPE_4BYTE_ABGR);

    // clone image and set alpha value
    for (int x = 0; x < OVERALLHISTOGRAMWIDTH; x++) {
        for (int y = 0; y < OVERALLHISTOGRAMHEIGHT; y++) {
            int rgb = chartImage.getRGB(x, y);
            Color c = new Color(rgb);
            int r = c.getRed();
            int b = c.getBlue();
            int g = c.getGreen();
            int argb = 225 << 24 | r << 16 | g << 8 | b; // 225 as transparency value
            image.setRGB(x, y, argb);
        }
    }

    byte[] imageBytes = bufferedImageToByteArray(image);
    this.kmzWriter.addNonKMLFile(imageBytes, transportMode + OVERALLHISTROGRAM);

    ScreenOverlayType overlay = kmlObjectFactory.createScreenOverlayType();
    LinkType icon = kmlObjectFactory.createLinkType();
    icon.setHref(transportMode + OVERALLHISTROGRAM);
    overlay.setIcon(icon);
    overlay.setName("Histogram " + transportMode);
    // place the image top right
    Vec2Type overlayXY = kmlObjectFactory.createVec2Type();
    overlayXY.setX(0.0);
    overlayXY.setY(1.0);
    overlayXY.setXunits(UnitsEnumType.FRACTION);
    overlayXY.setYunits(UnitsEnumType.FRACTION);
    overlay.setOverlayXY(overlayXY);
    Vec2Type screenXY = kmlObjectFactory.createVec2Type();
    screenXY.setX(0.02);
    screenXY.setY(0.98);
    screenXY.setXunits(UnitsEnumType.FRACTION);
    screenXY.setYunits(UnitsEnumType.FRACTION);
    overlay.setScreenXY(screenXY);
    return overlay;
}

From source file:com.abm.mainet.common.service.EmployeeService.java

public List<LookUp> getAllEmployee(List<Object[]> emp) {
    List<LookUp> list = new ArrayList<LookUp>(0);

    ListIterator<Object[]> listIterator = emp.listIterator();
    while (listIterator.hasNext()) {
        Object[] obj = listIterator.next();

        LookUp title = getEmpTitle(obj);
        String fname = (String) obj[1];
        String lname = " ";
        if (obj[2] != null) {
            lname = (String) obj[2];
        }/*w w w  . ja v a2 s  .  c o m*/

        String fullName = " ";

        if (title.getLookUpDesc() != null) {
            fullName = title.getLookUpDesc() + " " + fname + " " + lname;
        } else {
            fullName = " " + fname + " " + lname;
        }
        // fullName = fname + " " + lname;
        LookUp lookUp = new LookUp("", fullName);
        lookUp.setLookUpId((long) obj[4]);
        list.add(lookUp);
    }
    return list;
}

From source file:org.slc.sli.dashboard.unit.client.SDKAPIClientTest.java

@Test
public void testGetAssessmentsForStudent()
        throws URISyntaxException, IOException, MessageProcessingException, SLIClientException {
    String token = "token";
    String key = "studentId";
    String studentId = "288598192";

    String filename = getFilename(MOCK_DATA_DIRECTORY + "common/" + MOCK_ASSESSMENTS_FILE);
    when(mockSdk.read(anyString())).thenReturn(fromFileWithValue(filename, studentId, key));

    List<GenericEntity> assessments = client.getAssessmentsForStudent(token, studentId);

    assertNotNull(assessments);// w w w .  j av a2 s  . c o m
    assertEquals(18, assessments.size());
    ListIterator<GenericEntity> li = assessments.listIterator();
    int count = 0;
    while (li.hasNext()) {
        GenericEntity ge = li.next();
        assertEquals(ge.getString(key), studentId);
        if (ge.getString("assessmentName").equals("StateTest_READING")) {
            count++;
        }
    }
    assertEquals(count, 6);
}

From source file:geogebra.common.kernel.implicit.AlgoIntersectImplicitpolys.java

private void insert(double[] pair) {
    ListIterator<double[]> it = valPairs.listIterator();
    double eps = 1E-3; //find good value...
    while (it.hasNext()) {
        double[] p = it.next();
        if (Kernel.isGreater(p[0], pair[0], eps)) {
            it.previous();/*from   w w  w  .ja  va  2 s. c  o m*/
            break;
        }
        if (Kernel.isEqual(p[0], pair[0], eps)) {
            if (Kernel.isGreater(p[1], pair[1], eps)) {
                it.previous();
                break;
            }
            if (Kernel.isEqual(p[1], pair[1], eps))
                return; //do not add
        }
    }
    it.add(pair);
}

From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java

/**
 * Used by find dialog/*from ww  w  . ja  v a2s.co  m*/
 */
public boolean findNext(SearchContext context) {
    SpreadSheetSearchContext ctx = (SpreadSheetSearchContext) context;

    int row = this.getCurrentRow();
    // make sure in bounds
    if (row < 0)
        row = 0;
    if (row >= getCache().getSize())
        row = getCache().getSize() - 1;

    ListIterator i = getCache().getIterator(row);
    if (ctx.getRow() != -1) { // after the first search, need to move ahead or back
        if (ctx.isForward())
            if (i.hasNext())
                i.next();
            else if (i.hasPrevious())
                i.previous();
    }

    boolean found = false;
    GraphicNode gnode = null;
    Object obj;
    Node node;
    while (ctx.isForward() ? i.hasNext() : i.hasPrevious()) {
        gnode = (GraphicNode) (ctx.isForward() ? i.next() : i.previous());
        if (gnode.isVoid())
            continue;
        node = gnode.getNode();
        obj = node.getImpl();
        if (ctx.matches(obj)) {
            found = true;
            break;
        }
    }
    if (found) {
        int r = getCache().getRowAt(gnode);
        int col = getFieldArray().indexOf(ctx.getField()) - 1;
        this.changeSelection(r, col, false, false);
        ctx.setRow(r);
    }
    return found;
}

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

@Override
public int getSelectedObjects() {
    Gate gate;//from w  ww  . ja  v  a 2 s . co  m
    ListIterator<Gate> gate_itr = gates.listIterator();

    //.get
    int selected = 0;
    int gated = 0;
    int total = 0;

    ArrayList<MicroObject> result = new ArrayList<MicroObject>();

    while (gate_itr.hasNext()) {
        gate = gate_itr.next();
        if (gate.getSelected()) {
            Path2D path = gate.createPath2DInChartSpace();

            ArrayList<MicroObject> volumes = (ArrayList) this.plotvalues.get(1);
            MicroObjectModel volume;

            double xValue = 0;
            double yValue = 0;

            ListIterator<MicroObject> it = volumes.listIterator();
            try {
                while (it.hasNext()) {
                    volume = it.next();
                    if (volume != null) {
                        xValue = ((Number) processPosition(currentX, (MicroObject) volume)).doubleValue();
                        yValue = ((Number) processPosition(currentY, (MicroObject) volume)).doubleValue();
                        if (path.contains(xValue, yValue)) {
                            result.add((MicroObject) volume);
                        }
                    }
                }
            } catch (NullPointerException e) {
                return 0;
            }
        }
    }

    //System.out.println("RESULT: total gates " + gates.size() + ": " + this.getTitle() + ", Gated: " + selected + ", Total: " + total + ", for: " + 100 * (new Double(selected).doubleValue() / (new Double(total)).doubleValue()) + "%");
    return result.size();
}

From source file:org.slc.sli.dashboard.unit.client.SDKAPIClientTest.java

@Test
public void testGetSchools()
        throws URISyntaxException, IOException, MessageProcessingException, SLIClientException {
    SDKAPIClient client = new SDKAPIClient() {
        @Override/*from  w w w  .ja  v a2s.c o  m*/
        public String getId(String token) {
            return null;
        }

        @Override
        public List<GenericEntity> getSectionsForTeacher(String teacherId, String token,
                Map<String, String> params) {
            return null;
        }

        @Override
        public List<GenericEntity> getSectionsForNonEducator(String token, Map<String, String> params) {
            return null;
        }
    };
    SLIClientFactory factory = mock(SLIClientFactory.class);
    when(factory.getClientWithSessionToken(anyString())).thenReturn(mockSdk);
    client.setClientFactory(factory);

    SecurityContextHolder.getContext().setAuthentication(new Authentication() {
        @Override
        public String getName() {
            return null;
        }

        @Override
        public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        }

        @Override
        public boolean isAuthenticated() {
            return false;
        }

        @Override
        public Object getPrincipal() {
            return null;
        }

        @Override
        public Object getDetails() {
            return null;
        }

        @Override
        public Object getCredentials() {
            return null;
        }

        @Override
        public Collection<GrantedAuthority> getAuthorities() {
            return Collections.emptyList();
        }
    });

    String token = "token";
    String key = "schoolId";
    String[] idArr = { "Illinois PS145", "Illinois PS200" };
    List<String> schoolIds = Arrays.asList(idArr);

    String filename = getFilename(MOCK_DATA_DIRECTORY + "common/" + MOCK_SCHOOL_FILE);
    when(mockSdk.read(anyString())).thenReturn(fromFileWithIDList(filename, schoolIds, key));

    List<GenericEntity> schoolList = client.getSchools(token, schoolIds);

    assertNotNull(schoolList);
    assertEquals(2, schoolList.size());
    ListIterator<GenericEntity> li = schoolList.listIterator();
    while (li.hasNext()) {
        assertTrue(schoolIds.contains(li.next().getString(key)));
    }
}

From source file:com.tacitknowledge.util.migration.jdbc.SqlScriptMigrationTask.java

/**
 * Executes the passed sql in the passed context.
 *
 * @param ctx       the <code>MigrationContext> to execute the SQL in
 * @param sqlToExec the SQL to execute/*from  w  w  w.j  av  a  2  s  .c om*/
 * @throws MigrationException thrown if there is an error when executing the SQL
 */
private void executeSql(MigrationContext ctx, String sqlToExec) throws MigrationException {
    JdbcMigrationContext context = (JdbcMigrationContext) ctx;

    Connection conn = null;
    Statement stmt = null;
    String sqlStatement = "";
    ListIterator listIterator = null;
    try {
        conn = context.getConnection();

        // cleaning the slate before we execute the patch.
        // This was inspired by a Sybase ASE server that did not allow
        // ALTER TABLE statements in multi-statement transactions.  Instead of putting
        // a if(sybase) conditional, we decided to clean the slate for everyone.
        context.commit();

        List sqlStatements = getSqlStatements(context, sqlToExec);
        for (listIterator = sqlStatements.listIterator(); listIterator.hasNext();) {
            sqlStatement = (String) listIterator.next();
            log.debug(getName() + ": Attempting to execute: " + sqlStatement);

            stmt = conn.createStatement();

            // handle sybase special case with illegal commands in multi
            // command transactions
            if (isSybase(context) && SybaseUtil.containsIllegalMultiStatementTransactionCommand(sqlStatement)) {
                log.warn("Committing current transaction since patch " + getName()
                        + " contains commands that are not allowed in multi statement"
                        + " transactions.  If the patch contains errors, this patch may"
                        + " not be rolled back cleanly.");
                context.commit();
                stmt.execute(sqlStatement);
                context.commit();
            } else // regular case
            {
                stmt.execute(sqlStatement);
            }

            SqlUtil.close(null, stmt, null);
        }

        context.commit();
    } catch (Exception e) {
        String message = getName() + ": Error running SQL at statement number " + listIterator.previousIndex()
                + " \"" + sqlStatement + "\"";
        log.error(message, e);

        if (e instanceof SQLException) {
            if (((SQLException) e).getNextException() != null) {
                log.error("Chained SQL Exception", ((SQLException) e).getNextException());
            }
        }

        context.rollback();
        throw new MigrationException(message, e);
    } finally {
        SqlUtil.close(null, stmt, null);
    }
}