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:com.platum.restflow.RestflowModel.java

/**
 * //from  ww  w  .j  a  v  a  2 s  .co m
 * @param name
 * @return
 */
public RestflowModel removeResource(String name) {
    if (resources != null) {
        ListIterator<Resource> iterator = resources.listIterator();
        while (iterator.hasNext()) {
            if (iterator.next().getName().equals(name)) {
                iterator.remove();
                return this;
            }
        }
    }
    throw new RestflowNotExistsException("Resource does not exists.");
}

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

/** 
 * Add EditRepresentation as a variant when appropriate. 
 * //  www.jav  a 2 s  .  c  o  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.offbynull.voip.kademlia.model.NodeLeastRecentSet.java

public ActivityChangeSet remove(Node node) {
    Validate.notNull(node);/*from  w ww. jav  a 2s  .c om*/

    Id nodeId = node.getId();

    InternalValidate.matchesLength(baseId.getBitLength(), nodeId);

    ListIterator<Activity> it = entries.listIterator();
    while (it.hasNext()) {
        Activity entry = it.next();

        Id entryId = entry.getNode().getId();

        if (entryId.equals(nodeId)) {
            InternalValidate.matchesLink(entry.getNode(), node);

            // remove
            it.remove();
            return ActivityChangeSet.removed(entry);
        }
    }

    return ActivityChangeSet.NO_CHANGE;
}

From source file:com.xtivia.training.BookPortlet.java

@ProcessAction(name = "ajaxDelete")
public void ajaxDelete(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    response.setContentType("text/html");
    String isbn = request.getParameter("isbn");
    ListIterator iterator = books.listIterator();
    while (iterator.hasNext()) {
        Book book = (Book) iterator.next();
        String isbns = book.getIsbnNumber() + "";
        if (isbn.equals(isbns)) {
            iterator.remove();
        }// w  w  w  .  ja va2  s  .co  m
    }
    request.setAttribute("books", books);
    System.out.println("I am in ajax delete");
    /*request.setAttribute("books", books);
    System.out.println("I am here whats up");
    include(templateJSP, request, response, PortletRequest.RESOURCE_PHASE);*/
}

From source file:com.xtivia.training.BookPortlet.java

public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    response.setContentType("text/html");
    String message = request.getParameter("message");
    String isbn = message;//w  w w .  jav a  2s  .com
    ListIterator iterator = books.listIterator();
    while (iterator.hasNext()) {
        Book book = (Book) iterator.next();
        String isbns = book.getIsbnNumber() + "";
        if (isbn.equals(isbns)) {
            iterator.remove();
        }
    }
    request.setAttribute("books", books);
    System.out.println("I am in ajax delete");

    // this seems to be the page that was calling...?
    String resourceID = request.getResourceID();
    System.out.println("resourceId was : " + resourceID);
    System.out.println("message was : " + message);
}

From source file:storm.mesos.resources.RangeResource.java

private List<ResourceEntry> removeAndGet(Collection<ReservationType> reservationTypes,
        RangeResourceEntry desiredRange) {
    // Because of the way Storm does assignments, we will only ever need a single port at a time, bail out if this is not the case
    assert desiredRange.getBegin() == desiredRange.getEnd();

    List<ResourceEntry> removedResources = new ArrayList<>();
    Long desiredPort = desiredRange.getBegin();

    // Iterate over all of the available resources
    for (ReservationType reservationType : reservationTypes) {
        List<RangeResourceEntry> availableRanges = availableResourcesByReservationType.get(reservationType);
        ListIterator<RangeResourceEntry> iterator = availableRanges.listIterator();
        while (iterator.hasNext()) {
            RangeResourceEntry availableRange = iterator.next();
            if (desiredPort >= availableRange.getBegin() && desiredPort <= availableRange.getEnd()) {
                iterator.remove();
                // Salvage resources before the beginning of the requested port
                if (availableRange.getBegin() < desiredPort) {
                    iterator.add(new RangeResourceEntry(reservationType, availableRange.getBegin(),
                            desiredPort - 1));
                }//from  ww  w.  j  a v a  2s.com
                // Salvage resources after the end of the requested port
                if (availableRange.getEnd() > desiredPort) {
                    iterator.add(
                            new RangeResourceEntry(reservationType, desiredPort + 1, availableRange.getEnd()));
                }
                // Now that we've salvaged all available resources, add the resources for the specifically requested range
                removedResources.add(new RangeResourceEntry(reservationType, desiredPort, desiredPort));
                break;
            }
        }
    }
    return removedResources;
}

From source file:org.elasticsoftware.elasticactors.geoevents.actors.Region.java

private void handle(DeRegisterInterest message) {
    State state = getState(State.class);
    ListIterator<RegisterInterest> itr = state.getListeners().listIterator();
    while (itr.hasNext()) {
        RegisterInterest registeredInterest = itr.next();
        if (registeredInterest.getActorRef().equals(message.getActorRef())
                && registeredInterest.getLocation().equals(message.getLocation())) {
            itr.remove();
            if (message.isPropagate()) {
                // remove without propagating
                removeFromOtherRegions(state.getId(), registeredInterest,
                        new DeRegisterInterest(message.getActorRef(), message.getLocation(), false));
            }/*from w ww  .j a v a  2s.  c om*/
        }
    }
}

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

public int removeUnpopulatedGroups(List<PropertyGroup> groups) {
    if (groups == null || groups.size() == 0)
        return 0;
    int removedGroupsCount = 0;
    ListIterator<PropertyGroup> it = groups.listIterator();
    while (it.hasNext()) {
        PropertyGroup group = it.next();
        List properties = group.getPropertyList();
        if (properties == null || properties.size() < 1) {
            removedGroupsCount++;//from w  ww . java  2  s.com
            it.remove();
        }
    }
    return removedGroupsCount;
}

From source file:com.xtivia.training.BookPortlet.java

@ProcessAction(name = "editBookAction")
public void editBookAction(ActionRequest actionRequest, ActionResponse actionResponse) {
    String isbn = actionRequest.getParameter("isbn");
    ArrayList<String> errors = new ArrayList<String>();
    Book bookEdit = ActionUtil.getFormRequest(actionRequest);
    boolean validate = ValidateBook.validateBook(bookEdit, errors);
    Book fromArray = null;//from   www  .ja v a2 s .co  m
    if (validate) {
        ListIterator iterator = books.listIterator();
        while (iterator.hasNext()) {
            Book book = (Book) iterator.next();
            String isbns = book.getIsbnNumber() + "";
            if (isbn.equals(isbns)) {
                iterator.remove();
            }
        }
        books.add(bookEdit);
        actionRequest.setAttribute("book", bookEdit);
        actionResponse.setRenderParameter(MYACTION_PARAM, bookJSP);
    } else {
        for (String error : errors) {
            SessionErrors.add(actionRequest, error);
        }
        SessionErrors.add(actionRequest, "error-saving-book");
        actionResponse.setRenderParameter(MYACTION_PARAM, addJSP);
        actionRequest.setAttribute("book", bookEdit);
        actionRequest.setAttribute("edit", "edit");
    }
}

From source file:org.apache.solr.cloud.ExclusiveSliceProperty.java

private void removeSliceAlreadyHostedFromPossibles(String sliceName) {
    for (Map.Entry<String, List<SliceReplica>> entReplica : nodesHostingReplicas.entrySet()) {

        ListIterator<SliceReplica> iter = entReplica.getValue().listIterator();
        while (iter.hasNext()) {
            SliceReplica sr = iter.next();
            if (sr.slice.getName().equals(sliceName))
                iter.remove();
        }/*from w w  w. j ava  2  s .  c o m*/
    }
}