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:oct.util.Util.java

public static double[][] getXYArraysFromPoints(List<Point> points) {
    double[] x = new double[points.size()];
    double[] y = new double[points.size()];
    ListIterator<Point> pi = points.listIterator();
    for (int i = 0; pi.hasNext(); i++) {
        Point p = pi.next();
        x[i] = p.getX();// ww w. j av  a  2s  .  c om
        y[i] = p.getY();
    }
    return new double[][] { x, y };
}

From source file:oct.util.Util.java

/**
 *
 * @param points/*from  w  w  w  .j ava  2s  .com*/
 * @return
 */
public static double[][] getXYArraysFromLinePoints(List<LinePoint> points) {
    double[] x = new double[points.size()];
    double[] y = new double[points.size()];
    ListIterator<LinePoint> pi = points.listIterator();
    for (int i = 0; pi.hasNext(); i++) {
        LinePoint p = pi.next();
        x[i] = p.getX();
        y[i] = p.getY();
    }
    return new double[][] { x, y };
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator.java

private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
        List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited) {
    log.debug(/*from  w  w  w  .  j a  v a2  s .  c om*/
            "starting to check for duplicate range individuals in SelectListGenerator.removeIndividualsAlreadyInRange() ...");
    HashSet<String> range = new HashSet<String>();

    for (ObjectPropertyStatement ops : stmts) {
        if (ops.getPropertyURI().equals(predicateUri))
            range.add(ops.getObjectURI());
    }

    int removeCount = 0;
    ListIterator<Individual> it = individuals.listIterator();
    while (it.hasNext()) {
        Individual ind = it.next();
        if (range.contains(ind.getURI()) && !(ind.getURI().equals(objectUriBeingEdited))) {
            it.remove();
            ++removeCount;
        }
    }
    log.debug("removed " + removeCount + " duplicate range individuals");
    return individuals;
}

From source file:annis.visualizers.component.grid.EventExtractor.java

/**
* Returns the annotations to display according to the mappings configuration.
*
* This will check the "annos" and "annos_regex" paramters for determining.
* the annotations to display. It also iterates over all nodes of the graph
* matching the type./*www  .  java  2 s.  c  om*/
*
* @param input The input for the visualizer.
* @param type Which type of nodes to include
* @return
*/
public static List<String> computeDisplayAnnotations(VisualizerInput input, Class<? extends SNode> type) {
    if (input == null) {
        return new LinkedList<String>();
    }

    SDocumentGraph graph = input.getDocument().getSDocumentGraph();

    Set<String> annoPool = getAnnotationLevelSet(graph, input.getNamespace(), type);
    List<String> annos = new LinkedList<String>(annoPool);

    String annosConfiguration = input.getMappings().getProperty(MAPPING_ANNOS_KEY);
    if (annosConfiguration != null && annosConfiguration.trim().length() > 0) {
        String[] split = annosConfiguration.split(",");
        annos.clear();
        for (String s : split) {
            s = s.trim();
            // is regular expression?
            if (s.startsWith("/") && s.endsWith("/")) {
                // go over all remaining items in our pool of all annotations and
                // check if they match
                Pattern regex = Pattern.compile(StringUtils.strip(s, "/"));

                LinkedList<String> matchingAnnos = new LinkedList<String>();
                for (String a : annoPool) {
                    if (regex.matcher(a).matches()) {
                        matchingAnnos.add(a);
                    }
                }

                annos.addAll(matchingAnnos);
                annoPool.removeAll(matchingAnnos);

            } else {
                annos.add(s);
                annoPool.remove(s);
            }
        }
    }

    // filter already found annotation names by regular expression
    // if this was given as mapping
    String regexFilterRaw = input.getMappings().getProperty(MAPPING_ANNO_REGEX_KEY);
    if (regexFilterRaw != null) {
        try {
            Pattern regexFilter = Pattern.compile(regexFilterRaw);
            ListIterator<String> itAnnos = annos.listIterator();
            while (itAnnos.hasNext()) {
                String a = itAnnos.next();
                // remove entry if not matching
                if (!regexFilter.matcher(a).matches()) {
                    itAnnos.remove();
                }
            }
        } catch (PatternSyntaxException ex) {
            log.warn("invalid regular expression in mapping for grid visualizer", ex);
        }
    }
    return annos;
}

From source file:com.qualogy.qafe.core.errorhandling.ErrorProcessor.java

private static List<ErrorHandler> getErrorHandlers(ListIterator<? extends Item> itrItem,
        ApplicationContext context, Window window) {
    List<ErrorHandler> errorHandlerList = new ArrayList<ErrorHandler>();
    if (itrItem != null) {
        while (itrItem.hasNext()) {
            Item item = itrItem.next();
            if (item instanceof ErrorHandler) {
                errorHandlerList.add((ErrorHandler) item);
            } else if (item instanceof EventRef) {
                EventRef eventRef = (EventRef) item;
                String eventId = eventRef.getEvent();
                Event event = getEvent(eventId, context, window);
                if (event != null) {
                    List<ErrorHandler> errorHandlers = getErrorHandlers(event.getEventItems().listIterator(),
                            context, window);
                    if (errorHandlers != null) {
                        errorHandlerList.addAll(errorHandlers);
                    }//from  ww  w  .j  a va 2  s .  c  om
                }
            }
        }
    }
    return errorHandlerList;
}

From source file:annis.visualizers.component.grid.EventExtractor.java

/**
* Splits events of a row if they contain a gap. Gaps are found using the
* token index (provided as ANNIS specific {@link SFeature}. Inserted events
* have a special style to mark them as gaps.
*
* @param row//from ww  w.  j av  a  2  s  .c  o  m
* @param graph
* @param startTokenIndex token index of the first token in the match
* @param endTokenIndex token index of the last token in the match
*/
private static void splitRowsOnGaps(Row row, final SDocumentGraph graph, long startTokenIndex,
        long endTokenIndex) {
    ListIterator<GridEvent> itEvents = row.getEvents().listIterator();
    while (itEvents.hasNext()) {
        GridEvent event = itEvents.next();

        int lastTokenIndex = Integer.MIN_VALUE;

        // sort the coveredIDs
        LinkedList<String> sortedCoveredToken = new LinkedList<String>(event.getCoveredIDs());
        Collections.sort(sortedCoveredToken, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                SNode node1 = graph.getSNode(o1);
                SNode node2 = graph.getSNode(o2);

                if (node1 == node2) {
                    return 0;
                }
                if (node1 == null) {
                    return -1;
                }
                if (node2 == null) {
                    return +1;
                }

                long tokenIndex1 = node1.getSFeature(ANNIS_NS, FEAT_TOKENINDEX).getSValueSNUMERIC();
                long tokenIndex2 = node2.getSFeature(ANNIS_NS, FEAT_TOKENINDEX).getSValueSNUMERIC();

                return ((Long) (tokenIndex1)).compareTo(tokenIndex2);
            }
        });

        // first calculate all gaps
        List<GridEvent> gaps = new LinkedList<GridEvent>();
        for (String id : sortedCoveredToken) {

            SNode node = graph.getSNode(id);
            long tokenIndexRaw = node.getSFeature(ANNIS_NS, FEAT_TOKENINDEX).getSValueSNUMERIC();

            tokenIndexRaw = clip(tokenIndexRaw, startTokenIndex, endTokenIndex);

            int tokenIndex = (int) (tokenIndexRaw - startTokenIndex);
            int diff = tokenIndex - lastTokenIndex;

            if (lastTokenIndex >= 0 && diff > 1) {
                // we detected a gap
                GridEvent gap = new GridEvent(event.getId() + "_gap", lastTokenIndex + 1, tokenIndex - 1, "");
                gap.setGap(true);
                gaps.add(gap);
            }

            lastTokenIndex = tokenIndex;
        } // end for each covered token id

        for (GridEvent gap : gaps) {
            // remember the old right value
            int oldRight = event.getRight();

            // shorten last event
            event.setRight(gap.getLeft() - 1);

            // insert the real gap
            itEvents.add(gap);

            // insert a new event node that covers the rest of the event
            GridEvent after = new GridEvent(event.getId() + "_after", gap.getRight() + 1, oldRight,
                    event.getValue());
            after.getCoveredIDs().addAll(event.getCoveredIDs());
            itEvents.add(after);
        }

    }
}

From source file:LNISmokeTest.java

/**
 * Do propfind./*from www  . jav  a  2 s  . c o  m*/
 * 
 * @param lni the lni
 * @param handle the handle
 * @param pf the pf
 * @param depth the depth
 * @param types the types
 * 
 * @throws RemoteException the remote exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private static void doPropfind(LNISoapServlet lni, String handle, String pf, int depth, String types)
        throws java.rmi.RemoteException, java.io.IOException {
    String uri = doLookup(lni, handle, null);
    String result = lni.propfind(uri, pf, depth, types);
    try {
        SAXBuilder builder = new SAXBuilder();
        Document msDoc = builder.build(new java.io.StringReader(result));
        Element ms = msDoc.getRootElement();
        ListIterator ri = ms.getChildren("response", NS_DAV).listIterator();
        while (ri.hasNext()) {
            Element resp = (Element) ri.next();
            String href = resp.getChildText("href", NS_DAV);
            System.out.println("Resource = " + href);
            ListIterator pi = resp.getChildren("propstat", NS_DAV).listIterator();
            while (pi.hasNext()) {
                Element ps = (Element) pi.next();
                String status = ps.getChildText("status", NS_DAV);
                if (status.indexOf("200") >= 0) {
                    System.out.println("  === PROPERTIES Successfully returned:");
                } else {
                    System.out.println("  === PROPERTIES with Status=" + status);
                }
                // print properties and values
                Element prop = ps.getChild("prop", NS_DAV);
                ListIterator ppi = prop.getChildren().listIterator();
                while (ppi.hasNext()) {
                    Element e = (Element) ppi.next();
                    String value = e.getTextTrim();
                    if (value.equals("")) {
                        List kids = e.getChildren();
                        if (kids.size() > 0) {
                            value = outputPretty.outputString(kids);
                        }
                        if (value.indexOf('\n') >= 0) {
                            value = "\n" + value;
                        }
                    } else {
                        value = "\"" + value + "\"";
                    }
                    String equals = value.equals("") ? "" : " = ";
                    System.out.println("    " + e.getQualifiedName() + equals + value);
                }
            }
        }

    } catch (JDOMParseException je) {
        je.printStackTrace();

        die(3, "ERROR: " + je.toString());
    } catch (JDOMException je) {
        je.printStackTrace();

        die(4, "ERROR: " + je.toString());
    }

}

From source file:com.ofalvai.bpinfo.api.bkkinfo.BkkInfoClient.java

/**
 * Alerts scheduled for the current day (and not yet started) appear in the current alerts list.
 * We need to find them and move to the future alerts list
 *///ww w  .jav  a 2 s  . c  o m
private static void fixFutureAlertsInTodayList(List<Alert> alertsToday, List<Alert> alertsFuture) {
    // Avoiding ConcurrentModificationException when removing from alertsToday
    ListIterator<Alert> todayIterator = alertsToday.listIterator();
    while (todayIterator.hasNext()) {
        Alert alert = todayIterator.next();
        DateTime startTime = new DateTime(alert.getStart() * 1000L);
        if (startTime.isAfterNow()) {
            alertsFuture.add(alert);
            todayIterator.remove();
        }
    }
}

From source file:net.firstpartners.nounit.utility.XmlUtil.java

/**
 * indexes the nodes in the document that is passed in , via a HashMap mapping
 * mapping is in the format <index> as String , handle to <element> of node<BR>
 * Strings are used as they are better lookup in the hashmap.
 * @param inXmlDocument to generated the hashmap from
 * @param uniqueAttribute to do the index on (i.e. key in HashMap). Examples
 *        of uniqueAttributes are id's or names.
 * @return HashMap containing mappings// w w  w  . j  av  a 2 s . c  om
 */
public static HashMap getNodeIndex(Document inXmlDocument, String uniqueAttribute) {

    //Internal Variables
    int stackPointer = 0;
    String locationId = null;
    Attribute tmpAttribute = null;
    Element thisElement = null;
    ListIterator deepestList = null;

    HashMap mappings = new HashMap();
    List stack = new Vector();

    //Get the list information for the entire document
    stack.add(inXmlDocument.getContent().listIterator());

    //Loop though the elements on list
    while (!stack.isEmpty()) {

        //Get the last list on the stack
        deepestList = (ListIterator) stack.get(stack.size() - 1);

        //Does this list have more elements?
        if (deepestList.hasNext()) {

            //if so Get Next element from this list
            thisElement = (Element) deepestList.next();

            //Add Mapping for this element to hashtable
            tmpAttribute = thisElement.getAttribute(uniqueAttribute);

            //Attibute can be null for non folder elements (e.g. root element) - if so ignore
            if (tmpAttribute != null) {
                locationId = tmpAttribute.getValue();
                if ((locationId != null) && (locationId != "")) {
                    mappings.put(locationId.toString(), thisElement);

                }
            } //end add mapping

            //does this list have children ?
            if (thisElement.hasChildren()) {

                //if so add to the stack
                stackPointer++;
                stack.add(thisElement.getChildren().listIterator());
            }
        } else {
            //if not , remove this list from the stack
            stack.remove(stackPointer);
            stackPointer--;

        } // end if stack has more elements

    }

    return mappings;
}

From source file:edu.harvard.mcz.imagecapture.PositionTemplate.java

/** Fetch the list of valid template names (including the no component parts template).  
 * Use these names in the constructor PositionTemplate(String templateToUse);   
 * /*from w w w .j ava 2s .  c o  m*/
 * @return a list of the identifiers of the currently available templates.
 */
public static List<String> getTemplateIds() {
    String[] templates = { TEMPLATE_TEST_1, TEMPLATE_DEFAULT, TEMPLATE_NO_COMPONENT_PARTS };

    List<String> temp = Arrays.asList(templates);
    ArrayList<String> templateIdList = new ArrayList<String>();
    for (int i = 0; i < temp.size(); i++) {
        templateIdList.add(temp.get(i));
    }
    TemplateLifeCycle tls = new TemplateLifeCycle();
    List<Template> persistentTemplates = tls.findAll();
    if (persistentTemplates == null) {
        tls.cleanUpReferenceImage();
        persistentTemplates = tls.findAll();
    }
    ListIterator<Template> iter = persistentTemplates.listIterator();
    while (iter.hasNext()) {
        templateIdList.add(iter.next().getTemplateId());
    }
    return templateIdList;
}