Example usage for java.util Collection remove

List of usage examples for java.util Collection remove

Introduction

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

Prototype

boolean remove(Object o);

Source Link

Document

Removes a single instance of the specified element from this collection, if it is present (optional operation).

Usage

From source file:org.extremesite.controller.SelectedPresidentsUtils.java

public static Collection saveSelectedPresidentsIDs(HttpServletRequest request) {
    Collection presidents = (Collection) request.getSession()
            .getAttribute(SelectedPresidentsConstants.SELECTED_PRESIDENTS);

    if (presidents == null) {
        presidents = new ArrayList();
        request.getSession().setAttribute(SelectedPresidentsConstants.SELECTED_PRESIDENTS, presidents);
    }//  w  w  w .j a  v  a2s . co m

    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        if (parameterName.startsWith("chkbx_")) {
            String presidentId = StringUtils.substringAfter(parameterName, "chkbx_");
            String parameterValue = request.getParameter(parameterName);
            if (parameterValue.equals(SelectedPresidentsConstants.SELECTED)) {
                if (!presidents.contains(presidentId)) {
                    presidents.add(presidentId);
                }
            } else {
                presidents.remove(presidentId);
            }
        }
    }

    return presidents;
}

From source file:org.ralasafe.servlet.RolePrivilegeAction.java

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String oper = req.getParameter("oper");
    int roleId = WebUtil.getIntParameter(req, "roleId", -23);
    String rawPvlgIds = req.getParameter("pvlgIds");
    String[] assignPvlgIds = StringUtil.split(rawPvlgIds, ",");
    Collection pvlgIds = Util.convert2IntegerCollection(assignPvlgIds);
    pvlgIds.remove(new Integer(0)); // remove root node

    // log/*from www  .j av  a  2 s . c om*/
    if (log.isDebugEnabled()) {
        log.debug("oper=" + oper + " ,roleId=" + roleId + ", assignPrivilegeIds=" + rawPvlgIds);
    }

    RoleManager roleMng = WebUtil.getRoleManager(req);

    roleMng.assignPrivileges(roleId, pvlgIds);
}

From source file:MultiMap.java

public void remove(K k, V v) {
    Collection<V> s = map.get(k);
    if (s != null) {
        s.remove(v);
        if (s.isEmpty())
            map.remove(k);/*from w ww.  ja v  a 2  s. c  o  m*/
    }
}

From source file:com.framework.infrastructure.utils.HibernateUtils.java

/**
 * ID,./*from   w  w w . j av a  2 s .co  m*/
 * 
 * id,id.
 * id,id. ID,
 * cascade-save-or-update.
 * 
 * @param srcObjects
 *            ,.
 * @param checkedIds
 *            ,ID.
 * @param clazz
 *            
 * @param idName
 *            
 */
public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds,
        final Class<T> clazz, final String idName) {

    // 
    Assert.notNull(srcObjects, "scrObjects");
    Assert.hasText(idName, "idName");
    Assert.notNull(clazz, "clazz");

    // , .
    if (checkedIds == null) {
        srcObjects.clear();
        return;
    }

    // ,idID,.
    // ,id,idid.
    Iterator<T> srcIterator = srcObjects.iterator();
    try {

        while (srcIterator.hasNext()) {
            T element = srcIterator.next();
            Object id;
            id = PropertyUtils.getProperty(element, idName);

            if (!checkedIds.contains(id)) {
                srcIterator.remove();
            } else {
                checkedIds.remove(id);
            }
        }

        // IDid,,id.
        for (ID id : checkedIds) {
            T obj = clazz.newInstance();
            PropertyUtils.setProperty(obj, idName, id);
            srcObjects.add(obj);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
}

From source file:com.kylinolap.query.routing.QueryRouter.java

private static void adjustOLAPContext(Collection<TblColRef> dimensionColumns,
        Collection<FunctionDesc> aggregations, //
        Collection<TblColRef> metricColumns, CubeInstance cube, Map<String, RelDataType> rewriteFields,
        OLAPContext olapContext) {// www  .java  2s  .co  m
    CubeDesc cubeDesc = cube.getDescriptor();
    Collection<FunctionDesc> cubeFuncs = cubeDesc.listAllFunctions();

    Iterator<FunctionDesc> it = aggregations.iterator();
    while (it.hasNext()) {
        FunctionDesc functionDesc = it.next();
        if (!cubeFuncs.contains(functionDesc)) {
            // try to convert the metric to dimension to see if it works
            TblColRef col = findTblColByColumnName(metricColumns, functionDesc.getParameter().getValue());
            functionDesc.setAppliedOnDimension(true);
            rewriteFields.remove(functionDesc.getRewriteFieldName());
            if (col != null) {
                metricColumns.remove(col);
                dimensionColumns.add(col);
                olapContext.storageContext.addOtherMandatoryColumns(col);
            }
            logger.info("Adjust OLAPContext for " + functionDesc);
        }
    }
}

From source file:com.digitalgeneralists.assurance.notification.NotificationProvider.java

public void removeEventObserver(Class<? extends IAssuranceEvent> eventClass, IEventObserver observer) {
    Collection<IEventObserver> eventObservers = eventObserverList.get(eventClass);
    if (eventObservers != null) {
        eventObservers.remove(observer);
        if (eventObservers.size() == 0) {
            eventObserverList.remove(eventObservers);
        }//from   w w w.j  av  a 2  s .c  om
    }

    eventObservers = null;
}

From source file:org.openanzo.rdf.utils.AnzoMultiMap.java

@Override
@SuppressWarnings("unchecked")
public V remove(Object key, Object item) {
    Collection<V> valuesForKey = getCollection(key);
    if (valuesForKey == null) {
        return null;
    }//  ww w.  j av a 2  s .c o  m
    boolean valueRemoved = valuesForKey.remove(item);

    // remove the list if it is now empty
    // (saves space, and allows equals to work)
    if (valuesForKey.isEmpty()) {
        remove(key);
    }
    return (valueRemoved) ? (V) item : null;
}

From source file:org.simbasecurity.core.domain.repository.ConditionDatabaseRepository.java

@Override
public void updatePolicies(Condition condition, Collection<Policy> newPolicies) {
    Collection<Policy> oldPolicies = findPolicies(condition);
    for (Policy policy : oldPolicies) {
        if (!newPolicies.remove(policy)) {
            policy.getConditions().remove(condition);
        }//from  w ww  .j  a va 2s. com
    }

    for (Policy policy : newPolicies) {
        policy.getConditions().add(condition);
    }
}

From source file:org.springside.modules.orm.hibernate.HibernateUtils.java

/**
 * ?ID?,???.//from  w  w  w.  j av a  2 s  .  c  om
 * 
 * ??????id,??????id?????.
 * ???id??,??id??.
 * ?ID, ??cascade-save-or-update??.
 * 
 * @param srcObjects ??,.
 * @param checkedIds  ?,ID.
 * @param clazz  ?
 * @param idName ??
 */
public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds,
        final Class<T> clazz, final String idName) {

    //?
    Assert.notNull(srcObjects, "scrObjects?");
    Assert.hasText(idName, "idName?");
    Assert.notNull(clazz, "clazz?");

    //?, ???.
    if (checkedIds == null) {
        srcObjects.clear();
        return;
    }

    //????,id?ID?,.
    //?,???id,?id???id.
    Iterator<T> srcIterator = srcObjects.iterator();
    try {

        while (srcIterator.hasNext()) {
            T element = srcIterator.next();
            Object id;
            id = PropertyUtils.getProperty(element, idName);

            if (!checkedIds.contains(id)) {
                srcIterator.remove();
            } else {
                checkedIds.remove(id);
            }
        }

        //ID??id????,,id??.
        for (ID id : checkedIds) {
            T obj = clazz.newInstance();
            PropertyUtils.setProperty(obj, idName, id);
            srcObjects.add(obj);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
}

From source file:com.thinkmore.framework.orm.hibernate.HibernateWebUtils.java

/**
 * ?ID?,???./*ww  w.j a va 2 s . co m*/
 * 
 * ??????id,??????id?????.
 * ???id??,??id??.
 * ?ID, ??cascade-save-or-update.
 * 
 * @param srcObjects ??,.
 * @param checkedIds  ?,ID.
 * @param clazz  ?
 * @param idName ??
 */
public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds,
        final Class<T> clazz, final String idName) {

    //?
    Assert.notNull(srcObjects, "scrObjects?");
    Assert.hasText(idName, "idName?");
    Assert.notNull(clazz, "clazz?");

    //?,???.
    if (checkedIds == null) {
        srcObjects.clear();
        return;
    }

    //????,id?ID?,.
    //?,???id,?id???id.
    Iterator<T> srcIterator = srcObjects.iterator();
    try {

        while (srcIterator.hasNext()) {
            T element = srcIterator.next();
            Object id;
            id = PropertyUtils.getProperty(element, idName);

            if (!checkedIds.contains(id)) {
                srcIterator.remove();
            } else {
                checkedIds.remove(id);
            }
        }

        //ID??id????,,id??.
        for (ID id : checkedIds) {
            T obj = clazz.newInstance();
            PropertyUtils.setProperty(obj, idName, id);
            srcObjects.add(obj);
        }
    } catch (Exception e) {
        throw ReflectionUtil.convertReflectionExceptionToUnchecked(e);
    }
}