Example usage for java.util ListIterator remove

List of usage examples for java.util ListIterator remove

Introduction

In this page you can find the example usage for java.util ListIterator remove.

Prototype

void remove();

Source Link

Document

Removes from the list the last element that was returned by #next or #previous (optional operation).

Usage

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  av  a  2  s  . co  m
            "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:org.jcodec.movtool.Util.java

public static Pair<List<Edit>> split(List<Edit> edits, Rational trackByMv, long tvMv) {
    long total = 0;
    List<Edit> l = new ArrayList<Edit>();
    List<Edit> r = new ArrayList<Edit>();
    ListIterator<Edit> lit = edits.listIterator();
    while (lit.hasNext()) {
        Edit edit = lit.next();//from ww w  .  ja v  a2s. c  o  m
        if (total + edit.getDuration() > tvMv) {
            int leftDurMV = (int) (tvMv - total);
            int leftDurMedia = trackByMv.multiplyS(leftDurMV);

            Edit left = new Edit(leftDurMV, edit.getMediaTime(), 1.0f);
            Edit right = new Edit(edit.getDuration() - leftDurMV, leftDurMedia + edit.getMediaTime(), 1.0f);

            lit.remove();
            if (left.getDuration() > 0) {
                lit.add(left);
                l.add(left);
            }
            if (right.getDuration() > 0) {
                lit.add(right);
                r.add(right);
            }
            break;
        } else {
            l.add(edit);
        }
        total += edit.getDuration();
    }
    while (lit.hasNext()) {
        r.add(lit.next());
    }
    return new Pair<List<Edit>>(l, r);
}

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.//from  w  ww .  j  a v a2 s  .c  o  m
*
* @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:org.scify.NewSumServer.Server.Utils.Main.java

private static void writeSummaryToFile(List<Sentence> lsSen, String sCluster, HashMap<String, Topic> hsTopics)
        throws IOException {
    File f = new File(sTxtSumPath);
    if (!f.exists()) {
        System.err.println("FILE " + sTxtSumPath + " DOES NOT EXIST");
        if (!f.mkdirs()) {
            System.err.println("FILE " + sTxtSumPath + " Could not be created");
        }//from w  w w .  j  av  a2 s.  co m
    }
    if (f.isDirectory()) {
        f.setWritable(true);
    }
    String sFullFileName = sTxtSumPath + sCluster + ".txt";
    File fFile = new File(sFullFileName);
    fFile.createNewFile();
    BufferedWriter bw = new BufferedWriter(new FileWriter(fFile, false));
    bw.write("ClusterID" + sSep + sCluster);
    bw.newLine();
    bw.write("Title: " + hsTopics.get(sCluster).getTitle());
    bw.write(("\n========================================\n"));
    StringBuilder sb = new StringBuilder();
    ListIterator<Sentence> li = lsSen.listIterator();
    while (li.hasNext()) {
        Sentence sCur = li.next();
        if (sCur.getSnippet().split("[;,. ]").length < 5) {
            li.remove();
        }
    }
    lsSen = new RedundancyRemover().removeRedundantSentences(lsSen);
    for (Sentence each : lsSen) {
        sb.append(each.getSnippet());
        sb.append("\n========================================\n");
        //            sb.append(each.getLinkToSource());
        //            sb.append("\n");
        //            sb.append(each.getFeed());
        //            sb.append("\n");
    }
    bw.write(sb.toString());
    bw.close();
}

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
 *//*from   w  ww. java  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:Main.java

/**
 * Returns a list iterator that swaps all previous/next calls.
 * <p><b>Important:</b> The returned iterator violates the {@link ListIterator#nextIndex()} and {@link ListIterator#previousIndex()} specifications.
 *//*from w  w w.java 2s .c om*/
public static <E> ListIterator<E> reverse(ListIterator<E> iterator) {
    return new ListIterator<E>() {
        @Override
        public boolean hasNext() {
            return iterator.hasPrevious();
        }

        @Override
        public E next() {
            return iterator.previous();
        }

        @Override
        public boolean hasPrevious() {
            return iterator.hasNext();
        }

        @Override
        public E previous() {
            return iterator.next();
        }

        @Override
        public int nextIndex() {
            return iterator.previousIndex();
        }

        @Override
        public int previousIndex() {
            return iterator.nextIndex();
        }

        @Override
        public void remove() {
            iterator.remove();
        }

        @Override
        public void set(E e) {
            iterator.set(e);
        }

        @Override
        public void add(E e) {
            iterator.add(e);
        }
    };
}

From source file:org.wso2.carbon.bpel.ui.BpelUIUtil.java

/**
 * when scope events defined in deploy.xml is changed in runtime by DD Editor this method is used to get the
 * updated events list//from   w ww.j  a v  a  2 s  .  c  o  m
 * assigned with each scope event. It is got as a string array with the data about the events selected and
 * categories into (5 for each) groups. Then these events list is again written back to the corresponding scope
 * event
 */
public static void updateScopeEvents(String[] selecttype, List<String> scopeNames,
        DeploymentDescriptorUpdater deployDescriptorUpdater) {
    ArrayList<String> valueArray = selecttype != null ? new ArrayList<String>(Arrays.asList(selecttype))
            : new ArrayList<String>();
    ListIterator<String> it = valueArray.listIterator();
    while (it.hasNext()) {
        String nextVal = it.next();
        if (!nextVal.equalsIgnoreCase("0") && it.hasNext()) {
            it.next();
            it.remove();
        }
    }

    String[] allEnabledEvents = valueArray.toArray(new String[valueArray.size()]);
    ScopeEventType[] scopeEventTypes = new ScopeEventType[scopeNames.size()];
    for (int j = 0; j < scopeNames.size(); j++) {
        ScopeEventType scopeEventType = new ScopeEventType();
        scopeEventType.setScope(scopeNames.get(j));
        String[] events = new String[5];
        System.arraycopy(allEnabledEvents, 0, events, 0, 5);
        ArrayList<String> actualEventsList = new ArrayList<String>();
        for (String event : events) {
            if (!event.equalsIgnoreCase("0")) {
                actualEventsList.add(event);
            }
        }
        String[] eventsArray = actualEventsList.toArray(new String[actualEventsList.size()]);

        EnableEventListType enableEventListType = new EnableEventListType();
        enableEventListType.setEnableEvent(eventsArray);
        scopeEventType.setEnabledEventList(enableEventListType);

        scopeEventTypes[j] = scopeEventType;
    }
    deployDescriptorUpdater.setScopeEvents(scopeEventTypes);

}

From source file:org.apache.directory.fortress.core.util.VUtil.java

/**
 * This utility iterates over all of the Validators initialized for runtime and calls them passing the {@link org.apache.directory.fortress.core.model.Constraint} contained within the
 * targeted entity.  If a particular {@link org.apache.directory.fortress.core.model.UserRole} violates constraint it will not be activated.  If {@link org.apache.directory.fortress.core.model.User} validation fails a ValidationException will be thrown thus preventing User logon.
 *
 * @param session contains {@link org.apache.directory.fortress.core.model.User} and {@link org.apache.directory.fortress.core.model.UserRole} constraints {@link org.apache.directory.fortress.core.model.Constraint} to be checked.
 * @param type    specifies User {@link ConstraintType#USER} or rOLE {@link ConstraintType#ROLE}.
 * @param checkDsd will check DSD constraints if true
 * @throws org.apache.directory.fortress.core.SecurityException in the event validation fails for User or system error occurs.
 *//*from  ww  w.ja  v  a 2 s  .c o  m*/
public static void validateConstraints(Session session, ConstraintType type, boolean checkDsd)
        throws SecurityException {
    String location = "validateConstraints";
    int rc;
    if (validators == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("{} userId [{}]  no constraints enabled", location, session.getUserId());
        }
        return;
    }
    // no need to continue if the role list is empty and we're trying to check role constraints:
    else if (type == ConstraintType.ROLE && !CollectionUtils.isNotEmpty(session.getRoles())
            && !CollectionUtils.isNotEmpty(session.getAdminRoles())) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("{} userId [{}]  has no roles assigned", location, session.getUserId());
        }
        return;
    }
    for (Validator val : validators) {
        Time currTime = TUtil.getCurrentTime();
        // first check the constraint on the user:
        if (type == ConstraintType.USER) {
            rc = val.validate(session, session.getUser(), currTime, type);
            if (rc > 0) {
                String info = location + " user [" + session.getUserId() + "] was deactivated reason code ["
                        + rc + "]";
                throw new ValidationException(rc, info);
            }
        }
        // Check the constraints for each activated role:
        else {
            if (CollectionUtils.isNotEmpty(session.getRoles())) {
                // now check the constraint on every role activation candidate contained within session object:
                ListIterator<UserRole> roleItems = session.getRoles().listIterator();

                while (roleItems.hasNext()) {
                    Constraint constraint = roleItems.next();
                    rc = val.validate(session, constraint, currTime, type);

                    if (rc > 0) {
                        String msg = location + " role [" + constraint.getName() + "] for user ["
                                + session.getUserId() + "] was deactivated reason code [" + rc + "]";
                        LOG.info(msg);
                        roleItems.remove();
                        session.setWarning(new ObjectFactory().createWarning(rc, msg, Warning.Type.ROLE,
                                constraint.getName()));
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(session.getAdminRoles())) {
                // now check the constraint on every arbac role activation candidate contained within session object:
                ListIterator roleItems = session.getAdminRoles().listIterator();
                while (roleItems.hasNext()) {
                    Constraint constraint = (Constraint) roleItems.next();
                    rc = val.validate(session, constraint, currTime, ConstraintType.ROLE);
                    if (rc > 0) {
                        String msg = location + " admin role [" + constraint.getName() + "] for user ["
                                + session.getUserId() + "] was deactivated reason code [" + rc + "]";
                        LOG.info(msg);
                        roleItems.remove();
                        session.setWarning(new ObjectFactory().createWarning(rc, msg, Warning.Type.ROLE,
                                constraint.getName()));
                    }
                }
            }
        }
    }

    // now perform DSD validation on session's impl roles:
    if (checkDsd && DSDVALIDATOR != null && DSDVALIDATOR.length() > 0 && type == ConstraintType.ROLE
            && CollectionUtils.isNotEmpty(session.getRoles())) {
        Validator dsdVal = (Validator) ClassUtil.createInstance(DSDVALIDATOR);
        dsdVal.validate(session, session.getUser(), null, null);
    }
    // reset the user's last access timestamp:
    session.setLastAccess();
}

From source file:org.jactr.tools.tracer.sinks.FileSink.java

public void flush() throws Exception {
    synchronized (_queue) {
        ListIterator<ITransformedEvent> itr = _queue.listIterator();
        while (itr.hasNext()) {
            _outputStream.writeObject(itr.next());
            itr.remove();
        }//w  w  w .j av a2 s.  com
    }
    _outputStream.flush();
}

From source file:net.netheos.pcsapi.request.Headers.java

/**
 * Remove a header from the list//from   w  w  w.  j a va  2  s  .  co m
 *
 * @param name The header name
 */
public void removeHeader(String name) {
    ListIterator<Header> it = headers.listIterator();
    while (it.hasNext()) {
        if (it.next().getName().equals(name)) {
            it.remove();
        }
    }
}