Example usage for java.util Set remove

List of usage examples for java.util Set remove

Introduction

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

Prototype

boolean remove(Object o);

Source Link

Document

Removes the specified element from this set if it is present (optional operation).

Usage

From source file:com.employee.scheduler.nurserostering.swingui.NurseRosteringPanel.java

@Override
public void updatePanel(Solution solution) {
    NurseRoster nurseRoster = (NurseRoster) solution;
    List<ShiftDate> shiftDateList = nurseRoster.getShiftDateList();
    List<Shift> shiftList = nurseRoster.getShiftList();
    Set<Employee> deadEmployeeSet = new LinkedHashSet<Employee>(employeeToPanelMap.keySet());
    deadEmployeeSet.remove(null);
    for (Employee employee : nurseRoster.getEmployeeList()) {
        deadEmployeeSet.remove(employee);
        EmployeePanel employeePanel = employeeToPanelMap.get(employee);
        if (employeePanel == null) {
            employeePanel = new EmployeePanel(this, shiftDateList, shiftList, employee);
            employeeListPanel.add(employeePanel);
            employeeToPanelMap.put(employee, employeePanel);
        }/* www . j a  va 2s.  c om*/
        employeePanel.clearShiftAssignments();
    }
    unassignedPanel.clearShiftAssignments();
    for (ShiftAssignment shiftAssignment : nurseRoster.getShiftAssignmentList()) {
        Employee employee = shiftAssignment.getEmployee();
        EmployeePanel employeePanel = employeeToPanelMap.get(employee);
        employeePanel.addShiftAssignment(shiftAssignment);
    }
    for (Employee deadEmployee : deadEmployeeSet) {
        EmployeePanel deadEmployeePanel = employeeToPanelMap.remove(deadEmployee);
        employeeListPanel.remove(deadEmployeePanel);
    }
    for (EmployeePanel employeePanel : employeeToPanelMap.values()) {
        employeePanel.update();
    }
}

From source file:de.uni_rostock.goodod.owl.normalization.SubsumptionMaterializationNormalizer.java

private void cleanClassHierarchy() {
    Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF, true);
    for (OWLSubClassOfAxiom ax : axioms) {

        OWLClassExpression subEx = ax.getSubClass();
        OWLClassExpression superEx = ax.getSuperClass();

        // Consider only named classes
        if ((subEx instanceof OWLClass) && (superEx instanceof OWLClass)) {

            /*/*from w  w w .j a v  a 2  s .c om*/
             * Get the subclasses of the superclass and the
             * superclasses of the subclass. If the resulting sets
             * share a member (modulo the classes in the axiom), the subclass
             * relation is entailed by transitivity alone and we can safely
             * remove the axiom.
             */
            Set<OWLClass> subs = transitiveSuperClasses(subEx.asOWLClass());
            Set<OWLClass> supers = transitiveSubClasses(superEx.asOWLClass());
            subs.remove(superEx);
            supers.remove(subEx);
            if (false == Collections.disjoint(subs, supers)) {
                changes.add(new RemoveAxiom(ontology, ax));
            }
        }

        /*
         * Special-case: If the superclass has "Test" (case-insensitively)
         * as its fragment, remove the axiom.
         */
        if (superEx instanceof OWLClass) {
            IRI superIRI = ((OWLClass) superEx).getIRI();
            String fragment = superIRI.getFragment();
            if (fragment.equalsIgnoreCase("TEST")) {
                RemoveAxiom removeAx = new RemoveAxiom(ontology, ax);
                if (false == changes.contains(removeAx)) {
                    changes.add(removeAx);
                }
            }
        }
    }

    logger.debug("Removed " + changes.size() + " redundant subsumptions.");
    commitChanges();
}

From source file:be.fgov.kszbcss.rhq.websphere.WebSphereServerPlugin.java

/**
 * auto inventory resources in two phases
 * //w w  w.  ja v a  2  s  .  co  m
 * The sweep phase uninventories all resources which are tagged as 'unconfigured' for a certain time. The mark phase
 * checks for all unavailable resources if they're still configured and adds the 'unconfigured' tag if so.
 * 
 * @param invocation
 *            job context
 */
public void autoUninventory(ScheduledJobInvocationContext invocation) {
    try {
        Subject user = LookupUtil.getSubjectManager().getOverlord();
        TagManagerLocal tagManager = LookupUtil.getTagManager();
        ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();

        int uninventoryDelay = Integer
                .parseInt(invocation.getJobDefinition().getCallbackData().getProperty("uninventoryDelay"));

        // addTags either creates a new tag or returns an existing tag
        Tag unconfiguredTag = tagManager
                .addTags(user, Collections.singleton(new Tag("websphere", null, "unconfigured"))).iterator()
                .next();

        // Resources to check
        LinkedList<Resource> resources = new LinkedList<Resource>();

        // Sweep - search resources that can be uninventoried
        ResourceCriteria resourceCriteria = new ResourceCriteria();
        resourceCriteria.addFilterCurrentAvailability(AvailabilityType.DISABLED);
        resourceCriteria.addFilterTag(unconfiguredTag);
        resourceCriteria.fetchTags(true);
        resourceCriteria.setPageControl(PageControl.getUnlimitedInstance());
        PageList<Resource> resourcePageList = resourceManager.findResourcesByCriteria(user, resourceCriteria);
        for (Resource resource : resourcePageList) {
            ResourceAvailabilitySummary availability = resourceManager.getAvailabilitySummary(user,
                    resource.getId());
            if ((System.currentTimeMillis() - availability.getLastChange().getTime())
                    / 60000 > uninventoryDelay) {
                LOG.debug("Removing unconfigured tag from resource " + resource.getName() + " ("
                        + resource.getId() + ") to work around an issue in RHQ 4.5.1");
                Set<Tag> tags = resource.getTags();
                tags.remove(unconfiguredTag);
                tagManager.updateResourceTags(user, resource.getId(), tags);
                LOG.info("About to uninventory " + resource.getName() + " (" + resource.getId() + ")");
                resourceManager.uninventoryResources(user, new int[] { resource.getId() });
            } else {
                LOG.debug("Resource " + resource.getName() + " (" + resource.getId()
                        + ") is tagged as unconfigured; force configuration check");
                resources.add(resource);
            }
        }

        // Search for WebSphere resources that are down and check if they have been unconfigured
        // AvailabilityType.MISSING results seems to have been converted to DOWN at this point
        resourceCriteria = new ResourceCriteria();
        resourceCriteria.addFilterCurrentAvailability(AvailabilityType.DOWN);
        resourceCriteria.addFilterPluginName("WebSphere");
        resourceCriteria.fetchParentResource(true);
        resourceCriteria.fetchTags(true);
        resourceCriteria.setPageControl(PageControl.getUnlimitedInstance());
        resourcePageList = resourceManager.findResourcesByCriteria(user, resourceCriteria);
        for (Resource resource : resourcePageList) {
            if (!resourcePageList.contains(resource.getParentResource())) {
                resources.add(resource);
            }
        }

        // check and mark - for all resources that were already marked as unconfigured and for the unavailable resources
        checkAndMarkUnconfiguredResources(resources, unconfiguredTag);
    } catch (RuntimeException e) {
        // need to catch all exceptions here because letting the exception pass will unschedule the job forevermore
        LOG.error("Exception during autoUninventory of resources", e);
    }
}

From source file:com.mnxfst.testing.server.cfg.PTestServerConfiguration.java

/**
 * Adds a specific key/value pair to the selected context handler
 * //ww  w  .  j  a  v a 2  s.  co m
 * @param ctxHandler
 * @param keyValue
 */
public void addContextHandlerSetting(String ctxPath, NameValuePair keyValue) {

    Set<NameValuePair> settings = contextHandlerSettings.get(ctxPath);
    if (settings == null)
        settings = new HashSet<NameValuePair>();

    // ensure entry replacement since the add method just does nothing if the value is already contained 
    settings.remove(keyValue);
    settings.add(keyValue);
    contextHandlerSettings.put(ctxPath, settings);
}

From source file:io.minio.policy.Statement.java

private void removeReadOnlyBucketActions(String prefix) {
    if (!this.actions.containsAll(Constants.READ_ONLY_BUCKET_ACTIONS)) {
        return;// www.  ja v a 2s  . c  om
    }

    this.actions.removeAll(Constants.READ_ONLY_BUCKET_ACTIONS);

    if (this.conditions == null) {
        return;
    }

    if (prefix == null || prefix.isEmpty()) {
        return;
    }

    ConditionKeyMap stringEqualsValue = this.conditions.get("StringEquals");
    if (stringEqualsValue == null) {
        return;
    }

    Set<String> values = stringEqualsValue.get("s3:prefix");
    if (values != null) {
        values.remove(prefix);
    }

    if (values == null || values.isEmpty()) {
        stringEqualsValue.remove("s3:prefix");
    }

    if (stringEqualsValue.isEmpty()) {
        this.conditions.remove("StringEquals");
    }

    if (this.conditions.isEmpty()) {
        this.conditions = null;
    }
}

From source file:net.sbbi.upnp.DiscoveryListener.java

/**
 * Unregisters an SSDP response message handler
 * @param resultsHandler the SSDP response message handler
 * @param searchTarget the search target
 *///  www  .j a  va  2 s. c  o  m
public void unRegisterResultsHandler(DiscoveryResultsHandler resultsHandler, String searchTarget) {
    synchronized (REGISTRATION_PROCESS) {
        Set handlers = (Set) registeredHandlers.get(searchTarget);
        if (handlers != null) {
            handlers.remove(resultsHandler);
            if (handlers.size() == 0) {
                registeredHandlers.remove(searchTarget);
            }
        }
        if (registeredHandlers.size() == 0) {
            stopDevicesListenerThread();
        }
    }
}

From source file:org.mashupmedia.controller.configuration.EditUserController.java

protected void processAdministratorRole(EditUserPage editUserPage) {
    boolean isAdministrator = editUserPage.isAdministrator();
    User user = editUserPage.getUser();//w  w  w. ja v a  2  s .c o m

    Role administrationRole = adminManager.getRole(AdminHelper.ROLE_ADMIN_IDNAME);
    Set<Role> roles = user.getRoles();
    if (roles == null) {
        roles = new HashSet<Role>();
    }

    if (isAdministrator) {
        roles.add(administrationRole);
    } else {
        roles.remove(administrationRole);
    }

    user.setRoles(roles);
}

From source file:de.hybris.platform.b2bacceleratorfacades.company.impl.DefaultB2BCommerceCostCenterFacade.java

@Override
public B2BSelectionData deSelectBudgetForCostCenter(final String costCenterCode, final String budgetCode)
        throws DuplicateUidException {
    final B2BCostCenterModel b2BCostCenterModel = getB2BCommerceCostCenterService()
            .getCostCenterForCode(costCenterCode);
    final Set<B2BBudgetModel> budgetModelSet = new HashSet<B2BBudgetModel>(b2BCostCenterModel.getBudgets());
    final B2BBudgetModel b2BBudgetModel = getB2BCommerceBudgetService().getBudgetModelForCode(budgetCode);
    if (b2BBudgetModel != null) {
        budgetModelSet.remove(b2BBudgetModel);
    }//from   w  w w .jav a 2s .  c o m

    b2BCostCenterModel.setBudgets(budgetModelSet);
    getCompanyB2BCommerceService().saveModel(b2BCostCenterModel);

    if (b2BBudgetModel != null) {
        return createB2BSelectionData(b2BBudgetModel.getCode(), false,
                b2BBudgetModel.getActive().booleanValue());
    }

    throw new IllegalStateException("The b2BBudgetModel must be found in the system");
}

From source file:edu.ku.brc.specify.datamodel.DataModelObjBase.java

/**
 * @param dataObject//from  ww  w  . j  a  v a  2s  . c  o  m
 * @param fieldName
 * @param ref
 * @return
 */
public static boolean removeFromCollectionById(final Object dataObject, final String fieldName,
        final FormDataObjIFace ref) {
    if (ref.getId() != null) {
        try {
            DataObjectGettable getter = DataObjectGettableFactory.get(dataObject.getClass().getName(),
                    FormHelper.DATA_OBJ_GETTER);
            Object dataMember = getter.getFieldValue(dataObject, fieldName);
            if (dataMember != null && dataMember instanceof Set<?>) {
                Set<?> dataSet = (Set<?>) dataMember;
                for (Object obj : dataSet) {
                    if (obj instanceof DataModelObjBase) {
                        Integer id1 = ((DataModelObjBase) ref).getId();
                        Integer id2 = ref.getId();
                        if (id2 != null && id1.equals(id2)) {
                            dataSet.remove(ref);
                            return true;
                        }
                    }
                }
            }
        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex);
            ex.printStackTrace();
        }
    }
    return false;
}

From source file:org.openscore.lang.compiler.modeller.transformers.Java_ActionTransformer.java

@Override
public Map<String, String> transform(Map<String, String> rawData) {
    Set<String> expectedKeySet = new HashSet<>(Arrays.asList(ACTION_CLASS_KEY, ACTION_METHOD_KEY));

    if (rawData != null) {
        // validation case: there is at least one key under java_action property
        Set<String> actualKeySet = rawData.keySet();

        for (String key : actualKeySet) {
            if (!expectedKeySet.remove(key)) {
                throw new RuntimeException("Invalid key for java action: " + key);
            }//from   ww  w . j  av a  2s . co  m
        }

        if (!expectedKeySet.isEmpty()) {
            throw new RuntimeException(
                    "The following keys for java action are missing: " + StringUtils.join(expectedKeySet, ","));
        }
    }

    return rawData;
}