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:annis.gui.frequency.FrequencyResultPanel.java

private String createFieldsString() {
    StringBuilder sb = new StringBuilder();

    ListIterator<FrequencyTableEntry> it = freqDefinition.listIterator();
    while (it.hasNext()) {
        FrequencyTableEntry e = it.next();

        sb.append(e.getReferencedNode()).append(":");
        if (e.getType() == FrequencyTableEntryType.span) {
            sb.append("tok");
        } else {/*from www . j a v a 2 s.  com*/
            sb.append(e.getKey());
        }

        if (it.hasNext()) {
            sb.append(",");
        }
    }

    return sb.toString();
}

From source file:com.google.gwt.emultest.java.util.ListTestBase.java

public void testListIteratorHasNextHasPreviousAndIndexes() {
    List l = makeEmptyList();//w w  w. ja va  2s.com
    ListIterator i = l.listIterator();
    assertFalse(i.hasNext());
    assertFalse(i.hasPrevious());
    i.add(new Integer(1));
    assertEquals(1, i.nextIndex());
    assertEquals(0, i.previousIndex());
    i = l.listIterator();
    assertEquals(0, i.nextIndex());
    assertEquals(-1, i.previousIndex());
    assertTrue(i.hasNext());
    assertFalse(i.hasPrevious());
    i.next();
    assertEquals(1, i.nextIndex());
    assertEquals(0, i.previousIndex());
    assertFalse(i.hasNext());
    assertTrue(i.hasPrevious());
}

From source file:de.fhg.iais.asc.ui.MyCortexStarter.java

private void handleNextArgument(ListIterator<String> argIterator) {
    String arg = argIterator.next();
    if (StringUtils.isEmpty(arg)) {
        return;//from   ww w.  j  a  v  a 2 s  . c o  m
    }

    if (arg.equals("-conf")) {
        if (!argIterator.hasNext()) {
            LOG.warn("Found option \"-conf\" without [name of configuration] as next argument - ignored");
        } else {
            this.config = argIterator.next();
        }
    } else if (!handleServerArgument(arg)) {
        LOG.warn("Found unknown argument \"{}\" - ignored", arg);
    }
}

From source file:com.krawler.esp.utils.ConfigReader.java

private synchronized Properties getProps() {
    if (properties == null) {
        Properties defaults = new Properties();
        Properties newProps = new Properties(defaults);
        ListIterator i = resourceNames.listIterator();
        while (i.hasNext()) {
            if (i.nextIndex() == 0) { // load defaults
                loadResource(defaults, i.next(), false);
            } else if (i.nextIndex() == resourceNames.size() - 1) { // load
                // site
                loadResource(newProps, i.next(), true);
            } else { // load intermediate
                loadResource(newProps, i.next(), false);
            }//from  w w  w .  ja va  2 s. co  m
        }
        properties = newProps;
    }
    return properties;
}

From source file:net.oneandone.stool.overview.ProcessesController.java

@RequestMapping(value = "{id}/log", method = RequestMethod.GET)
@ResponseBody//from  w w  w.  j  av  a2 s  .  com
public ResponseEntity log(@PathVariable(value = "id") String id,
        @RequestParam(defaultValue = "0") Integer index) throws IOException, InterruptedException {
    Node logfile;
    StringBuilder output;
    MultiValueMap<String, String> headers;
    output = new StringBuilder();
    List<String> strings;
    ListIterator<String> iterator;

    headers = new HttpHeaders();

    try {
        logfile = logFile(id);
    } catch (ResourceNotFoundException e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    strings = logfile.readLines();
    iterator = strings.listIterator(index);
    while (iterator.hasNext()) {
        output.append(iterator.next()).append("<br />");
    }
    headers.set("X-index", "" + strings.size());
    return new ResponseEntity<>(output.toString(), headers, HttpStatus.OK);
}

From source file:com.projity.algorithm.buffer.GroupedCalculatedValues.java

public void mergeIn(GroupedCalculatedValues add) {
    ListIterator baseIterator = values.listIterator();
    ListIterator addIterator = add.values.listIterator();
    Point basePoint = baseIterator.hasNext() ? (Point) baseIterator.next() : null;
    long start = basePoint.date;
    Point previousAddPoint = null;
    Point addPoint = addIterator.hasNext() ? (Point) addIterator.next() : null;
    while (basePoint != null && addPoint != null) {
        //TODO handle overlaps
        if (basePoint.compareTo(addPoint) >= 0) {
            if (addPoint.date >= start) {
                basePoint.value += addPoint.value;
                if (basePoint.date == start && previousAddPoint != null) { // if first time
                    double proratedAmount = ((double) addPoint.date - start)
                            / (addPoint.date - previousAddPoint.date);
                    if (proratedAmount > 0)
                        basePoint.value += (previousAddPoint.value * proratedAmount);
                }/* w  ww .  j  a v a  2s  .c o  m*/
            }
            previousAddPoint = addPoint;
            addPoint = addIterator.hasNext() ? (Point) addIterator.next() : null;
            continue;
        }

        if (baseIterator.hasNext()) {
            basePoint = (Point) baseIterator.next();
        } else {
            if (previousAddPoint != null) {// handle end boundary
                double proratedAmount = ((double) (basePoint.date - previousAddPoint.date))
                        / (addPoint.date - previousAddPoint.date);
                if (proratedAmount > 0)
                    basePoint.value += (addPoint.value * proratedAmount);
            }
            basePoint = null;
        }
    }
}

From source file:msearch.filmlisten.MSFilmlisteSchreiben.java

public void filmlisteSchreibenJson(String datei, ListeFilme listeFilme) {
    MSLog.systemMeldung("Filme schreiben (" + listeFilme.size() + " Filme) :");
    File file = new File(datei);
    File dir = new File(file.getParent());
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            MSLog.fehlerMeldung(915236478, MSLog.FEHLER_ART_PROG,
                    "MSearchIoXmlFilmlisteSchreiben.xmlSchreibenStart",
                    "Kann den Pfad nicht anlegen: " + dir.toString());
        }/*w ww  . j  a va2  s .  c o m*/
    }
    MSLog.systemMeldung("   --> Start Schreiben nach: " + datei);
    try {
        String sender = "", thema = "";
        JsonFactory jsonF = new JsonFactory();
        JsonGenerator jg;
        if (datei.endsWith(MSConst.FORMAT_XZ)) {
            LZMA2Options options = new LZMA2Options();
            XZOutputStream out = new XZOutputStream(new FileOutputStream(file), options);
            jg = jsonF.createGenerator(out);
        } else if (datei.endsWith(MSConst.FORMAT_BZ2)) {
            bZip2CompressorOutputStream = new BZip2CompressorOutputStream(new FileOutputStream(file),
                    9 /*Blocksize: 1 - 9*/);
            jg = jsonF.createGenerator(bZip2CompressorOutputStream, JsonEncoding.UTF8);
        } else if (datei.endsWith(MSConst.FORMAT_ZIP)) {
            zipOutputStream = new ZipOutputStream(new FileOutputStream(file));
            ZipEntry entry = new ZipEntry(MSConst.XML_DATEI_FILME);
            zipOutputStream.putNextEntry(entry);
            jg = jsonF.createGenerator(zipOutputStream, JsonEncoding.UTF8);
        } else {
            jg = jsonF.createGenerator(new File(datei), JsonEncoding.UTF8);
        }
        jg.useDefaultPrettyPrinter(); // enable indentation just to make debug/testing easier
        jg.writeStartObject();
        // Infos zur Filmliste
        jg.writeArrayFieldStart(ListeFilme.FILMLISTE);
        for (int i = 0; i < ListeFilme.MAX_ELEM; ++i) {
            jg.writeString(listeFilme.metaDaten[i]);
        }
        jg.writeEndArray();
        // Infos der Felder in der Filmliste
        jg.writeArrayFieldStart(ListeFilme.FILMLISTE);
        for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) {
            jg.writeString(DatenFilm.COLUMN_NAMES[DatenFilm.COLUMN_NAMES_JSON[i]]);
        }
        jg.writeEndArray();
        //Filme schreiben
        ListIterator<DatenFilm> iterator;
        DatenFilm datenFilm;
        iterator = listeFilme.listIterator();
        while (iterator.hasNext()) {
            datenFilm = iterator.next();
            jg.writeArrayFieldStart(DatenFilm.FILME_);
            for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) {
                int m = DatenFilm.COLUMN_NAMES_JSON[i];
                if (m == DatenFilm.FILM_SENDER_NR) {
                    if (datenFilm.arr[m].equals(sender)) {
                        jg.writeString("");
                    } else {
                        sender = datenFilm.arr[m];
                        jg.writeString(datenFilm.arr[m]);
                    }
                } else if (m == DatenFilm.FILM_THEMA_NR) {
                    if (datenFilm.arr[m].equals(thema)) {
                        jg.writeString("");
                    } else {
                        thema = datenFilm.arr[m];
                        jg.writeString(datenFilm.arr[m]);
                    }
                } else {
                    jg.writeString(datenFilm.arr[m]);
                }
            }
            jg.writeEndArray();
        }
        jg.writeEndObject();
        jg.close();
        MSLog.systemMeldung("   --> geschrieben!");
    } catch (Exception ex) {
        MSLog.fehlerMeldung(846930145, MSLog.FEHLER_ART_PROG, "IoXmlSchreiben.FilmeSchreiben", ex,
                "nach: " + datei);
    }
}

From source file:msearch.io.MSFilmlisteSchreiben.java

public void filmlisteSchreibenJson(String datei, ListeFilme listeFilme) {
    MSLog.systemMeldung("Filme Schreiben (" + listeFilme.size() + " Filme) :");
    File file = new File(datei);
    File dir = new File(file.getParent());
    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            MSLog.fehlerMeldung(915236478, MSLog.FEHLER_ART_PROG,
                    "MSearchIoXmlFilmlisteSchreiben.xmlSchreibenStart",
                    "Kann den Pfad nicht anlegen: " + dir.toString());
        }//from ww  w . ja  va2s . com
    }
    MSLog.systemMeldung("   --> Start Schreiben nach: " + datei);
    try {
        String sender = "", thema = "";
        JsonFactory jsonF = new JsonFactory();
        JsonGenerator jg;
        if (datei.endsWith(MSConst.FORMAT_XZ)) {
            LZMA2Options options = new LZMA2Options();
            XZOutputStream out = new XZOutputStream(new FileOutputStream(file), options);
            jg = jsonF.createGenerator(out);
        } else if (datei.endsWith(MSConst.FORMAT_BZ2)) {
            bZip2CompressorOutputStream = new BZip2CompressorOutputStream(new FileOutputStream(file),
                    9 /*Blocksize: 1 - 9*/);
            jg = jsonF.createGenerator(bZip2CompressorOutputStream, JsonEncoding.UTF8);
        } else if (datei.endsWith(MSConst.FORMAT_ZIP)) {
            zipOutputStream = new ZipOutputStream(new FileOutputStream(file));
            ZipEntry entry = new ZipEntry(MSConst.XML_DATEI_FILME);
            zipOutputStream.putNextEntry(entry);
            jg = jsonF.createGenerator(zipOutputStream, JsonEncoding.UTF8);
        } else {
            jg = jsonF.createGenerator(new File(datei), JsonEncoding.UTF8);
        }
        jg.useDefaultPrettyPrinter(); // enable indentation just to make debug/testing easier
        jg.writeStartObject();
        // Infos zur Filmliste
        jg.writeArrayFieldStart(ListeFilme.FILMLISTE);
        for (int i = 0; i < ListeFilme.MAX_ELEM; ++i) {
            jg.writeString(listeFilme.metaDaten[i]);
        }
        jg.writeEndArray();
        // Infos der Felder in der Filmliste
        jg.writeArrayFieldStart(ListeFilme.FILMLISTE);
        for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) {
            jg.writeString(DatenFilm.COLUMN_NAMES[DatenFilm.COLUMN_NAMES_JSON[i]]);
        }
        jg.writeEndArray();
        //Filme schreiben
        ListIterator<DatenFilm> iterator;
        DatenFilm datenFilm;
        iterator = listeFilme.listIterator();
        while (iterator.hasNext()) {
            datenFilm = iterator.next();
            jg.writeArrayFieldStart(DatenFilm.FILME_);
            for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) {
                int m = DatenFilm.COLUMN_NAMES_JSON[i];
                if (m == DatenFilm.FILM_SENDER_NR) {
                    if (datenFilm.arr[m].equals(sender)) {
                        jg.writeString("");
                    } else {
                        sender = datenFilm.arr[m];
                        jg.writeString(datenFilm.arr[m]);
                    }
                } else if (m == DatenFilm.FILM_THEMA_NR) {
                    if (datenFilm.arr[m].equals(thema)) {
                        jg.writeString("");
                    } else {
                        thema = datenFilm.arr[m];
                        jg.writeString(datenFilm.arr[m]);
                    }
                } else {
                    jg.writeString(datenFilm.arr[m]);
                }
            }
            jg.writeEndArray();
        }
        jg.writeEndObject();
        jg.close();
        MSLog.systemMeldung("   --> geschrieben!");
    } catch (Exception ex) {
        MSLog.fehlerMeldung(846930145, MSLog.FEHLER_ART_PROG, "IoXmlSchreiben.FilmeSchreiben", ex,
                "nach: " + datei);
    }
}

From source file:eu.scidipes.toolkits.pawebapp.web.ItemsController.java

public String editItemHelper(final List<Form> formSubset, final Form form, final Model model,
        final RedirectAttributes redirectAttrs) {
    final ListIterator<Form> formIterator = formSubset.listIterator();

    while (formIterator.hasNext()) {
        final Form theForm = formIterator.next();
        if (theForm.equals(form)) {
            /* Jump back: */
            formIterator.previous();//  w  w  w .j  av  a 2s .c o m
            if (formIterator.hasPrevious()) {
                model.addAttribute("previous",
                        Integer.valueOf(formSubset.get(formIterator.previousIndex()).getFormID().intValue()));
            }
            /* Jump forward: */
            formIterator.next();
            if (formIterator.hasNext()) {
                model.addAttribute("next",
                        Integer.valueOf(formSubset.get(formIterator.nextIndex()).getFormID().intValue()));
            }
        }
    }
    model.addAttribute("saveAction", EDIT);

    final CurationPersistentIdentifier manifestCPID = form.getManifestCPID();
    final Map<DatasetRIL, Set<CoreRIType>> rilMembership = new HashMap<>();

    /* Fetch the current RIL membership for this form instance: */
    for (final DatasetRIL dsRIL : form.getParentBundle().getRils()) {

        final RepresentationInformation[] repInfo = dsRIL.getRil().getRepresentationInformationChildren();

        for (final RepresentationInformation coreRI : repInfo) {

            if (coreRI.getRepresentationInformation() instanceof RepInfoGroup) {
                final RepInfoGroup repInfoGroup = (RepInfoGroup) coreRI.getRepresentationInformation();

                for (final RepresentationInformation ri : repInfoGroup.getRepresentationInformationChildren()) {

                    if (ri.getCpid().equals(manifestCPID)) {

                        if (!rilMembership.containsKey(dsRIL)) {
                            rilMembership.put(dsRIL, new HashSet<CoreRIType>());
                        }
                        rilMembership.get(dsRIL).add(CoreRIType.fromClass(coreRI.getClass()));
                    }

                }

            }
        }
    }
    model.addAttribute("rilMembership", rilMembership);

    model.addAttribute("form", form);
    return "datasets/items/edit";
}

From source file:mediathek.controller.IoXmlSchreiben.java

private void xmlSchreibenAbo() {
    ListIterator<DatenAbo> iterator;
    //Abo schreibem
    DatenAbo datenAbo;/*  www.j  av a2  s . com*/
    iterator = Daten.listeAbo.listIterator();
    while (iterator.hasNext()) {
        datenAbo = iterator.next();
        xmlSchreibenDaten(DatenAbo.ABO, DatenAbo.COLUMN_NAMES, datenAbo.arr, false);
    }
}