Example usage for java.util LinkedList listIterator

List of usage examples for java.util LinkedList listIterator

Introduction

In this page you can find the example usage for java.util LinkedList 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:edu.cornell.mannlib.vitro.webapp.dao.filtering.IndividualFiltering.java

@Override
public List<DataProperty> getDataPropertyList() {
    List<DataProperty> dprops = _innerIndividual.getDataPropertyList();
    LinkedList<DataProperty> outdProps = new LinkedList<DataProperty>();
    if (dprops == null)
        return outdProps;
    Filter.filter(dprops, _filters.getDataPropertyFilter(), outdProps);

    ListIterator<DataProperty> it = outdProps.listIterator();
    while (it.hasNext()) {
        DataProperty dp = it.next();/*from  w ww  .  j  a v  a 2s  .com*/
        List<DataPropertyStatement> filteredStmts = new LinkedList<DataPropertyStatement>();
        Filter.filter(dp.getDataPropertyStatements(), _filters.getDataPropertyStatementFilter(), filteredStmts);
        if (filteredStmts.size() == 0) {
            it.remove();
        } else {
            dp.setDataPropertyStatements(filteredStmts);
        }
    }
    return outdProps;
}

From source file:com.icantrap.collections.dawg.DawgBuilder.java

private void compress() {
    LinkedList<Node> stack = new LinkedList<Node>();
    int index = 0;

    stack.addLast(root);/*ww  w .  j  av a  2  s .  c  o  m*/
    while (!stack.isEmpty()) {
        Node ptr = stack.removeFirst();

        ptr.index = index++;
        if (root != ptr)
            ptr.siblings = ptr.parent.nextChildren.size() - 1 + (null == ptr.parent.child ? 0 : 1);
        nodeList.add(ptr);

        for (Node nextChild : ptr.nextChildren)
            stack.add(nextChild);
        if (null != ptr.child)
            stack.add(ptr.child);
    }

    // assign child depths to all nodes
    for (Node node : nodeList)
        if (node.terminal) {
            node.childDepth = 0;

            Node ptr = node;
            int depth = 0;
            while (root != ptr) {
                ptr = ptr.parent;
                ++depth;
                if (depth > ptr.childDepth)
                    ptr.childDepth = depth;
                else
                    break;
            }
        }

    // bin nodes by child depth
    for (Node node : nodeList) {
        LinkedList<Node> nodes = childDepths.get(node.childDepth);
        if (null == nodes) {
            nodes = new LinkedList<Node>();
            nodes.add(node);
            childDepths.put(node.childDepth, nodes);
        } else
            nodes.add(node);
    }

    int maxDepth = -1;
    for (int depth : childDepths.keySet())
        if (depth > maxDepth)
            maxDepth = depth;

    for (int depth = 0; depth <= maxDepth; ++depth) {
        LinkedList<Node> nodes = childDepths.get(depth);
        if (null == nodes)
            continue;

        for (ListIterator<Node> pickNodeIter = nodes.listIterator(); pickNodeIter.hasNext();) {
            Node pickNode = pickNodeIter.next();

            if ((null == pickNode.replaceMeWith) && pickNode.isChild && (0 == pickNode.siblings))
                for (ListIterator<Node> searchNodeIter = nodes
                        .listIterator(pickNodeIter.nextIndex()); searchNodeIter.hasNext();) {
                    Node searchNode = searchNodeIter.next();
                    if ((null == searchNode.replaceMeWith) && searchNode.isChild && (0 == searchNode.siblings)
                            && pickNode.equals(searchNode)) {
                        searchNode.parent.child = pickNode;
                        searchNode.replaceMeWith = pickNode;
                    }
                }
        }
    }
}

From source file:net.relet.freimap.NodeInfo.java

public void setLinkCountProfile(LinkedList<LinkCount> lcp) {
    if (lcp.size() == 0) {
        minLinks = 0;//  w  ww  .  ja v a 2  s .com
        maxLinks = 0;
        return;
    }

    XYSeries data = new XYSeries("links");
    XYSeries avail = new XYSeries("avail");
    XYSeriesCollection datac = new XYSeriesCollection(data);
    datac.addSeries(avail);
    linkCountChart = ChartFactory.createXYLineChart("average incoming link count\r\nincoming link availability",
            "time", "count", datac, PlotOrientation.VERTICAL, false, false, false);
    sexupLayout(linkCountChart);

    long first = lcp.getFirst().time, last = lcp.getLast().time, lastClock = first, count = 0, maxCount = 0;
    long aggregate = (last - first) / CHART_WIDTH;
    double sum = 0;

    /* ok, this ain't effective, we do it just to pre-calculate maxCount */
    ListIterator<LinkCount> li = lcp.listIterator();
    while (li.hasNext()) {
        LinkCount lc = li.next();
        count++;
        if (lc.time - lastClock > aggregate) {
            if (maxCount < count)
                maxCount = count;
            lastClock = lc.time;
            count = 0;
        }
    }

    //reset for second iteration
    count = 0;
    lastClock = first;

    //iterate again
    li = lcp.listIterator();
    while (li.hasNext()) {
        LinkCount lc = li.next();
        if (minLinks > lc.count)
            minLinks = lc.count;
        if (maxLinks < lc.count)
            maxLinks = lc.count;

        sum += lc.count;
        count++;

        if (aggregate == 0)
            aggregate = 1000;//dirty hack
        if (lc.time - lastClock > aggregate) {
            for (long i = lastClock; i < lc.time - aggregate; i += aggregate) {
                data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN);
                avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0);
            }

            count = 0;
            sum = 0;
            lastClock = lc.time;
        }
    }

    status = STATUS_AVAILABLE;
}

From source file:com.jaspersoft.studio.property.section.style.inerithance.StylesListSection.java

/**
 * Print the attributes of all the styles of the element
 * //ww w.jav  a2  s  .  c  o  m
 * @param styles List of styles
 * @param parent composite of the main widget
 */
private void printStyles(LinkedList<MStyle> styles, Composite parent) {
    ListIterator<MStyle> itr = styles.listIterator();
    boolean hasDefaultStyleInGerarchy = false;
    while (itr.hasNext()) {
        MStyle style = itr.next();
        String titleLabelText = MessageFormat.format(Messages.StylesSectionList_Inherited_From_Style,
                new Object[] { style.getPropertyValue(JRDesignStyle.PROPERTY_NAME) });
        printStyleTitle(titleLabelText, style, parent);
        printStyleAttribute(parent, style, null, AttributeParent.STYLE); //$NON-NLS-1$
        if (style == defaultStyle)
            hasDefaultStyleInGerarchy = true;
    }
    //FIXME: JR has a bug where it dosen't use the default styles if the element has at least one style
    //unit it will be fixed, to show the effective hierarchy, the default style is print only if there 
    //aren't other styles on the element
    if (styles.isEmpty() && !hasDefaultStyleInGerarchy && defaultStyle != null
            && defaultStyle != getElement()) {
        String titleLabelText = MessageFormat.format(Messages.StylesListSection_Inherited_From_Default_Style,
                new Object[] { defaultStyle.getPropertyValue(JRDesignStyle.PROPERTY_NAME) });
        printStyleTitle(titleLabelText, defaultStyle, parent);
        printStyleAttribute(parent, defaultStyle, null, AttributeParent.STYLE); //$NON-NLS-1$ 
    }
}

From source file:net.relet.freimap.LinkInfo.java

public void setLinkProfile(LinkedList<LinkData> lp) {

    XYSeries data = new XYSeries("etx");
    XYSeries avail = new XYSeries("avail");
    XYSeriesCollection datac = new XYSeriesCollection(data);
    datac.addSeries(avail);//w  w w  .  j  a v a 2 s . c o m
    linkChart = ChartFactory.createXYLineChart("average link etx\r\naverage link availability", "time", "etx",
            datac, PlotOrientation.VERTICAL, false, false, false);
    sexupLayout(linkChart);

    long first = lp.getFirst().time, last = lp.getLast().time, lastClock = first, count = 0, //number of samplis in aggregation timespan
            maxCount = 0; //max idem
    long aggregate = (last - first) / CHART_WIDTH; //calculate aggregation timespan: divide available timespan in CHART_WIDTH equal chunks
    double sum = 0;

    /* ok, this ain't effective, we do it just to pre-calculate maxCount */
    ListIterator<LinkData> li = lp.listIterator();
    while (li.hasNext()) {
        LinkData ld = li.next();
        count++;
        if (ld.time - lastClock > aggregate) {
            if (maxCount < count)
                maxCount = count;
            lastClock = ld.time;
            count = 0;
        }
    }

    //reset for second iteration
    count = 0;
    lastClock = first;

    //iterate again
    li = lp.listIterator();
    while (li.hasNext()) {
        LinkData ld = li.next();

        sum += ld.quality;
        count++;

        if (aggregate == 0)
            aggregate = 1000;//dirty hack
        if (ld.time - lastClock > aggregate) {
            for (long i = lastClock; i < ld.time - aggregate; i += aggregate) {
                data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN);
                avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0);
            }

            count = 0;
            sum = 0;
            lastClock = ld.time;
        }
    }

    status = STATUS_AVAILABLE;
}

From source file:com.jaspersoft.studio.property.section.style.StylesListSection.java

/**
 * Print the attributes of all the styles of the element
 * /*from w  ww.j  a v  a  2  s.  c o m*/
 * @param styles
 *          List of styles
 * @param parent
 *          composite of the main widget
 */
private void printStyles(LinkedList<MStyle> styles, Composite parent) {
    ListIterator<MStyle> itr = styles.listIterator();
    boolean hasDefaultStyleInGerarchy = false;
    while (itr.hasNext()) {
        MStyle style = itr.next();
        printStyleAttribute(parent, style, Messages.StylesSectionList_Inherited_From_Style
                + style.getPropertyValue(JRDesignStyle.PROPERTY_NAME), "", elementAttributes, true); //$NON-NLS-1$
        if (style == defaultStyle)
            hasDefaultStyleInGerarchy = true;
    }
    if (!hasDefaultStyleInGerarchy && defaultStyle != null && defaultStyle != getElement())
        printStyleAttribute(parent, defaultStyle,
                Messages.StylesListSection_Inherited_From_Default_Style
                        .concat(defaultStyle.getPropertyValue(JRDesignStyle.PROPERTY_NAME).toString()),
                "", elementAttributes, true); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:com.sun.portal.rssportlet.SettingsHandler.java

/**
 * Persist this handler's <code>RssPortletBean</code>, if necessary.
 *///w  w  w.  j  ava  2  s  .  c om
public void persistSettingsBean(SettingsBean delta) throws ReadOnlyException, IOException, ValidatorException {
    boolean store = false;
    LinkedList feeds = null;
    // selected feed        
    if (delta.getFeeds() != null && delta.getFeedsSize() == 0) {
        // if there are no feeds, set the selected feed to null
        getPortletSession().setAttribute(SessionKeys.SELECTED_FEED, null);
    } else if (delta.getSelectedFeed() != null) {
        getPortletSession().setAttribute(SessionKeys.SELECTED_FEED, delta.getSelectedFeed());
    }

    // feeds and start feed - remove default feeds- not stored in preferences
    if (delta.getFeeds() != null) {
        feeds = delta.getFeeds();
        Iterator it = null;

        if (log.isDebugEnabled()) {
            it = feeds.listIterator();
            while (it.hasNext()) {
                log.debug("Delta feeds before ***********" + (String) it.next());
            }
        }

        //remove mandatory+role feeds- not stored in preferences
        //retrieved from jsp file
        if (delta.getFeedsSize() > 0) {
            if (null != role_feeds && role_feeds.length != 0) {
                feeds = fileterFeeds(delta, role_feeds);
            }
            if (null != mandate_feeds && mandate_feeds.length != 0) {
                feeds = fileterFeeds(delta, mandate_feeds);
            }
        }

        if (log.isDebugEnabled()) {
            it = feeds.listIterator();
            while (it.hasNext()) {
                log.debug("Delta feeds after ***********" + (String) it.next());
            }
        }
        getPortletPreferences().setValues(PrefKeys.USER_FEEDS, (String[]) feeds.toArray(new String[0]));
        getPortletPreferences().setValue(PrefKeys.START_FEED, delta.getStartFeed());
        getPortletPreferences().setValue(PrefKeys.DEFAULT_FEEDS_LEVEL, String.valueOf(default_feeds.size()));
        store = true;
    }
    // feed titles - for all feeds
    if (delta.getFeeds() != null && delta.getFeedsSize() != 0) {
        delta.setTitleList(delta.getFeeds());
    }

    // max age
    if (delta.isMaxAgeSet()) {
        getPortletPreferences().setValue(PrefKeys.MAX_AGE, Integer.toString(delta.getMaxAge()));
        store = true;
    }

    // disable max age
    if (delta.isDisableMaxAgeSet()) {
        getPortletPreferences().setValue(PrefKeys.DISABLE_MAX_AGE, Boolean.toString(delta.isDisableMaxAge()));
        store = true;
    }

    // max entries
    if (delta.isMaxEntriesSet()) {
        getPortletPreferences().setValue(PrefKeys.MAX_ENTRIES, Integer.toString(delta.getMaxEntries()));
        store = true;
    }

    // new window
    if (delta.isNewWindowSet()) {
        getPortletPreferences().setValue(PrefKeys.NEWWIN, Boolean.toString(delta.isNewWindow()));
        store = true;
    }

    if (store) {
        getPortletPreferences().store();
    }
}

From source file:com.projity.grouping.core.hierarchy.MutableNodeHierarchy.java

private List internalIndent(List nodes, int deltaLevel, int actionType) {
    if (deltaLevel != 1 && deltaLevel != -1)
        return null;

    //Indent only parents
    LinkedList nodesToChange = new LinkedList();
    HierarchyUtils.extractParents(nodes, nodesToChange);

    List modifiedVoids = new ArrayList();

    //exclude Assignments and VoidNodes
    if (deltaLevel > 0) {
        for (ListIterator i = nodesToChange.listIterator(); i.hasNext();) {
            if (!internalIndent((Node) i.next(), deltaLevel, actionType & NodeModel.UNDO, modifiedVoids))
                i.remove();//from  w w  w  . jav a2 s.  c o m
            for (Iterator j = modifiedVoids.iterator(); j.hasNext();) {
                i.add(j.next());
            }
            modifiedVoids.clear();
        }
    } else {
        for (ListIterator i = nodesToChange.listIterator(nodesToChange.size()); i.hasPrevious();) {
            if (!internalIndent((Node) i.previous(), deltaLevel, actionType & NodeModel.UNDO, modifiedVoids))
                i.remove();
            for (Iterator j = modifiedVoids.iterator(); j.hasNext();) {
                i.add(j.next());
            }
            modifiedVoids.clear();
        }
    }

    if (isEvent(actionType) && nodesToChange.size() > 0)
        fireNodesChanged(this, nodesToChange.toArray());
    return nodesToChange;
}

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParser.java

public void parse(String[] args) throws CmdLineParseException {
    LinkedList<String> arglist = new LinkedList<String>();
    arglist.addAll(Arrays.asList(args));

    // Quick Help
    if (arglist.contains("--" + OPT_HELP)) {
        usage();//from w w  w .java2  s . c o  m
        return;
    }

    // Configuration File Option
    int idx = arglist.indexOf("--" + OPT_CONFIG);
    if (idx >= 0) {
        if (idx + 1 > arglist.size()) {
            throw new CmdLineParseException("Expected <File> parameter for option: --" + OPT_CONFIG);
        }
        String value = arglist.get(idx + 1);
        File file = (File) ConvertUtils.convert(value, File.class);

        this.configer.setPersistFile(file);

        arglist.remove(idx + 1);
        arglist.remove(idx);
    }

    // Save Options Option
    boolean saveOptions = false;

    idx = arglist.indexOf("--" + OPT_SAVE);
    if (idx >= 0) {
        saveOptions = true;
        arglist.remove(idx);
    }

    // Restore from persist first.
    try {
        configer.restore();
    } catch (IOException e) {
        throw new CmdLineParseException("Unable to load configuration: " + e.getMessage(), e);
    }

    // Set values from command line now.
    String value;
    ListIterator<String> iter = arglist.listIterator();
    while (iter.hasNext()) {
        String arg = iter.next();
        if (arg.startsWith("--")) {
            // Its an option.
            String optname = arg.substring(2);

            Configurable cfgrbl = configer.getConfigurable(optname);

            if (cfgrbl == null) {
                throw new CmdLineParseException("Invalid Option: " + arg);
            }

            if (!iter.hasNext()) {
                throw new CmdLineParseException(
                        "Expected <" + cfgrbl.getType() + "> parameter for option: " + arg);
            }
            value = iter.next();
            configer.setValue(optname, value);
            continue; // process next arg
        }

        // All others are considered args.
        addToRawArgs(arg);
    }

    // Save options (if specified)
    if (saveOptions) {
        try {
            configer.persist();
        } catch (IOException e) {
            throw new CmdLineParseException("Unable to save configuration: " + e.getMessage(), e);
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.IndividualSDB.java

private List<VClass> getMyVClasses(boolean assertedOnly) {
    List<VClass> vClassList = new ArrayList<VClass>();
    Model tempModel = null;/*from  w  w  w. ja  va  2  s.com*/
    if (ind.getModel().contains((Resource) null, RDF.type, (RDFNode) null)) {
        tempModel = ind.getModel();
    } else {
        String getTypesQuery = buildMyVClassesQuery(assertedOnly);

        RDFService service = webappDaoFactory.getRDFService();
        try {
            tempModel = RDFServiceUtils.parseModel(
                    service.sparqlConstructQuery(getTypesQuery, RDFService.ModelSerializationFormat.N3),
                    RDFService.ModelSerializationFormat.N3);
        } catch (RDFServiceException e) {
            throw new RuntimeException(e);
        }
    }
    StmtIterator stmtItr = tempModel.listStatements((Resource) null, RDF.type, (RDFNode) null);
    LinkedList<String> list = new LinkedList<String>();
    while (stmtItr.hasNext()) {
        Statement stmt = stmtItr.nextStatement();
        if (stmt.getObject().isResource() && !stmt.getObject().isAnon()) {
            list.add(((Resource) stmt.getObject()).getURI());
        }
    }
    Iterator<String> itr = null;
    VClassDao checkSubClass = this.webappDaoFactory.getVClassDao();
    boolean directTypes = false;
    String currentType = null;
    ArrayList<String> done = new ArrayList<String>();

    /* Loop for comparing starts here */
    if (assertedOnly) {
        while (!directTypes) {
            itr = list.listIterator();

            do {
                if (itr.hasNext()) {
                    currentType = itr.next();
                } else {
                    directTypes = true; // get next element for comparison
                    break;
                }
            } while (done.contains(currentType));

            if (directTypes)
                break;
            // check to see if it's all over otherwise start comparing
            else
                itr = list.listIterator();

            while (itr.hasNext()) {
                String nextType = itr.next();
                if (checkSubClass.isSubClassOf(currentType, nextType)
                        && !currentType.equalsIgnoreCase(nextType)) {
                    itr.remove();
                }
            }

            done.add(currentType); // add the uri to done list. 
        }
    }

    /* Loop for comparing ends here */
    Iterator<String> typeIt = list.iterator();

    for (Iterator it = typeIt; it.hasNext();) {
        Resource type = ResourceFactory.createResource(it.next().toString());
        String typeURI = (!type.isAnon()) ? type.getURI()
                : VitroVocabulary.PSEUDO_BNODE_NS + type.getId().toString();
        if (type.getNameSpace() == null
                || (!webappDaoFactory.getNonuserNamespaces().contains(type.getNameSpace()))) {
            VClass vc = webappDaoFactory.getVClassDao().getVClassByURI(type.getURI());
            if (vc != null) {
                vClassList.add(vc);
            }
        }
    }

    try {
        Collections.sort(vClassList);
    } catch (Exception e) {
        log.error("Unable to sort VClass list", e);
    }

    return vClassList;
}