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:de.dhke.projects.cutil.collections.aspect.AspectMapValueCollectionTest.java

/**
 * Test of iterator method, of class AspectMapValueCollection.
 *//* w w w  .  j av  a2 s.  co  m*/
@Test
public void testIterator_remove() {
    _baseMap.put("_", "1");
    Iterator<String> iter = _values.iterator();
    /* this empty while loop is intentional */
    while (!iter.next().equals("1"))
        ;
    iter.remove();
    /* the other value stays. It is not really possible to identify, which one */
    assertTrue(_values.contains("1"));
}

From source file:com.epam.ta.reportportal.core.dashboard.impl.UpdateDashboardHandler.java

@Override
public OperationCompletionRS updateDashboard(UpdateDashboardRQ rq, String dashboardId, String userName,
        String projectName) {/*from w  w w. j a  v  a2 s  .  c om*/

    StringBuilder additionalInfo = new StringBuilder();
    Dashboard dashboard = dashboardRepository.findOne(dashboardId);
    expect(dashboard, notNull()).verify(DASHBOARD_NOT_FOUND, dashboardId);

    AclUtils.isAllowedToEdit(dashboard.getAcl(), userName, projectRepository.findProjectRoles(userName),
            dashboard.getName());
    expect(dashboard.getProjectName(), equalTo(projectName)).verify(ACCESS_DENIED);

    ofNullable(rq.getName()).ifPresent(it -> {
        Dashboard isExist = dashboardRepository.findOneByUserProject(userName, projectName, rq.getName());
        if (isExist != null && !dashboardId.equalsIgnoreCase(isExist.getId()))
            fail().withError(RESOURCE_ALREADY_EXISTS, rq.getName());
        dashboard.setName(it.trim());
    });

    ofNullable(rq.getDescription()).ifPresent(dashboard::setDescription);

    expect(null != rq.getAddWidget() && null != rq.getDeleteWidgetId()
            && rq.getDeleteWidgetId().equalsIgnoreCase(rq.getAddWidget().getWidgetId()), equalTo(Boolean.FALSE))
                    .verify(DASHBOARD_UPDATE_ERROR, "Unable delete and add the same widget simultaneously.");

    // update widget (or list of widgets if one of them change position on
    // dashboard)
    ofNullable(rq.getWidgets()).ifPresent(rqWidgets -> {
        for (WidgetObject widget : dashboard.getWidgets()) {
            rqWidgets.stream()
                    .filter(updWidget -> widget.getWidgetId().equalsIgnoreCase(updWidget.getWidgetId()))
                    .forEach(updWidget -> {
                        ofNullable(updWidget.getWidgetPosition()).ifPresent(widget::setWidgetPosition);
                        ofNullable(updWidget.getWidgetSize()).ifPresent(widget::setWidgetSize);
                    });
        }
    });

    // add widget
    if (null != rq.getAddWidget()) {
        Widget widget = widgetRepository.findOneLoadACL(rq.getAddWidget().getWidgetId());
        validateAddingWidget(dashboard.getWidgets(), widget, rq.getAddWidget().getWidgetId(), userName,
                projectName);

        // add widget position
        if ((null == rq.getAddWidget().getWidgetPosition())
                || (rq.getAddWidget().getWidgetPosition().size() < 2)) {
            List<Integer> widgetPosition = new ArrayList<>();
            int yPosition = 0;
            int xPosition = 0;
            List<WidgetObject> widgets = dashboard.getWidgets();
            for (WidgetObject widgetObject : widgets) {
                if ((widgetObject.getWidgetPosition().size() > 1)
                        && (widgetObject.getWidgetPosition().get(1) > yPosition)) {
                    yPosition = widgetObject.getWidgetPosition().get(1);
                }
            }
            widgetPosition.add(xPosition);
            widgetPosition.add(++yPosition);
            rq.getAddWidget().setWidgetPosition(widgetPosition);
        }

        dashboard.getWidgets().add(new WidgetObject(widget.getId(), rq.getAddWidget().getWidgetSize(),
                rq.getAddWidget().getWidgetPosition()));

        // Share all information on already shared dashboard (i.e. widget
        // and filter)
        if (!dashboard.getAcl().getEntries().isEmpty() && widget.getAcl().getEntries().isEmpty()) {
            sharingService.modifySharing(Lists.newArrayList(dashboard), userName, projectName, true);
            additionalInfo.append("Widget '");
            additionalInfo.append(rq.getAddWidget().getWidgetId());
            additionalInfo.append("' has been shared for project cause shared dashboard.");
        }
    }

    // remove widget
    ofNullable(rq.getDeleteWidgetId()).ifPresent(it -> {
        expect(processWidgets(dashboard.getWidgets(), it, true), equalTo(true))
                .verify(WIDGET_NOT_FOUND_IN_DASHBOARD, it, dashboardId);
        Widget widget = widgetRepository.findOneLoadACL(it);
        if (null != widget && widget.getAcl().getOwnerUserId().equals(userName)) {
            try {
                widgetRepository.delete(it);
            } catch (Exception e) {
                throw new ReportPortalException("Error during deleting widget", e);
            }
        } else {
            Iterator<WidgetObject> iterator = dashboard.getWidgets().iterator();
            while (iterator.hasNext()) {
                if (iterator.next().getWidgetId().equals(it)) {
                    iterator.remove();
                    break;
                }
            }
        }
    });

    ofNullable(rq.getShare()).ifPresent(
            it -> sharingService.modifySharing(Lists.newArrayList(dashboard), userName, projectName, it));

    dashboardRepository.save(dashboard);

    eventPublisher.publishEvent(new DashboardUpdatedEvent(dashboard, rq, userName));
    return new OperationCompletionRS("Dashboard with ID = '" + dashboard.getId() + "' successfully updated."
            + additionalInfo.toString());
}

From source file:com.amazonaws.services.iot.client.shadow.AwsIotDeviceCommandManager.java

public void onDeactivate() {
    Iterator<Entry<String, AwsIotDeviceCommand>> it = pendingCommands.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, AwsIotDeviceCommand> entry = it.next();
        it.remove();

        final AwsIotDeviceCommand deviceCommand = entry.getValue();
        LOGGER.warning("Request was cancelled: " + deviceCommand.getCommand().name() + "/"
                + deviceCommand.getCommandId());
        device.getClient().scheduleTask(new Runnable() {
            @Override/*  w  w  w  . j  a  v a2 s .  c  o m*/
            public void run() {
                deviceCommand.onFailure();
            }
        });
    }
}

From source file:be.fedict.eid.idp.model.bean.AttributeServiceBean.java

@Override
public RPEntity setAttributes(RPEntity rp, List<String> attributes) {

    LOG.debug("set attributes: " + rp.getName());

    RPEntity attachedRp = this.entityManager.find(RPEntity.class, rp.getId());
    List<RPAttributeEntity> oldRpAttributes = attachedRp.getAttributes();

    // add new ones
    for (String attributeName : attributes) {

        boolean found = false;
        for (RPAttributeEntity oldRpAttribute : oldRpAttributes) {
            if (oldRpAttribute.getAttribute().getUri().equals(attributeName)) {
                // already in, ok
                found = true;/*w  w  w . j a  v a2 s.c o  m*/
                break;
            }
        }

        if (!found) {

            // new one
            AttributeEntity attribute = this.entityManager.find(AttributeEntity.class, attributeName);
            RPAttributeEntity rpAttribute = new RPAttributeEntity(attachedRp, attribute);
            this.entityManager.persist(rpAttribute);
            attachedRp.getAttributes().add(rpAttribute);
        }
    }

    // remove old ones
    Iterator<RPAttributeEntity> iter = attachedRp.getAttributes().iterator();
    while (iter.hasNext()) {
        RPAttributeEntity rpAttribute = iter.next();
        if (!attributes.contains(rpAttribute.getAttribute().getUri())) {
            // removed one
            iter.remove();
            this.entityManager.remove(rpAttribute);
        }
    }

    // HSQLDB issue, filter out doubles... ( TODO: ... )
    List<RPAttributeEntity> rpAttributes = new LinkedList<RPAttributeEntity>();
    for (RPAttributeEntity rpAttribute : attachedRp.getAttributes()) {
        if (!rpAttributes.contains(rpAttribute)) {
            rpAttributes.add(rpAttribute);
        }
    }
    attachedRp.setAttributes(rpAttributes);

    LOG.debug("attachedRP.attributes: " + attachedRp.getAttributes().size());

    return attachedRp;
}

From source file:com.epam.ta.reportportal.core.dashboard.impl.UpdateDashboardHandler.java

/**
 * Iterate over Widget's Set find widget with specified id and remove it if
 * required// w  ww. ja  v  a 2 s.  co m
 * 
 * @param widgets
 * @param searchingId
 * @param isRemove
 * @return isFound
 */
private boolean processWidgets(List<WidgetObject> widgets, String searchingId, boolean isRemove) {
    Iterator<WidgetObject> iterator = widgets.iterator();
    boolean isFound = false;
    while (iterator.hasNext()) {
        WidgetObject widget = iterator.next();
        if (widget.getWidgetId().equalsIgnoreCase(searchingId)) {
            if (isRemove) {
                iterator.remove();
            }
            isFound = true;
            break;
        }
    }
    return isFound;
}

From source file:at.beris.virtualfile.FileContext.java

private void disposeSiteUrlToClientMap() throws IOException {
    Iterator<Map.Entry<String, Client>> it = siteUrlToClientMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, Client> next = it.next();
        next.getValue().dispose();/* w ww  .j av  a 2  s  .co m*/
        it.remove();
    }
}

From source file:com.all.shared.model.TrackUtil.java

public void filterTracksWithoutMagnetLink(Iterable<Track> playlist) {
    Iterator<Track> trackIterator = playlist.iterator();
    while (trackIterator.hasNext()) {
        Track track = trackIterator.next();
        if (track.getDownloadString() == null) {
            log.warn("Track does not contain magnet link, removing it! " + track.getName());
            trackIterator.remove();
        }/*from w  w w. j a  va 2  s  .c  o m*/
    }
}

From source file:net.ripe.ipresource.IpResourceSet.java

public void add(IpResource resource) {
    Validate.notNull(resource, "resource is null");

    UniqueIpResource start = resource.getStart();
    if (!start.equals(start.getType().getMinimum())) {
        start = start.predecessor();//from  w  ww .j a  v  a 2 s .c o  m
    }

    IpResource resourceToAdd = normalize(resource);

    Iterator<IpResource> iterator = resourcesByEndPoint.tailMap(start, true).values().iterator();
    while (iterator.hasNext()) {
        IpResource potentialMatch = iterator.next();
        if (resourceToAdd.isMergeable(potentialMatch)) {
            iterator.remove();
            resourceToAdd = resourceToAdd.merge(potentialMatch);
        } else {
            break;
        }
    }

    IpResource normalized = normalize(resourceToAdd);
    resourcesByEndPoint.put(normalized.getEnd(), normalized);
}

From source file:be.ugent.maf.cellmissy.gui.controller.load.generic.singlecell.GenericSingleCellImagedPlateController.java

/**
 * Remove timeSteps from List: this is called when the user wants to
 * overwrite data or to clear data.//from   w ww.ja  v a2 s  . c o  m
 *
 * @param wellHasImagingTypeToOverwrite
 * @return
 */
public List<WellHasImagingType> removeOldDataFromList(WellHasImagingType wellHasImagingTypeToOverwrite) {
    List<WellHasImagingType> list = new ArrayList<>();
    Iterator<TrackPoint> iterator = trackPointsBindingList.iterator();
    while (iterator.hasNext()) {
        WellHasImagingType wellHasImagingType = iterator.next().getTrack().getWellHasImagingType();
        if (wellHasImagingType.equals(wellHasImagingTypeToOverwrite)) {
            list.add(wellHasImagingType);
            iterator.remove();
        }
    }
    return list;
}

From source file:ca.twoducks.vor.ossindex.report.ProjectConfig.java

/** Get a list of all CPE matches against the project.
 * // w  w w . j  a  va2 s.  c om
 * @return
 */
public Collection<String> getCpes() {
    if (cpes != null) {
        Iterator<String> it = cpes.iterator();
        while (it.hasNext()) {
            String cpe = it.next();
            if ("cpe:/none".equals(cpe))
                it.remove();
        }
        if (cpes.isEmpty())
            cpes = null;
    }
    return cpes;
}