Example usage for java.util List removeAll

List of usage examples for java.util List removeAll

Introduction

In this page you can find the example usage for java.util List removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this list all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:org.usd.edu.btl.betsconverter.BETSV1.BETSV1.java

/**
 * Combines this BETSV1 object with the param BETSV1 object. Only fills
 * empty fields and concatenates the lists. If both objects have a
 * particular field, keeps the original. If the field is a list and both
 * objects have that field, concatenates the lists.
 *
 * @param other//from  w w w . j  av  a 2s .  c  om
 * @return
 */
public BETSV1 combine(BETSV1 other) {
    if (other == null) {
        return this;
    }
    if (this.name == null || this.name.isEmpty()) {
        this.setName(other.getName());
    }
    if (this.display_name == null || this.display_name.isEmpty()) {
        this.setDisplay_name(other.getDisplay_name());
    }
    if (this.version == null || this.version.isEmpty()) {
        this.setVersion(other.getVersion());
    }
    if (this.summary == null || this.summary.isEmpty()) {
        this.setSummary(other.getSummary());
    }
    if (this.description == null || this.description.isEmpty()) {
        this.setDescription(other.getDescription());
    }
    if (this.limitations == null || this.limitations.isEmpty()) {
        this.setLimitations(other.getLimitations());
    }
    if (other.getExample() != null && other.getExample().size() > 0) {
        if (this.example == null) {
            this.example = new ArrayList<>();
        }
        this.example.removeAll(other.getExample());
        this.example.addAll(other.getExample());
    }
    if (other.getLinks() != null && other.getLinks().size() > 0) {
        if (this.links == null) {
            this.links = new ArrayList<>();
        }
        this.links.removeAll(other.getLinks());
        this.links.addAll(other.getLinks());
    }
    if (other.getReferences() != null && other.getReferences().size() > 0) {
        if (this.references == null) {
            this.references = new ArrayList<>();
        }
        this.references.removeAll(other.getReferences());
        this.references.addAll(other.getReferences());
    }
    if (this.author == null || this.author.isEmpty()) {
        this.setAuthor(other.getAuthor());
    }
    if (this.created_at == null || this.created_at.isEmpty()) {
        this.setCreated_at(other.getCreated_at());
    }
    if (this.owner == null || this.owner.isEmpty()) {
        this.setOwner(other.getOwner());
    }
    if (this.maintained == null || this.maintained.isEmpty()) {
        this.setMaintained(other.getMaintained());
    }
    if (other.getAvailability() != null && other.getAvailability().size() > 0) {
        if (this.availability == null) {
            this.availability = new ArrayList<>();
        }
        this.availability.removeAll(other.getAvailability());
        this.availability.addAll(other.getAvailability());
    }
    if (this.contact == null && other.getContact() != null) {
        this.contact = other.getContact();
    } else if (this.contact != null && other.getContact() != null) {
        if (this.contact.getName() == null || this.contact.getName().isEmpty()) {
            this.contact.setName(other.getContact().getName());
        }
        if (this.contact.getPhone() == null || this.contact.getPhone().isEmpty()) {
            this.contact.setPhone(other.getContact().getPhone());
        }
        if (this.contact.getEmail() == null || this.contact.getEmail().isEmpty()) {
            this.contact.setEmail(other.getContact().getPhone());
        }
        if (this.contact.getAddress() == null || this.contact.getAddress().isEmpty()) {
            this.contact.setAddress(other.getContact().getAddress());
        }
        if (this.contact.getInstitution() == null || this.contact.getInstitution().isEmpty()) {
            this.contact.setInstitution(other.getContact().getInstitution());
        }
    }
    if (this.category == null && other.getCategory() != null) {
        this.category = other.getCategory();
    } else if (this.category != null && other.getCategory() != null) {
        if (this.category.getId() == null || this.category.getId().isEmpty()) {
            this.category.setId(other.getCategory().getId());
        }
        if (this.category.getName() == null || this.category.getName().isEmpty()) {
            this.category.setName(other.getCategory().getName());
        }
        if (this.category.getPath() == null || this.category.getPath().isEmpty()) {
            this.category.setPath(other.getCategory().getPath());
        }
        if (other.category.getApplication() != null || other.category.getApplication().size() > 0) {
            List<Application> temp = new ArrayList<>();
            if (this.category.getApplication() == null) {
                temp = other.category.getApplication();
            } else {
                temp = new ArrayList<>();
                temp.addAll(this.category.getApplication());
                temp.removeAll(other.category.getApplication());
                temp.addAll(other.category.getApplication());
            }
            this.category.setApplication(temp);
        }
        if (other.category.getDomain() != null || other.category.getDomain().size() > 0) {
            List<Domain> temp = new ArrayList<>();
            if (this.category.getDomain() == null) {
                temp = other.category.getDomain();
            } else {
                temp = new ArrayList<>();
                temp.addAll(this.category.getDomain());
                temp.removeAll(other.category.getDomain());
                temp.addAll(other.category.getDomain());
            }
            this.category.setDomain(temp);
        }
        if (other.category.getMethod() != null || other.category.getMethod().size() > 0) {
            List<Method> temp = new ArrayList<>();
            if (this.category.getMethod() == null) {
                temp = other.category.getMethod();
            } else {
                temp = new ArrayList<>();
                temp.addAll(this.category.getMethod());
                temp.removeAll(other.category.getMethod());
                temp.addAll(other.category.getMethod());
            }
            this.category.setMethod(temp);
        }
        if (other.category.getTags() != null || other.category.getTags().size() > 0) {
            List<String> temp = new ArrayList<>();
            if (this.category.getTags() == null) {
                temp = other.category.getTags();
            } else {
                temp = new ArrayList<>();
                temp.addAll(this.category.getTags());
                temp.removeAll(other.category.getTags());
                temp.addAll(other.category.getTags());
            }
            this.category.setTags(temp);
        }
        if (other.category.getFormat() != null && this.category.getFormat() == null) {
            this.category.setFormat(other.category.getFormat());
        }
        if (other.category.getNgs_provider() != null && this.category.getNgs_provider() == null) {
            this.category.setNgs_provider(other.category.getNgs_provider());
        }
        if (other.category.getSequence_platform() != null && this.category.getSequence_platform() == null) {
            this.category.setSequence_platform(other.category.getSequence_platform());
        }
        if (other.category.getReference() != null && this.category.getReference() == null) {
            this.category.setReference(other.category.getReference());
        }
    }
    if (other.getTechnology() != null && other.getTechnology().size() > 0) {
        if (this.technology == null) {
            this.technology = new ArrayList<>();
        }
        this.technology.removeAll(other.getTechnology());
        this.technology.addAll(other.getTechnology());
    }
    if (other.getProgramming_language() != null && other.getTechnology().size() > 0) {
        if (this.programming_language == null) {
            this.programming_language = new ArrayList<>();
        }
        this.programming_language.removeAll(other.getProgramming_language());
        this.programming_language.addAll(other.getProgramming_language());
    }
    if (other.getLicense() != null && other.getLicense().size() > 0) {
        if (this.license == null) {
            this.license = new ArrayList<>();
        }
        this.license.removeAll(other.getLicense());
        this.license.addAll(other.getLicense());
    }
    if (other.getOperating_system() != null && other.getOperating_system().size() > 0) {
        if (this.operating_system == null) {
            this.operating_system = new ArrayList<>();
        }
        this.operating_system.removeAll(other.getOperating_system());
        this.operating_system.addAll(other.getOperating_system());
    }
    if (this.software_features == null || this.software_features.isEmpty()) {
        this.setSoftware_features(other.getSoftware_features());
    }
    if (this.software_libraries == null || this.software_libraries.isEmpty()) {
        this.setSoftware_libraries(other.getSoftware_libraries());
    }
    if (other.getInputs() != null && other.getInputs().size() > 0) {
        if (this.inputs == null) {
            this.inputs = new ArrayList<>();
        }
        this.inputs.removeAll(other.getInputs());
        this.inputs.addAll(other.getInputs());
    }
    if (other.getParameters() != null && other.getParameters().size() > 0) {
        if (this.parameters == null) {
            this.parameters = new ArrayList<>();
        }
        this.parameters.removeAll(other.getParameters());
        this.parameters.addAll(other.getParameters());
    }
    if (other.getOutputs() != null && other.getOutputs().size() > 0) {
        if (this.outputs == null) {
            this.outputs = new ArrayList<>();
        }
        this.outputs.removeAll(other.getOutputs());
        this.outputs.addAll(other.getOutputs());
    }
    if (this.requirements == null || this.requirements.isEmpty()) {
        this.setRequirements(other.getRequirements());
    }
    if (other.getQuality() != null && other.getQuality().size() > 0) {
        if (this.quality == null) {
            this.quality = new ArrayList<>();
        }
        this.quality.removeAll(other.getQuality());
        this.quality.addAll(other.getQuality());
    }
    if (other.getLearn_flow() != null && other.getLearn_flow().size() > 0) {
        if (this.learn_flow == null) {
            this.learn_flow = new ArrayList<>();
        }
        this.learn_flow.removeAll(other.getLearn_flow());
        this.learn_flow.addAll(other.getLearn_flow());
    }
    if (this.release_date == null || this.release_date.isEmpty()) {
        this.setRelease_date(other.getRelease_date());
    }
    if (other.getAlgorithm() != null && other.getAlgorithm().size() > 0) {
        if (this.algorithm == null) {
            this.algorithm = new ArrayList<>();
        }
        this.algorithm.removeAll(other.getAlgorithm());
        this.algorithm.addAll(other.getAlgorithm());
    }
    if (this.validation_date == null || this.validation_date.isEmpty()) {
        this.setValidation_date(other.getValidation_date());
    }
    if (other.getNature_of_tool() != null && other.getNature_of_tool().size() > 0) {
        if (this.nature_of_tool == null) {
            this.nature_of_tool = new ArrayList<>();
        }
        this.nature_of_tool.removeAll(other.getNature_of_tool());
        this.nature_of_tool.addAll(other.getNature_of_tool());
    }
    if (other.getTool_type() != null && other.getTool_type().size() > 0) {
        if (this.tool_type == null) {
            this.tool_type = new ArrayList<>();
        }
        this.tool_type.removeAll(other.getTool_type());
        this.tool_type.addAll(other.getTool_type());
    }
    if (other.getInterfaces() != null && other.getInterfaces().size() > 0) {
        if (this.interfaces == null) {
            this.interfaces = new ArrayList<>();
        }
        this.interfaces.removeAll(other.getInterfaces());
        this.interfaces.addAll(other.getInterfaces());
    }
    if (this.parallelism == null || this.parallelism.isEmpty()) {
        this.setParallelism(other.getParallelism());
    }
    if (other.getIplant_specific() != null) {
        this.setIplant_specific(other.getIplant_specific());
    }
    if (other.getSeq_specific() != null) {
        this.setSeq_specific(other.getSeq_specific());
    }
    if (other.getGalaxy_specific() != null) {
        this.setGalaxy_specific(other.getGalaxy_specific());
    }
    if (other.getBld_specific() != null) {
        this.setBld_specific(other.getBld_specific());
    }
    if (other.getOmic_specific() != null) {
        this.setOmic_specific(other.getOmic_specific());
    }
    return this;
}

From source file:com.thoughtworks.go.config.BasicCruiseConfig.java

@Override
public List<ConfigErrors> getAllErrorsExceptFor(Validatable skipValidatable) {
    List<ConfigErrors> all = getAllErrors();
    if (skipValidatable != null) {
        all.removeAll(ErrorCollector.getAllErrors(skipValidatable));
    }/*from ww w  .  j a v  a 2 s  .c o  m*/
    return all;
}

From source file:com.dell.asm.asmcore.asmmanager.tasks.ServiceDeploymentJob.java

@Override
protected void executeSafely(JobExecutionContext context) {
    logger.info("Executing ServiceDeploymentJob's executeServiceDeployment method!");
    List<DeviceInventoryEntity> uncomplyingDevices = null;
    FirmwareRepositoryEntity firmwareRepository = null;
    try {/*from  ww w.  j a  va2s .c  o  m*/
        // Initialize member data from Job context
        initializeServiceDeploymentJob(context);

        setJobStatus(JobStatus.IN_PROGRESS);

        // need to clean up template for deployment
        ServiceTemplate serviceTemplate = getCurrentJobDeployment().getServiceTemplate();
        if (serviceTemplate == null) {
            throw new AsmManagerRuntimeException(
                    "No service template for deployment " + getCurrentJobDeployment().getId());
        }

        ServiceDeploymentUtil.prepareTemplateForDeployment(serviceTemplate);

        DeploymentEntity deploymentEntity = getDeploymentDAO().getDeployment(getCurrentJobDeployment().getId(),
                DEVICE_INVENTORY_ENTITIES + FIRMWARE_REPOSITORY_ENTITY);

        // Must capture the DeploymentInventoryEntity here, before modifications in order to update their compliance
        // properly at the end of the run (in case of a teardown of the deployment).  Once teardown is complete
        // and the Deployment is removed, there will be no way to determine the devices that were part of it.
        List<DeviceInventoryEntity> devInvEntityList = new ArrayList<>(deploymentEntity.getDeployedDevices());

        // Sets initial state of the compliance so the Deployment's compliance is represented properly during job run
        if (deploymentEntity.getFirmwareRepositoryEntity() != null) {
            // Assumes compliance_map table is in a proper state
            getServiceDeploymentUtil().runServiceComplianceCheck(deploymentEntity, true);
        }

        try { // Brownfield Deployments should not initiate Firmware Upgrades
            if (!getCurrentJobDeployment().isTeardown() && !getCurrentJobDeployment().isBrownfield()
                    && deploymentEntity.getFirmwareRepositoryEntity() != null) {
                firmwareRepository = getFirmwareRepositoryDAO()
                        .get(deploymentEntity.getFirmwareRepositoryEntity().getId());
                // Get devices we should update firmware on
                uncomplyingDevices = this.getFirmwareUpdateDevicesInDeployment(firmwareRepository,
                        getCurrentJobDeployment(), DriverType.FIRMWARE);
            }
        } catch (AsmManagerCheckedException e) {
            logger.error("Exception seen while generating firmware for template", e);
        }

        // Give repository time to settle into an available state
        if (firmwareRepository != null) {
            waitForRepositoryQuiescence(firmwareRepository);
        }

        // Create Firmware Jobs and wait for them to finish
        if (uncomplyingDevices != null && uncomplyingDevices.size() > 0 && firmwareRepository != null) {
            createAndRunFirmwareNoOpJob();
            createAndRunFirmwareUpdateJobs(uncomplyingDevices, FirmwareUpdateJob.COMPONENTS_FIRMWARE,
                    firmwareRepository, FirmwareUpdateJob.UPDATE_TYPE_DEPLOYMENT_DEVICE);

            // Recompute the list of devices that need updated.
            // This list should now contain 0 devices if all firmware updates were effective.
            uncomplyingDevices = this.getFirmwareUpdateDevicesInDeployment(firmwareRepository,
                    getCurrentJobDeployment(), DriverType.FIRMWARE);
            getCurrentJobDeployment().setRetry(true);
        }

        if (uncomplyingDevices != null && !uncomplyingDevices.isEmpty()) {
            logger.warn(uncomplyingDevices.size()
                    + " uncomplying devices were found after running Firmware Updates!");
            logger.warn("After Firmware updates device with refid " + uncomplyingDevices.get(0).getRefId()
                    + " is still non-compliant!");

            // Update the Server's Software inventory compliance as it's only updated on an InventoryJob run otherwise
            deploymentEntity = this.getDeploymentDAO().getDeployment(getCurrentJobDeployment().getId(),
                    DEVICE_INVENTORY_ENTITIES + FIRMWARE_REPOSITORY_ENTITY);
            getFirmwareUtil().updateServersSoftwareDeviceInventory(deploymentEntity);
            this.getServiceDeploymentUtil().runServiceComplianceCheck(deploymentEntity, true);

            // Check that devices states reflect firmware update failed
            for (DeviceInventoryEntity currDevice : uncomplyingDevices) {
                if (!DeviceState.UPDATE_FAILED.equals(currDevice.getState())) {
                    updateDeviceSafelyWithRetries(currDevice, DeviceState.UPDATE_FAILED);
                    logger.warn("Expected device state to be UPDATE_FAILED");
                }
            }
        }

        // Attempt to do the deployment regardless of firmware updates success or failures
        deploymentEntity = executeRazorDeployment(getCurrentJobDeployment(), uncomplyingDevices);

        // Must save the last known state so we can set it once Software updates are complete
        DeploymentStatusType lastDeploymentStatus = DeploymentStatusType.ERROR;
        if (deploymentEntity != null) {
            lastDeploymentStatus = deploymentEntity.getStatus(); // Will be Complete or Error
        }

        // Update the Deployment Status to complete again now that software updates are finished
        deploymentEntity = this.getDeploymentDAO().getDeployment(getCurrentJobDeployment().getId(),
                DEVICE_INVENTORY_ENTITIES + FIRMWARE_REPOSITORY_ENTITY);

        if (deploymentEntity != null) {
            if (getCurrentJobDeployment().isTeardown() || getCurrentJobDeployment().isIndividualTeardown()) { // It's a teardown of an individual component
                List<DeviceInventoryEntity> dies = this.getRemovedDeploymentEntity(devInvEntityList,
                        new ArrayList<>(deploymentEntity.getDeployedDevices()));
                if (dies != null && !dies.isEmpty()) {
                    ArrayList<DeviceInventoryEntity> diesRemoved = new ArrayList<>();
                    for (DeviceInventoryEntity die : dies) {
                        this.getDeviceInventoryDAO()
                                .deleteFirmwareDeviceInventoryForDeviceWithOperatingSystem(die.getRefId());
                        DeviceInventoryEntity freshDie = getDeviceInventoryDAO()
                                .getDeviceInventory(die.getRefId());
                        diesRemoved.add(freshDie);
                    }
                    this.getFirmwareUtil().updateComplianceMapsAndDeviceInventoryCompliance(diesRemoved);
                }
            } else { // It's a software update
                this.runSoftwareUpdates(serviceTemplate, firmwareRepository);
            }

            // Running software updates changes the deploymentEntity,  must reload or there will be a stale
            // Hibernate exception here
            deploymentEntity = this.getDeploymentDAO().getDeployment(getCurrentJobDeployment().getId(),
                    DEVICE_INVENTORY_ENTITIES + FIRMWARE_REPOSITORY_ENTITY);

            deploymentEntity.setStatus(lastDeploymentStatus);
            getDeploymentDAO().updateDeployment(deploymentEntity);

            // Regardless of whether everything is compliant run check for deployment one last time & update status
            // Make sure the software inventory is up to date
            this.getFirmwareUtil().updateServersSoftwareDeviceInventory(deploymentEntity);
            // Make sure the compliance map is recalculated after updating the software inventory
            this.getFirmwareUtil().updateComplianceMapsAndDeviceInventoryCompliance(
                    new ArrayList<>(deploymentEntity.getDeployedDevices()));
            // Make sure the deployment compliance is updated after updating the device compliances
            this.getServiceDeploymentUtil().runServiceComplianceCheck(deploymentEntity, true);
        } else { // If it's a teardown of the deployment which was deleted, need to update the devices with the devices with default/embedded
            ArrayList<DeviceInventoryEntity> diesRemoved = new ArrayList<>();
            for (DeviceInventoryEntity die : devInvEntityList) { // Remove the software inventory for all devices
                this.getDeviceInventoryDAO()
                        .deleteFirmwareDeviceInventoryForDeviceWithOperatingSystem(die.getRefId());
                DeviceInventoryEntity freshDie = getDeviceInventoryDAO().getDeviceInventory(die.getRefId());
                diesRemoved.add(freshDie);
            }
            this.getFirmwareUtil().updateComplianceMapsAndDeviceInventoryCompliance(diesRemoved);
        }
    } catch (Exception e) {
        logger.fatal("Unexpected exception while executing ServiceDeploymentJob!", e);
        setDeploymentFailed(DeploymentStatusType.ERROR);

        // Also need to set the status for devices that succeeded firmware update
        List<DeviceInventoryEntity> servers = getServersInDeployment();
        if (servers != null && servers.size() > 0) {
            if (uncomplyingDevices != null && uncomplyingDevices.size() > 0) {
                servers.removeAll(uncomplyingDevices);
            }
            for (DeviceInventoryEntity server : servers) {
                updateDeviceSafelyWithRetries(server, DeviceState.READY);
            }
        }
        setJobStatus(JobStatus.FAILED);
    } finally {
        logger.info("ServiceDeploymentJob has completed for " + this.getJobName());
    }
}

From source file:com.cloudbees.hudson.plugins.folder.AbstractFolder.java

/**
 * Add an action, replacing any existing actions of the (exact) same class.
 * Note: calls to {@link #getAllActions()} that happen before calls to this method may not see the update.
 * Note: this method does not affect transient actions contributed by a {@link TransientActionFactory}
 *
 * @param a an action to add/replace//w ww  . j  a  va 2 s.  c  o  m
 * @return {@code true} if this actions changed as a result of the call
 * @since FIXME
 */
// TODO remove once baseline has JENKINS-39404
@SuppressWarnings({ "ConstantConditions", "deprecation" })
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
public boolean addOrReplaceAction(@Nonnull Action a) {
    if (a == null) {
        throw new IllegalArgumentException("Action must be non-null");
    }
    // CopyOnWriteArrayList does not support Iterator.remove, so need to do it this way:
    List<Action> old = new ArrayList<Action>(1);
    List<Action> current = super.getActions();
    boolean found = false;
    for (Action a2 : current) {
        if (!found && a.equals(a2)) {
            found = true;
        } else if (a2.getClass() == a.getClass()) {
            old.add(a2);
        }
    }
    current.removeAll(old);
    if (!found) {
        addAction(a);
    }
    return !found || !old.isEmpty();
}

From source file:com.flexive.war.beans.admin.content.BeContentEditorBean.java

/**
 * Returns FxDeltas between two selected versions.
 *
 * @return FxDeltas between two selected versions
 *///from  w w  w  .  j  a  va  2 s.  com
public List<FxDelta.FxDeltaChange> getCompareEntries() {
    List<FxDelta.FxDeltaChange> emptyResult = new ArrayList<FxDelta.FxDeltaChange>(0);
    try {
        final ContentEngine ce = EJBLookup.getContentEngine();
        FxContentVersionInfo versionInfo = pk.isNew() ? FxContentVersionInfo.createEmpty()
                : ce.getContentVersionInfo(pk);
        if ("compare".equals(infoPanelState) && compareSourceVersion > 0
                && compareSourceVersion <= versionInfo.getMaxVersion() && compareDestinationVersion > 0
                && compareDestinationVersion <= versionInfo.getMaxVersion()) {
            FxContent content1 = ce.load(new FxPK(getId(), compareSourceVersion));
            FxContent content2 = ce.load(new FxPK(getId(), compareDestinationVersion));
            FxDelta delta = FxDelta.processDelta(content1, content2);
            List<FxDelta.FxDeltaChange> changes = delta.getDiff(content1, content2);
            //filter internal
            List<FxDelta.FxDeltaChange> internal = new ArrayList<FxDelta.FxDeltaChange>(5);
            for (FxDelta.FxDeltaChange d : changes)
                if (d.isInternal())
                    internal.add(d);
            changes.removeAll(internal);
            return changes;
        } else {
            return emptyResult;
        }
    } catch (FxApplicationException e) {
        new FxFacesMsgErr(e).addToContext();
        return emptyResult;
    }
}

From source file:com.idega.bedework.bussiness.impl.BedeworkCalendarServiceBean.java

@Override
public List<CalDAVCalendar> getUnSubscribedCalendars(User user, Integer maxResults, Integer firstResult) {
    if (user == null) {
        return null;
    }//w  w  w.j av  a 2 s.  c o m

    List<CalDAVCalendar> visibleCalendars = getVisibleSubscriptions(user, maxResults, firstResult);
    if (visibleCalendars == null) {
        return null;
    }

    List<CalDAVCalendar> subscribedCalendars = getSubscribedCalendars(user, maxResults, firstResult);
    if (ListUtil.isEmpty(subscribedCalendars)) {
        return visibleCalendars;
    }

    if (visibleCalendars.removeAll(subscribedCalendars)) {
        return visibleCalendars;
    }

    return null;
}

From source file:com.cloudbees.hudson.plugins.folder.AbstractFolder.java

/**
 * Replaces any actions of the specified type by the supplied action.
 * Note: calls to {@link #getAllActions()} that happen before calls to this method may not see the update.
 * Note: this method does not affect transient actions contributed by a {@link TransientActionFactory}
 *
 * @param clazz the type of actions to replace (note that the action you are replacing this with need not extend
 *              this class)/*  w w w . ja v a  2 s  .com*/
 * @param a     the action to replace with
 * @return {@code true} if this actions changed as a result of the call
 * @since FIXME
 */
// TODO remove once baseline has JENKINS-39404
@SuppressWarnings({ "ConstantConditions", "deprecation" })
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
public boolean replaceActions(@Nonnull Class<? extends Action> clazz, Action a) {
    if (clazz == null) {
        throw new IllegalArgumentException("Action type must be non-null");
    }
    if (a == null) {
        throw new IllegalArgumentException("Action must be non-null");
    }
    // CopyOnWriteArrayList does not support Iterator.remove, so need to do it this way:
    List<Action> old = new ArrayList<Action>();
    List<Action> current = super.getActions();
    boolean found = false;
    for (Action a1 : current) {
        if (!found && a.equals(a1)) {
            found = true;
        } else if (clazz.isInstance(a1) && !a.equals(a1)) {
            old.add(a1);
        }
    }
    current.removeAll(old);
    if (!found) {
        addAction(a);
    }
    return !(old.isEmpty() && found);
}

From source file:com.parse.OfflineStore.java

private <T extends ParseObject> Task<Void> unpinAllObjectsAsync(String name, final List<T> objects,
        final ParseSQLiteDatabase db) {
    if (objects == null || objects.size() == 0) {
        return Task.forResult(null);
    }/*from  w  w  w  .j  a  va2 s  .co m*/

    return getParsePin(name, db).onSuccessTask(new Continuation<ParsePin, Task<Void>>() {
        @Override
        public Task<Void> then(Task<ParsePin> task) throws Exception {
            ParsePin pin = task.getResult();

            //TODO (grantland): change to use relations. currently the related PO are only getting saved
            // offline as pointers.
            //        ParseRelation<ParseObject> relation = pin.getRelation(KEY_OBJECTS);
            //        relation.remove(object);

            // Hack to store collections in a pin
            List<ParseObject> modified = pin.getObjects();
            if (modified == null) {
                // Unpin a pin that doesn't exist. Wat?
                return Task.forResult(null);
            }

            modified.removeAll(objects);
            if (modified.size() == 0) {
                return unpinAsync(pin, db);
            }
            pin.setObjects(modified);

            return saveLocallyAsync(pin, true, db);
        }
    });
}

From source file:ait.ffma.service.preservation.riskmanagement.TestLODFreebaseRetrieve.java

/**
 * This method merges string arrays to one string array
 * @param existingValues/*from w  ww.ja  va2s.co  m*/
 * @param newValues
 * @return
 */
private String[] addArrays(String[] existingValues, String[] newValues) {
    List<String> existingIds = Arrays.asList(existingValues);
    List<String> newIds = Arrays.asList(newValues);
    List<String> idList = new ArrayList<String>();
    idList.addAll(existingIds);
    idList.addAll(newIds);
    List<String> emptyStrings = new ArrayList<String>();
    emptyStrings.add(" ");
    idList.removeAll(emptyStrings);
    return idList.toArray(new String[] {});
}