Example usage for java.util List listIterator

List of usage examples for java.util List listIterator

Introduction

In this page you can find the example usage for java.util List listIterator.

Prototype

ListIterator<E> listIterator();

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

From source file:com.tacitknowledge.util.migration.MigrationProcess.java

/**
 * Returns the patch level which is previous to the current level
 *
 * @param currentLevel the current patch level
 * @return the level of the patch that was applied previous to the current patch l
 * @throws MigrationException if there is an error retrieving the previous patch level
 */// ww  w  .j a v  a2s  . c o m
public int getPreviousPatchLevel(int currentLevel) throws MigrationException {
    boolean isCurrentPatchFound = false;
    List tasks = getMigrationTasks();
    int previousTaskLevel = 0;

    Collections.sort(tasks);

    for (ListIterator patchIterator = tasks.listIterator(); patchIterator.hasNext() && !isCurrentPatchFound;) {
        int previousIndex = patchIterator.previousIndex();

        //get the current patch
        MigrationTask task = (MigrationTask) patchIterator.next();

        if (currentLevel == task.getLevel().intValue()) {
            //the current patch level is found
            isCurrentPatchFound = true;

            if (previousIndex != -1) {
                MigrationTask previousTask = (MigrationTask) tasks.get(previousIndex);
                previousTaskLevel = previousTask.getLevel().intValue();
            }
        }
    }
    return previousTaskLevel;
}

From source file:com.beem.project.beem.ui.ContactList.java

/**
 * Get a {@link ContactListAdapter} for a group.
 * The {@link ContactListAdapter} will be created if it is not exist.
 * @param group the group/*from www . jav a 2 s  .c  om*/
 * @return the adapter
 */
ContactListAdapter getContactListAdapter(String group) {
    synchronized (contactListAdapters) {
        ContactListAdapter contactListAdapter = contactListAdapters.get(group);
        if (contactListAdapter == null) {
            contactListAdapter = new ContactListAdapter(ContactList.this);
            contactListAdapters.put(group, contactListAdapter);
            List<String> realGroups = mListGroup.subList(1, mListGroup.size() - 1);
            if (!mListGroup.contains(group)) {
                boolean added = false;
                // insert group in sorted list
                for (ListIterator<String> iterator = realGroups.listIterator(); iterator.hasNext();) {
                    String currentGroup = (String) iterator.next();
                    if (currentGroup.compareTo(group) > 0) {
                        iterator.previous();
                        iterator.add(group);
                        added = true;
                        break;
                    }
                }
                if (!added)
                    realGroups.add(group);
                groupsPagesAdapter.notifyDataSetChanged();
            }
        }
        boolean hideDisconnected = mSettings.getBoolean(BeemApplication.SHOW_OFFLINE_CONTACTS_KEY, false);
        contactListAdapter.setOnlineOnly(hideDisconnected);
        return contactListAdapter;
    }
}

From source file:com.projity.pm.graphic.model.transform.NodeCacheTransformer.java

public void transfrom(List list) {
    model.clear();/* www .  j  a v  a 2 s  .  c  o  m*/

    if (list == null)
        return;

    boolean preserveHierarchy = transformer.isPreserveHierarchy();

    if (!transformer.isShowSummary()) {
        preserveHierarchy = false;
        removeSummaries(list);
    }
    Map<GraphicNode, List<GraphicNode>> assignmentsMap = null;
    if (!transformer.isShowAssignments())
        removeAssignments(list);
    if (!transformer.isShowEmptyLines())
        removeVoids(list);
    if (transformer.isShowEmptyLines() && !transformer.isShowEndEmptyLines())
        removeEndVoids(list);

    NodeTransformer composition = transformer.getTransformer();

    NodeFilter hiddenFilter = transformer.getHiddenFilter();
    if (hiddenFilter instanceof BaseFilter && !((BaseFilter) hiddenFilter).isActive())
        hiddenFilter = null; //to avoid useless filtering in case of BaseFilter
    NodeFilter userFilter = (transformer.isNoneFilter()) ? null : transformer.getUserFilter();
    boolean filtering = hiddenFilter != null || userFilter != null;

    NodeSorter sorter1 = transformer.getHiddenSorter();
    NodeSorter sorter2 = transformer.getUserSorter();
    boolean sorting = !(sorter1 == null && transformer.isNoneSorter());

    NodeGrouper grouper = transformer.getUserGrouper();
    boolean grouping = !transformer.isNoneGrouper();

    if (!filtering && !sorting && !grouping)
        return;

    if (transformer.isShowAssignments() && preserveHierarchy && !transformer.isTreatAssignmentsAsTasks())
        assignmentsMap = extractAssignments(list);

    List localList = null;
    Stack parents = null;
    boolean alreadyExcluded;
    if (preserveHierarchy) {
        localList = new ArrayList();
        parents = new Stack();
    } else
        localList = list;

    GraphicNode gnode, previous = null;
    Object current;
    for (Iterator i = list.iterator(); i.hasNext();) {
        gnode = (GraphicNode) i.next();
        gnode.setFiltered(false);
        if (!gnode.isVoid()) {
            current = (composition == null) ? gnode.getNode() : composition.evaluate(gnode.getNode());
            alreadyExcluded = false;
            if (hiddenFilter != null) {
                if (!hiddenFilter.evaluate(current)) {
                    if (!gnode.isSummary() || !preserveHierarchy) {
                        i.remove();
                        continue;
                    }
                    if (gnode.isSummary() && preserveHierarchy)
                        gnode.setFiltered(true);
                    alreadyExcluded = true;
                }
            }
            if (userFilter != null && !alreadyExcluded) {
                if (!userFilter.evaluate(current)) {
                    if (!gnode.isSummary() || !preserveHierarchy) {
                        i.remove();
                        continue;
                    }
                    if (gnode.isSummary() && preserveHierarchy)
                        gnode.setFiltered(true);
                }
            }
        }
        if (preserveHierarchy) {
            //contruct a temporary tree for sorting and grouping
            //                if (parents==null||previous==null){
            //                   System.out.println("null");
            //                }
            if (gnode.getLevel() == 1) {
                localList.add(gnode);
                parents.clear();
            } else {
                if (previous.getLevel() < gnode.getLevel()) {
                    parents.push(previous);
                } else if (previous.getLevel() >= gnode.getLevel()) {
                    while (parents.size() >= gnode.getLevel())
                        parents.pop();
                }
                ((GraphicNode) parents.peek()).getChildren().add(gnode);
            }
            previous = gnode;
        }
    }

    //remove parents without children
    if (preserveHierarchy) {
        list.clear();
        if (transformer.isShowEmptySummaries()) {
            if ("TaskUsage".equals(viewName))
                filterBadBranches(localList);
        } else
            filterEmptySummaries(localList, false);
    }

    if (sorting) {
        if (sorter1 != null)
            sorter1.sortList(localList, new GraphicNodeComparator(sorter1, composition), preserveHierarchy);
        if (!transformer.isNoneSorter())
            sorter2.sortList(localList, new GraphicNodeComparator(sorter2, composition), preserveHierarchy);
    }

    if (grouping) {
        List groups = grouper.getGroups();
        levelOffset = groups.size();
        List groupedList = new LinkedList();
        groupList(localList, groupedList, groups.listIterator(), null, composition, preserveHierarchy);
        localList.clear();
        localList.addAll(groupedList);
    }

    if (preserveHierarchy) { //converts tmp tree to list
        treeToList(localList, list);
    }

    if (assignmentsMap != null)
        recoverAssignments(list, assignmentsMap);

    //        if (transformer.isShowEmptyLines())
    //           placeVoidNodes(list);

}

From source file:org.apache.fop.layoutmgr.list.ListItemLayoutManager.java

/** {@inheritDoc} */
@Override//from w  ww . j av a2 s  .c o m
public List getChangedKnuthElements(List oldList, int alignment) {
    // label
    labelList = label.getChangedKnuthElements(labelList, alignment);

    // body
    // "unwrap" the Positions stored in the elements
    ListIterator oldListIterator = oldList.listIterator();
    KnuthElement oldElement;
    while (oldListIterator.hasNext()) {
        oldElement = (KnuthElement) oldListIterator.next();
        Position innerPosition = oldElement.getPosition().getPosition();
        if (innerPosition != null) {
            // oldElement was created by a descendant of this BlockLM
            oldElement.setPosition(innerPosition);
        } else {
            // thisElement was created by this BlockLM
            // modify its position in order to recognize it was not created
            // by a child
            oldElement.setPosition(new Position(this));
        }
    }

    List returnedList = body.getChangedKnuthElements(oldList, alignment);
    // "wrap" the Position inside each element
    List tempList = returnedList;
    KnuthElement tempElement;
    returnedList = new LinkedList();
    ListIterator listIter = tempList.listIterator();
    while (listIter.hasNext()) {
        tempElement = (KnuthElement) listIter.next();
        tempElement.setPosition(new NonLeafPosition(this, tempElement.getPosition()));
        returnedList.add(tempElement);
    }

    return returnedList;
}

From source file:org.apache.tika.parser.pdf18.PDF2XHTML.java

private void extractAcroForm(PDDocument pdf, XHTMLContentHandler handler) throws IOException, SAXException {
    //Thank you, Ben Litchfield, for org.apache.pdfbox.examples.fdf.PrintFields
    //this code derives from Ben's code
    PDDocumentCatalog catalog = pdf.getDocumentCatalog();

    if (catalog == null)
        return;/*from w ww . j  av a  2  s .  co  m*/

    PDAcroForm form = catalog.getAcroForm();
    if (form == null)
        return;

    //if it has xfa, try that.
    //if it doesn't exist or there's an exception,
    //go with traditional AcroForm
    PDXFA pdxfa = form.getXFA();
    if (pdxfa != null) {
        XFAExtractor xfaExtractor = new XFAExtractor();
        try {
            xfaExtractor.extract(new BufferedInputStream(new ByteArrayInputStream(pdxfa.getBytes())), handler,
                    metadata);
            return;
        } catch (XMLStreamException | IOException e) {
            //if there was an xml parse exception in xfa, try the AcroForm
        }
    }

    @SuppressWarnings("rawtypes")
    List fields = form.getFields();

    if (fields == null)
        return;

    @SuppressWarnings("rawtypes")
    ListIterator itr = fields.listIterator();

    if (itr == null)
        return;

    handler.startElement("div", "class", "acroform");
    handler.startElement("ol");

    while (itr.hasNext()) {
        Object obj = itr.next();
        if (obj != null && obj instanceof PDField) {
            processAcroField((PDField) obj, handler, 0);
        }
    }
    handler.endElement("ol");
    handler.endElement("div");
}

From source file:org.apache.tika.parser.pdf.PDF2XHTML.java

private void extractAcroForm(PDDocument pdf, XHTMLContentHandler handler) throws IOException, SAXException {
    //Thank you, Ben Litchfield, for org.apache.pdfbox.examples.fdf.PrintFields
    //this code derives from Ben's code
    PDDocumentCatalog catalog = pdf.getDocumentCatalog();

    if (catalog == null)
        return;//w  ww. ja v a  2s  . c o m

    PDAcroForm form = catalog.getAcroForm();
    if (form == null)
        return;

    //if it has xfa, try that.
    //if it doesn't exist or there's an exception,
    //go with traditional AcroForm
    PDXFAResource pdxfa = form.getXFA();

    if (pdxfa != null) {
        XFAExtractor xfaExtractor = new XFAExtractor();
        try {
            xfaExtractor.extract(new BufferedInputStream(new ByteArrayInputStream(pdxfa.getBytes())), handler,
                    metadata);
            return;
        } catch (XMLStreamException | IOException e) {
            //if there was an xml parse exception in xfa, try the AcroForm
        }
    }

    @SuppressWarnings("rawtypes")
    List fields = form.getFields();

    if (fields == null)
        return;

    @SuppressWarnings("rawtypes")
    ListIterator itr = fields.listIterator();

    if (itr == null)
        return;

    handler.startElement("div", "class", "acroform");
    handler.startElement("ol");

    while (itr.hasNext()) {
        Object obj = itr.next();
        if (obj != null && obj instanceof PDField) {
            processAcroField((PDField) obj, handler, 0);
        }
    }
    handler.endElement("ol");
    handler.endElement("div");
}

From source file:marytts.modules.phonemiser.AllophoneSet.java

/**
 * Syllabify a string of allophones. If stress markers are provided, they are preserved; otherwise, primary stress will be
 * assigned to the initial syllable.// w w w  . ja  va  2  s . c o m
 * <p>
 * The syllabification algorithm itself follows the <i>Core Syllabification Principle (CSP)</i> from <blockquote>G.N. Clements
 * (1990) "The role of the sonority cycle in core syllabification." In: J. Kingston &amp; M.E. Beckman (Eds.),
 * <em>Papers in Laboratory Phonology I: Between the Grammar and Physics of Speech</em>, Ch. 17, pp. 283-333, Cambridge
 * University Press.</blockquote>
 *
 * @param phoneString
 *            phoneString
 * @return a syllabified string; individual allophones are separated by spaces, and syllables, by dashes.
 * @throws IllegalArgumentException
 *             if the <b>phoneString</b> is empty or contains a symbol that satisfies none of the following conditions:
 *             <ol>
 *             <li>the symbol corresponds to an Allophone, or</li> <li>the symbol is a stress symbol (cf. {@link Stress}), or
 *             </li> <li>the symbol is a syllable boundary (<code>-</code>)</li>
 *             </ol>
 * 
 */
public String syllabify(String phoneString) throws IllegalArgumentException {
    // Before we process, a sanity check:
    if (phoneString.trim().isEmpty()) {
        throw new IllegalArgumentException("Cannot syllabify empty phone string");
    }

    // First, split phoneString into a List of allophone Strings...
    List<String> allophoneStrings = splitIntoAllophoneList(phoneString, true);
    // ...and create from it a List of generic Objects
    List<Object> phonesAndSyllables = new ArrayList<Object>(allophoneStrings);

    // Create an iterator
    ListIterator<Object> iterator = phonesAndSyllables.listIterator();

    // First iteration (left-to-right):
    // CSP (a): Associate each [+syllabic] segment to a syllable node.
    Syllable currentSyllable = null;
    while (iterator.hasNext()) {
        String phone = (String) iterator.next();
        try {
            // either it's an Allophone
            Allophone allophone = getAllophone(phone);
            if (allophone.isSyllabic()) {
                // if /6/ immediately follows a non-diphthong vowel, it should be appended instead of forming its own syllable
                boolean appendR = false;
                if (allophone.getFeature("ctype").equals("r")) {
                    // it's an /6/
                    if (iterator.previousIndex() > 1) {
                        Object previousPhoneOrSyllable = phonesAndSyllables.get(iterator.previousIndex() - 1);
                        if (previousPhoneOrSyllable == currentSyllable) {
                            // the /6/ immediately follows the current syllable
                            if (!currentSyllable.getLastAllophone().isDiphthong()) {
                                // the vowel immediately preceding the /6/ is not a diphthong
                                appendR = true;
                            }
                        }
                    }
                }
                if (appendR) {
                    iterator.remove();
                    currentSyllable.appendAllophone(allophone);
                } else {
                    currentSyllable = new Syllable(allophone);
                    iterator.set(currentSyllable);
                }
            }
        } catch (IllegalArgumentException e) {
            // or a stress or boundary marker
            if (!getIgnoreChars().contains(phone)) {
                throw e;
            }
        }
    }

    // Second iteration (right-to-left):
    // CSP (b): Given P (an unsyllabified segment) preceding Q (a syllabified segment), adjoin P to the syllable containing Q
    // iff P has lower sonority rank than Q (iterative).
    currentSyllable = null;
    boolean foundPrimaryStress = false;
    iterator = phonesAndSyllables.listIterator(phonesAndSyllables.size());
    while (iterator.hasPrevious()) {
        Object phoneOrSyllable = iterator.previous();
        if (phoneOrSyllable instanceof Syllable) {
            currentSyllable = (Syllable) phoneOrSyllable;
        } else if (currentSyllable == null) {
            // haven't seen a Syllable yet in this iteration
            continue;
        } else {
            String phone = (String) phoneOrSyllable;
            try {
                // it's an Allophone -- prepend to the Syllable
                Allophone allophone = getAllophone(phone);
                if (allophone.sonority() < currentSyllable.getFirstAllophone().sonority()) {
                    iterator.remove();
                    currentSyllable.prependAllophone(allophone);
                }
            } catch (IllegalArgumentException e) {
                // it's a provided stress marker -- assign it to the Syllable
                switch (phone) {
                case Stress.PRIMARY:
                    iterator.remove();
                    currentSyllable.setStress(Stress.PRIMARY);
                    foundPrimaryStress = true;
                    break;
                case Stress.SECONDARY:
                    iterator.remove();
                    currentSyllable.setStress(Stress.SECONDARY);
                    break;
                case "-":
                    iterator.remove();
                    // TODO handle syllable boundaries
                    break;
                default:
                    throw e;
                }
            }
        }
    }

    // Third iteration (left-to-right):
    // CSP (c): Given Q (a syllabified segment) followed by R (an unsyllabified segment), adjoin R to the syllable containing
    // Q iff has a lower sonority rank than Q (iterative).
    Syllable initialSyllable = currentSyllable;
    currentSyllable = null;
    iterator = phonesAndSyllables.listIterator();
    while (iterator.hasNext()) {
        Object phoneOrSyllable = iterator.next();
        if (phoneOrSyllable instanceof Syllable) {
            currentSyllable = (Syllable) phoneOrSyllable;
        } else {
            String phone = (String) phoneOrSyllable;
            try {
                // it's an Allophone -- append to the Syllable
                Allophone allophone;
                try {
                    allophone = getAllophone(phone);
                } catch (IllegalArgumentException e) {
                    // or a stress or boundary marker -- remove
                    if (getIgnoreChars().contains(phone)) {
                        iterator.remove();
                        continue;
                    } else {
                        throw e;
                    }
                }
                if (currentSyllable == null) {
                    // haven't seen a Syllable yet in this iteration
                    iterator.remove();
                    if (initialSyllable == null) {
                        // haven't seen any syllable at all
                        initialSyllable = new Syllable(allophone);
                        iterator.add(initialSyllable);
                    } else {
                        initialSyllable.prependAllophone(allophone);
                    }
                } else {
                    // append it to the last seen Syllable
                    iterator.remove();
                    currentSyllable.appendAllophone(allophone);
                }
            } catch (IllegalArgumentException e) {
                throw e;
            }
        }
    }

    // if primary stress was not provided, assign it to initial syllable
    if (!foundPrimaryStress) {
        initialSyllable.setStress(Stress.PRIMARY);
    }

    // join Syllables with dashes and return the String
    return StringUtils.join(phonesAndSyllables, " - ");
}

From source file:org.apache.tika.parser.pdf.AbstractPDF2XHTML.java

void extractAcroForm(PDDocument pdf) throws IOException, SAXException, TikaException {
    //Thank you, Ben Litchfield, for org.apache.pdfbox.examples.fdf.PrintFields
    //this code derives from Ben's code
    PDDocumentCatalog catalog = pdf.getDocumentCatalog();

    if (catalog == null)
        return;//ww w .ja v a2  s. c  o m

    PDAcroForm form = catalog.getAcroForm();
    if (form == null)
        return;

    //if it has xfa, try that.
    //if it doesn't exist or there's an exception,
    //go with traditional AcroForm
    PDXFAResource pdxfa = form.getXFA();

    if (pdxfa != null) {
        //if successful, return
        XFAExtractor xfaExtractor = new XFAExtractor();
        InputStream is = null;
        try {
            is = new BufferedInputStream(new ByteArrayInputStream(pdxfa.getBytes()));
        } catch (IOException e) {
            EmbeddedDocumentUtil.recordEmbeddedStreamException(e, metadata);
        }
        if (is != null) {
            try {
                xfaExtractor.extract(is, xhtml, metadata, context);
                return;
            } catch (XMLStreamException e) {
                //if there was an xml parse exception in xfa, try the AcroForm
                EmbeddedDocumentUtil.recordException(e, metadata);
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }

    @SuppressWarnings("rawtypes")
    List fields = form.getFields();

    if (fields == null)
        return;

    @SuppressWarnings("rawtypes")
    ListIterator itr = fields.listIterator();

    if (itr == null)
        return;

    xhtml.startElement("div", "class", "acroform");
    xhtml.startElement("ol");

    while (itr.hasNext()) {
        Object obj = itr.next();
        if (obj != null && obj instanceof PDField) {
            processAcroField((PDField) obj, 0);
        }
    }
    xhtml.endElement("ol");
    xhtml.endElement("div");
}

From source file:org.archive.crawler.restlet.EnhDirectoryResource.java

/** 
 * Add EditRepresentation as a variant when appropriate. 
 * /*from w w w. j  a  va 2  s  . co m*/
 * @see com.noelios.restlet.local.DirectoryResource#getVariants()
 */
@Override
public List<Variant> getVariants() {
    List<Variant> variants = super.getVariants();
    Form f = getRequest().getResourceRef().getQueryAsForm();
    String format = f.getFirstValue("format");
    if ("textedit".equals(format)) {
        if (variants.isEmpty()) {
            // create empty placeholder file if appropriate
            try {
                File file = new File(new URI(getTargetUri()));
                if (getEnhDirectory().allowsEdit(file)) {
                    file.createNewFile();
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            variants = super.getVariants();
        }
        // wrap FileRepresentations in EditRepresentations
        ListIterator<Variant> iter = variants.listIterator();
        while (iter.hasNext()) {
            Variant v = iter.next();
            if (v instanceof FileRepresentation) {
                File file = ((FileRepresentation) v).getFile();
                if (getEnhDirectory().allowsEdit(file)) {
                    iter.remove();
                    // any editable file for our purposes should 
                    // be XML/UTF-8
                    v.setCharacterSet(CharacterSet.UTF_8);
                    iter.add(new EditRepresentation((FileRepresentation) v, this));
                }
                ;
            }
        }
    } else if ("paged".equals(format)) {
        ListIterator<Variant> iter = variants.listIterator();
        while (iter.hasNext()) {
            Variant v = iter.next();
            if (v instanceof FileRepresentation) {
                File file = ((FileRepresentation) v).getFile();
                if (getEnhDirectory().allowsPaging(file)) {
                    iter.remove();
                    iter.add(new PagedRepresentation((FileRepresentation) v, this, f.getFirstValue("pos"),
                            f.getFirstValue("lines"), f.getFirstValue("reverse")));
                }
                ;
            }
        }
    } else {
        ListIterator<Variant> iter = variants.listIterator();
        while (iter.hasNext()) {
            Variant v = iter.next();
            v.setCharacterSet(CharacterSet.UTF_8);
        }
    }

    return variants;
}

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 ww .  jav a2 s . c om

        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;
}