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.amazonaws.services.kinesis.clientlibrary.lib.worker.ShardConsumerTest.java

private void verifyConsumedRecords(List<Record> expectedRecords, List<Record> actualRecords) {
    //@formatter:on
    assertThat(actualRecords.size(), is(equalTo(expectedRecords.size())));
    ListIterator<Record> expectedIter = expectedRecords.listIterator();
    ListIterator<Record> actualIter = actualRecords.listIterator();
    for (int i = 0; i < expectedRecords.size(); ++i) {
        assertThat(actualIter.next(), is(equalTo(expectedIter.next())));
    }/*w  ww  .  j a v a 2s  .c  om*/
}

From source file:de.codesourcery.asm.controlflow.AbstractBlock.java

@Override
public int getIndexOfSuperConstructorCall(MethodNode method) {
    if (!method.name.equals("<init>")) {
        return -1;
    }//from  w  ww  . ja  va2  s  . c om

    @SuppressWarnings("unchecked")
    final ListIterator<AbstractInsnNode> iterator = method.instructions.iterator();
    for (int index = 0; iterator.hasNext(); index++) {
        final AbstractInsnNode instruction = iterator.next();
        if (containsInstructionNum(index) && instruction.getOpcode() == Opcodes.INVOKESPECIAL) {
            final MethodInsnNode invocation = (MethodInsnNode) instruction;
            if (invocation.name.equals("<init>")) {
                return index;
            }
        }
    }
    return -1;
}

From source file:de.codesourcery.asm.controlflow.AbstractBlock.java

@Override
public String disassemble(MethodNode method, boolean includeVirtual, boolean printInsnIndices) {

    final StringBuilder builder = new StringBuilder();

    @SuppressWarnings("unchecked")
    final ListIterator<AbstractInsnNode> iterator = method.instructions.iterator();
    for (int index = 0; iterator.hasNext(); index++) {
        final AbstractInsnNode instruction = iterator.next();

        if (containsInstructionNum(index)) {
            String line = Disassembler.disassemble(instruction, method, includeVirtual, printInsnIndices);
            if (line != null) {
                if (builder.length() > 0) {
                    builder.append("\n");
                }//from  w  w w  .  java2s.c o  m
                builder.append(line);
            }
        }
    }
    return builder.toString();
}

From source file:org.powertac.householdcustomer.persons.Person.java

/**
 * This function fills out the daily routine with the leisure activity of the
 * day, if there is one for the person in question for the certain weekday.
 * /*from  w  ww.ja v  a 2s .c  o  m*/
 * @param weekday
 * @param gen
 * @return
 */
void addLeisure(int weekday) {
    // Create auxiliary variables
    ListIterator<Integer> iter = leisureVector.listIterator();
    Status st;

    while (iter.hasNext()) {
        if (iter.next() == weekday) {
            int start = VillageConstants.START_OF_LEISURE + gen.nextInt(VillageConstants.LEISURE_WINDOW);
            for (int i = start; i < start + leisureDuration; i++) {
                st = Status.Leisure;
                dailyRoutine.set(i, st);
                if (i == VillageConstants.QUARTERS_OF_DAY - 1)
                    break;
            }
        }
    }
}

From source file:es.tid.fiware.rss.service.SettlementManager.java

/**
 * Get files from path./*from   ww w  . j ava2 s.  c om*/
 * 
 * @param path
 * @return
 */
public List<RSSFile> getSettlementFilesOfPath(String path) {
    // Opening/creating the folder
    File folder = new File(path);
    List<RSSFile> rssFilesList = new ArrayList<RSSFile>();
    RSSFile rssf = new RSSFile();

    if (folder.exists() && folder.isDirectory()) {
        File[] files = folder.listFiles();
        Arrays.sort(files);

        if (files.length > 0) {
            List<File> fileList = new ArrayList<File>(Arrays.asList(files));
            ListIterator<File> lit = fileList.listIterator();

            while (lit.hasNext()) {
                File file = lit.next();
                logger.info(file.getAbsolutePath());

                if (file.isDirectory()) {
                    logger.debug("Is directory. Getting more files...");
                    File[] moreFiles = file.listFiles();
                    Arrays.sort(moreFiles);
                    if (moreFiles.length > 0) {
                        for (File f : moreFiles) {
                            lit.add(f);
                            lit.previous();
                        }
                    }
                } else {
                    rssf = new RSSFile();
                    rssf.setTxName(file.getName());
                    rssf.setTxUrl(file.getAbsolutePath());
                    rssFilesList.add(rssf);
                    logger.debug("File added");
                }
            }
        }
    }
    return rssFilesList;
}

From source file:com.caricah.iotracah.datastore.ignitecache.internal.impl.SubscriptionFilterHandler.java

public Observable<IotSubscriptionFilter> createTree(String partitionId, List<String> topicFilterTreeRoute) {

    return Observable.create(observer -> {

        try {//www. j a  v a 2  s . com

            List<String> growingTitles = new ArrayList<>();
            LinkedList<Long> growingParentIds = new LinkedList<>();

            ListIterator<String> pathIterator = topicFilterTreeRoute.listIterator();

            while (pathIterator.hasNext()) {

                growingTitles.add(pathIterator.next());

                IotSubscriptionFilterKey iotSubscriptionFilterKey = keyFromList(partitionId, growingTitles);
                Observable<IotSubscriptionFilter> filterObservable = getByKeyWithDefault(
                        iotSubscriptionFilterKey, null);

                filterObservable.subscribe(internalSubscriptionFilter -> {

                    if (null == internalSubscriptionFilter) {
                        internalSubscriptionFilter = new IotSubscriptionFilter();
                        internalSubscriptionFilter.setPartitionId(partitionId);
                        internalSubscriptionFilter.setName(iotSubscriptionFilterKey.getName());
                        internalSubscriptionFilter.setId(getIdSequence().incrementAndGet());

                        if (growingParentIds.isEmpty()) {
                            internalSubscriptionFilter.setParentId(0l);
                        } else {
                            internalSubscriptionFilter.setParentId(growingParentIds.getLast());
                        }
                        save(iotSubscriptionFilterKey, internalSubscriptionFilter);
                    }

                    growingParentIds.add(internalSubscriptionFilter.getId());

                    if (growingTitles.size() == topicFilterTreeRoute.size())
                        observer.onNext(internalSubscriptionFilter);

                }, throwable -> {
                }, () -> {

                    if (!pathIterator.hasNext()) {

                        observer.onCompleted();

                    }

                });
            }

        } catch (Exception e) {
            observer.onError(e);
        }

    });
}

From source file:mediathek.controller.IoXmlSchreiben.java

private void xmlSchreibenProg(Daten daten) {
    ListIterator<DatenPset> iterator;
    //Proggruppen schreiben
    DatenPset datenPset;//from w ww  . j a  v a2s. com
    ListIterator<DatenProg> it;
    iterator = daten.listePset.listIterator();
    while (iterator.hasNext()) {
        datenPset = iterator.next();
        xmlSchreibenDaten(DatenPset.PROGRAMMSET, DatenPset.COLUMN_NAMES_, datenPset.arr, false);
        it = datenPset.getListeProg().listIterator();
        while (it.hasNext()) {
            xmlSchreibenDaten(DatenProg.PROGRAMM, DatenProg.COLUMN_NAMES_, it.next().arr, false);
        }
    }
}

From source file:de.codesourcery.asm.controlflow.AbstractBlock.java

@Override
public int getByteCodeInstructionCount(MethodNode method) {

    final InsnList instructions = method.instructions;
    @SuppressWarnings("unchecked")
    final ListIterator<AbstractInsnNode> iterator = instructions.iterator();

    int count = 0;
    for (int index = 0; iterator.hasNext(); index++) {
        final AbstractInsnNode node = iterator.next();
        if (containsInstructionNum(index)) {
            final int opCode = node.getOpcode();
            if (opCode >= 0 && opCode < Printer.OPCODES.length) {
                count++;/*  ww  w. j  av a 2s. c o  m*/
            }
        }
    }
    return count;
}

From source file:com.berinchik.sip.FlexibleCommunicationServlet.java

@Override
protected void doRegister(SipServletRequest request) throws ServletException, IOException {

    logger.trace("Got REGISTER:\n" + request);
    normaliseRegisterRequest(request);/*  w  ww .  ja  v a 2  s  . co m*/
    logger.trace("normalisation performed");
    logMessageInfo(request);

    Registrar registrar = CommonUtils.getRegistrarHelper(request);

    URI toURI = request.getTo().getURI();

    ListIterator<Address> contacts = request.getAddressHeaders(CommonUtils.SC_CONTACT_HEADER);

    Address firstContact = null;
    if (contacts.hasNext()) {
        firstContact = contacts.next();
        contacts.previous();
        logger.trace("contact: " + firstContact);
    }

    SipServletResponse resp = null;

    try {
        logger.info("trying to register");
        if (registrar == null) {
            logger.error("registrar not initialised!!!");
            throw new RuntimeException("Registrar is not initialised");
        }

        if (!registrar.isPrimary(toURI.toString())) {
            logger.debug("Primary user " + toURI + " not found during registration");
            resp = request.createResponse(SC_NOT_FOUND, "No such user");
        } else if (firstContact == null) {
            logger.debug("No contact headers during registration to " + toURI + "\nReturning all bindings");

            resp = registrar.createRegisterSuccessResponse(request);
        } else if (firstContact.isWildcard()) {
            logger.debug("First contact is Wildcard");
            if (request.getExpires() == 0) {
                logger.debug("Contact = *, Expire = 0: complete de registration");
                registrar.deregisterUser(toURI.toString());
                resp = request.createResponse(SC_OK, "Ok");
                resp.removeHeader(CommonUtils.SC_EXPIRES_HEADER);
            } else {
                logger.debug("Contact = *, Expire != 0: request could not be understood");
                resp = request.createResponse(SC_BAD_REQUEST, "Bad request");
            }
        } else if (request.getExpires() == 0) {
            logger.info("Request is recognized as de registration" + "\ncontact - " + firstContact + "\nuser - "
                    + toURI);
            registrar.deregisterUser(toURI.toString(), firstContact.getURI().toString());
            resp = request.createResponse(SC_OK, "Ok");
            resp.removeHeader(CommonUtils.SC_EXPIRES_HEADER);
        } else {
            logger.debug("Request is recognized as registration request");
            while (contacts.hasNext()) {

                Address nextContact = contacts.next();

                logger.trace("Trying to register contact " + nextContact.getURI() + " to user " + toURI);

                int expires = CommonUtils.getExpires(nextContact, request);

                registrar.registerUser(toURI.toString(), nextContact.getURI().toString(), expires);
            }

            resp = registrar.createRegisterSuccessResponse(request);
        }
    } catch (SQLException e) {
        logger.error("SQL Exception durin registration", e);
        resp = request.createResponse(SC_SERVER_INTERNAL_ERROR, "Server internal error");
    } catch (RuntimeException e) {
        logger.error("Runtime exception", e);
        resp = request.createResponse(SC_SERVER_INTERNAL_ERROR, "Server internal error");
    }

    logger.trace("Sending response: \n" + resp);

    resp.send();
}

From source file:com.clearcenter.mobile_demo.mdStatusActivity.java

public void updateData() {
    JSONObject json_data;/*from w w w  . j  a  va2 s  . com*/

    String projection[] = new String[] { mdDeviceSamples.DATA };

    Cursor cursor = getContentResolver().query(mdDeviceSamples.CONTENT_URI, projection,
            mdDeviceSamples.NICKNAME + " = ?", new String[] { account_nickname }, null);

    int rows = 0;
    try {
        rows = cursor.getCount();
    } catch (NullPointerException e) {
    }

    Log.d(TAG, "Matches: " + rows);

    if (rows == 0) {
        Log.d(TAG, "No rows match for nickname: " + account_nickname);
        cursor.close();
        return;
    }

    cursor.moveToLast();

    String data = cursor.getString(cursor.getColumnIndex(mdDeviceSamples.DATA));

    try {
        json_data = new JSONObject(data);
        if (json_data.has("hostname"))
            hostname_textview.setText("Hostname: " + json_data.getString("hostname"));
        if (json_data.has("name") && json_data.has("release")) {
            final String release = json_data.getString("name") + " " + json_data.getString("release");
            release_textview.setText("Release: " + release);
        }
        if (json_data.has("time_locale")) {
            time_textview.setText("Clock: " + json_data.getString("time_locale"));
        }

        if (rows >= 2) {
            bw_graphview.reset();
            loadavg_graphview.reset();
            mem_graphview.reset();

            if (rows <= samples)
                cursor.moveToFirst();
            else
                cursor.move(-samples);

            long unix_time = 0;
            double bw_up = 0.0;
            double bw_down = 0.0;

            do {
                data = cursor.getString(cursor.getColumnIndex(mdDeviceSamples.DATA));

                final List<JSONObject> samples = sortedSamplesList(data);
                ListIterator<JSONObject> li = samples.listIterator();

                while (li.hasNext()) {
                    json_data = li.next();

                    if (unix_time == 0) {
                        bw_up = json_data.getDouble("bandwidth_up");
                        bw_down = json_data.getDouble("bandwidth_down");
                        unix_time = Long.valueOf(json_data.getString("time"));
                        continue;
                    }

                    long diff = Long.valueOf(json_data.getString("time")) - unix_time;

                    double rate_up = (json_data.getDouble("bandwidth_up") - bw_up) / diff;
                    double rate_down = (json_data.getDouble("bandwidth_down") - bw_down) / diff;

                    if (rate_up < 0.0)
                        rate_up = 0.0;
                    if (rate_down < 0.0)
                        rate_down = 0.0;

                    bw_graphview.addSample(bw_graph_up, unix_time, (float) rate_up);
                    bw_graphview.addSample(bw_graph_down, unix_time, (float) rate_down);

                    //                        Log.d(TAG, "time: " + diff +
                    //                            ", rate_up: " + rate_up + ", rate_down: " + rate_down);
                    bw_up = json_data.getDouble("bandwidth_up");
                    bw_down = json_data.getDouble("bandwidth_down");

                    loadavg_graphview.addSample(loadavg_graph_5min, unix_time,
                            (float) json_data.getDouble("loadavg_5min"));
                    loadavg_graphview.addSample(loadavg_graph_15min, unix_time,
                            (float) json_data.getDouble("loadavg_15min"));

                    mem_graphview.addSample(mem_graph_active, unix_time,
                            (float) json_data.getDouble("mem_active"));
                    mem_graphview.addSample(mem_graph_swap, unix_time,
                            (float) json_data.getDouble("mem_swap_used"));

                    unix_time = Long.valueOf(json_data.getString("time"));
                }
            } while (cursor.moveToNext());

            bw_graphview.update();
            loadavg_graphview.update();
            mem_graphview.update();
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSONException", e);
    }

    cursor.close();
}