Example usage for java.util Iterator remove

List of usage examples for java.util Iterator remove

Introduction

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

Prototype

default void remove() 

Source Link

Document

Removes from the underlying collection the last element returned by this iterator (optional operation).

Usage

From source file:ch.tatool.app.service.impl.TrialDAO.java

/** Delete a trial object. */
public void deleteTrial(Module module, ModuleSession session, Trial trial) {
    Iterator<Trial> it = ((ModuleSessionImpl) session).getTrials().iterator();
    while (it.hasNext()) {
        Trial t = it.next();/*w ww  .  j a  v  a  2 s .c o  m*/
        if (t.getId().equals(trial.getId())) {
            it.remove();
        }
    }
    getHibernateTemplate().delete(trial);
}

From source file:net.mindengine.oculus.frontend.web.controllers.report.ReportBrowseRememberSelectedRunsController.java

public void removeCollectedTestRuns(String ids, Session session) {
    List<TestRunSearchData> list = session.getCollectedTestRuns();
    if (list != null) {
        String[] id = ids.split(",");

        for (int i = 0; i < id.length; i++) {
            Iterator<TestRunSearchData> iterator = list.iterator();
            boolean bFound = false;
            while (iterator.hasNext() && !bFound) {
                TestRunSearchData run = iterator.next();
                if (run.getTestRunId().equals(Long.parseLong(id[i]))) {
                    iterator.remove();
                    bFound = true;/*from  ww  w .  ja  v a 2s  .com*/
                }
            }
        }
    }
    // Setting again the collected runs list to session as the content of
    // this list was changed and it is necessary
    // to update the id field of each item in list in the following method
    session.setCollectedTestRuns(list);
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTResources.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {

    // Extract the uri from which list the resources...
    String uri = restUtils.extractRepositoryUri(req.getPathInfo());

    // "resources" is a REST service path
    if (uri == null || "resources".equals(uri))
        uri = "/";

    // Extract the criteria
    String queryString = req.getParameter("q");
    if (queryString == null || queryString.length() == 0) {
        queryString = null;/*from w ww.ja v  a2 s .  c om*/
    }
    List<String> resourceTypes = new ArrayList<String>();

    String[] resourceTypesArray = req.getParameterValues("type");
    if (resourceTypesArray != null) {
        resourceTypes.addAll(Arrays.asList(resourceTypesArray));
    }

    Iterator<String> itr = resourceTypes.iterator();
    while (itr.hasNext()) {
        String resourceType = itr.next();
        if (!(resourceType != null && resourceType.length() != 0)) {
            itr.remove();
        }
    }

    int limit = 0;

    if (req.getParameter("limit") != null && req.getParameter("limit").length() > 0) {
        try {
            limit = Integer.parseInt(req.getParameter("limit"));
            if (limit < 0)
                throw new Exception();
        } catch (Throwable ex) {
            restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp,
                    "Invalid value set for parameter limit.");
            return;
        }
    }
    int startIndex = 0;

    if (req.getParameter("startIndex") != null && req.getParameter("startIndex").length() > 0) {
        try {
            startIndex = Integer.parseInt(req.getParameter("startIndex"));
            if (startIndex < 0)
                throw new Exception();
        } catch (Throwable ex) {
            restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp,
                    "Invalid value set for parameter startIndex.");
            return;
        }
    }

    List list = new ArrayList();

    // If not a search, just list the content of the specified folder...
    if (queryString == null && (resourceTypes.size() == 0)) {
        list = resourcesListRemoteService.listResources(uri, limit);
    } else {

        boolean recursive = false;
        if (req.getParameter("recursive") != null && (req.getParameter("recursive").equals("1")
                || req.getParameter("recursive").equalsIgnoreCase("true")
                || req.getParameter("recursive").equalsIgnoreCase("yes"))) {
            recursive = true;
        }

        //list = service.getResources(criteria, limit, resourceTypes == null ? null : Arrays.asList(resourceTypes));
        list = resourcesListRemoteService.getResources(uri, queryString,
                resourceTypes.size() == 0 ? null : resourceTypes, recursive, limit, startIndex);

    }

    StringBuilder xml = new StringBuilder();

    Marshaller m = new Marshaller();
    xml.append("<resourceDescriptors>\n");
    if (list != null && !list.isEmpty())
        for (Object rd : list) {
            // we assume the objects are actually resource descriptors...
            xml.append(m.writeResourceDescriptor((ResourceDescriptor) rd));
        }

    xml.append("</resourceDescriptors>");

    restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, xml.toString());
}

From source file:de.axelfaust.alfresco.nashorn.repo.loaders.CallerProvidedURLConnection.java

protected void cacheMetaData(final String digest) {
    synchronized (STRING_SCRIPT_META_CACHE) {
        STRING_SCRIPT_META_CACHE.put(digest,
                new Pair<Long, Long>(Long.valueOf(this.contentLength), Long.valueOf(this.lastModified)));

        if (STRING_SCRIPT_META_CACHE.size() > STRING_SCRIPT_META_MAX_CACHE_SIZE) {
            final Iterator<String> iterator = STRING_SCRIPT_META_CACHE.keySet().iterator();
            while (STRING_SCRIPT_META_CACHE.size() > STRING_SCRIPT_META_MAX_CACHE_SIZE && iterator.hasNext()) {
                iterator.next();/*from  w w  w. ja  v a2s . c o m*/
                iterator.remove();
            }
        }
    }
}

From source file:org.wallride.support.PageUtils.java

private void createNode(TreeNode<Page> parent, Collection<Page> pages) {
    List<TreeNode<Page>> children = new ArrayList<>();
    Iterator<Page> i = pages.iterator();
    while (i.hasNext()) {
        Page page = i.next();//w w  w .java 2  s  . c  o  m
        TreeNode<Page> node = new TreeNode<>(page);
        node.setParent(parent);
        if (parent.getObject().equals(page.getParent())) {
            children.add(node);
            i.remove();
        }
    }
    parent.setChildren(children);

    for (TreeNode<Page> node : children) {
        createNode(node, pages);
    }
}

From source file:org.activiti.explorer.cache.TrieBasedUserCache.java

public void notifyUserDataChanged(String userId) {
    User newData = identityService.createUserQuery().userId(userId).singleResult();

    // Update user trie: first remove old values
    if (keyCache.containsKey(userId)) {
        for (String key : keyCache.get(userId)) {
            List<User> users = userTrie.find(key);
            if (users != null && !users.isEmpty()) {
                Iterator<User> userIterator = users.iterator();
                while (userIterator.hasNext()) {
                    User next = userIterator.next();
                    if (next.getId().equals(userId)) {
                        userIterator.remove();
                    }/*from ww w.j a va  2s . c o m*/
                }
            }
        }
    }

    // Update key cache
    keyCache.remove(userId);

    if (newData != null) {
        // Update user trie: add new value
        addTrieItem(newData);

        // Update user cache
        userCache.put(newData.getId(), newData);
    }
}

From source file:de.dhke.projects.cutil.collections.aspect.AspectMultiMapValueCollection.java

@Override
public boolean remove(final Object o) {
    /**/*from  w ww  .  j  a va 2  s.  c  o  m*/
     * This potentially changes the behaviour of the underlying
     * collection, as the first key-value-pair with a matching
     * value will be removed.
     *
     * Also, searching through the collection may also
     * be slower as the remove()-implementation in the backend map.
     *
     * Still, this seems to be the only proper way to support to remove
     * items from the value collection.
     */
    Iterator<V> iter = iterator();
    while (iter.hasNext()) {
        V value = iter.next();
        if (value.equals(o)) {
            iter.remove();
            return true;
        }
    }
    return false;
}

From source file:com.yahoo.labs.samoa.streams.fs.LocalFileStreamSourceTest.java

@Test
public void testGetNextInputStream() {
    // write input files & noise files
    writeSimpleFiles(BASE_DIR, "txt", NUM_FILES_IN_DIR);

    // init with path to input dir
    streamSource.init(BASE_DIR, "txt");

    // call getNextInputStream & assertions
    Set<String> contents = new HashSet<>();
    for (int i = 1; i <= NUM_FILES_IN_DIR; i++) {
        contents.add(Integer.toString(i));
    }/*from  ww  w  .  j a  v a2s  .  com*/
    for (int i = 0; i < NUM_FILES_IN_DIR; i++) {
        InputStream inStream = streamSource.getNextInputStream();
        assertNotNull("Unexpected end of input stream list.", inStream);

        BufferedReader rd = new BufferedReader(new InputStreamReader(inStream));
        String inputRead = null;
        try {
            inputRead = rd.readLine();
        } catch (IOException ioe) {
            fail("Fail reading from stream at index:" + i + ioe.getMessage());
        }
        assertTrue("File content is incorrect.", contents.contains(inputRead));
        Iterator<String> it = contents.iterator();
        while (it.hasNext()) {
            if (it.next().equals(inputRead)) {
                it.remove();
                break;
            }
        }
    }

    // assert that another call to getNextInputStream will return null
    assertNull("Call getNextInputStream after the last file did not return null.",
            streamSource.getNextInputStream());
}

From source file:net.duckling.ddl.service.mobile.android.AndroidNoticeHandler.java

private void refresh() {
    long d = System.currentTimeMillis();
    if ((refreshTime + 1000 * 60 * 15) < d) {
        refreshTime = d;// www.jav  a  2s  .c om
        Iterator<Set<UserNoticeHandle>> it = userNoticeHandlers.values().iterator();
        while (it.hasNext()) {
            Set<UserNoticeHandle> handle = it.next();
            if (handle != null) {
                Iterator<UserNoticeHandle> i = handle.iterator();
                while (i.hasNext()) {
                    UserNoticeHandle h = i.next();
                    if (h.isExpired()) {
                        i.remove();
                    }
                }
            }
        }
    }
}

From source file:com.benfante.minimark.blo.AssessmentFillingBo.java

private List<AssessmentFilling> filterByAuthorization(List<AssessmentFilling> fillings) {
    Iterator<AssessmentFilling> fit = fillings.iterator();
    while (fit.hasNext()) {
        AssessmentFilling assessmentFilling = fit.next();
        if (!userProfileBo.canCurrentUserMonitorAssessment(assessmentFilling.getAssessment())) {
            fit.remove();
        }/*from w  w w  . j  a  v  a2s  .c om*/
    }
    return fillings;
}