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.romaframework.core.schema.SchemaHelper.java

public static Object removeElements(Object iContent, Object[] iSelection) {
    if (iContent == null) {
        return null;
    }// w  w w .  jav a2 s  . com

    Object result = null;

    if (iContent instanceof Collection<?>) {
        Collection<?> coll = (Collection<?>) iContent;
        for (int i = 0; i < iSelection.length; ++i) {
            coll.remove(iSelection[i]);
        }
    } else if (iContent instanceof Map<?, ?>) {
        Map<?, ?> map = (Map<?, ?>) iContent;
        Object toRemove;
        for (int i = 0; i < iSelection.length; ++i) {
            toRemove = iSelection[i] instanceof Map.Entry<?, ?> ? ((Map.Entry<?, ?>) iSelection[i]).getValue()
                    : iSelection[i];
            map.values().remove(toRemove);
        }
    } else if (iContent instanceof Set<?>) {
        Set<?> set = (Set<?>) iContent;
        for (int i = 0; i < iSelection.length; ++i) {
            set.remove(iSelection[i]);
        }
    } else if (iContent.getClass().isArray()) {
        Object[] array = (Object[]) iContent;
        List<Object> tempResult = new ArrayList<Object>(array.length);

        boolean found;
        for (int i = 0; i < array.length; ++i) {
            found = false;
            for (int sel = 0; sel < iSelection.length; ++sel) {
                if (array[i].equals(iSelection[sel])) {
                    found = true;
                    break;
                }
            }

            if (!found) {
                // OK, NOT TO BE REMOVED
                tempResult.add(array[i]);
            }
        }

        result = tempResult.toArray();
    }
    return result;
}

From source file:MultiMap.java

public boolean remove(Object key, Object value) {
    Collection values = (Collection) map.get(key);
    if (values == null) {
        return false;
    } else {/*from  ww  w  . j a  v  a2  s.c o m*/
        return values.remove(value);
    }
}

From source file:com.diversityarrays.dal.server.TestFiltering.java

public void testExpressions(boolean shouldPass, String[] expressions, Closure<Filtering> check,
        String... expectedColumnNames) {
    for (String expr : expressions) {
        Filtering f = new Filtering(expr);
        if (shouldPass) {
            if (f.error != null) {
                fail(expr + ": " + f.error);
            }//from  w ww. j a va 2  s.  c o m
            Collection<String> coll = new ArrayList<String>(f.columnNames);

            for (String expectedColumnName : expectedColumnNames) {
                if (!coll.remove(expectedColumnName)) {
                    fail(expr + ": Missing expected columnName '" + expectedColumnName + "'");
                }
            }

            if (!coll.isEmpty()) {
                fail(expr + ": Missing unexpected columnNames: " + join(",", coll));
            }
            if (check != null) {
                check.execute(f);
            }
        } else {
            if (f.error == null) {
                fail(expr + ": VALID but should not be!");
            }
        }
    }
}

From source file:de.iew.stagediver.fx.eventbus.services.impl.EventBusImpl.java

/**
 * Removes the specified observer for the specified topic.
 *
 * @param topic    The non NULL topic//from ww  w .  j  av a2  s.  c  o  m
 * @param observer The observer to remove
 */
public void removeObserver(final String topic, final AnnotatedObserver observer) {
    final Collection<AnnotatedObserver> observers = getObserversForTopic(topic);
    if (observers != null) {
        observers.remove(observer);
    }
}

From source file:net.bpfurtado.tas.model.persistence.XMLAdventureReader.java

/**
 * @param scene// w  w  w .ja v  a2 s .c om
 * @param scenesNotScannedYet
 *            Just to keep the scenes not yet visited.
 */
@SuppressWarnings("unchecked")
private void findAllTos(Scene scene, Collection<Scene> scenesNotScannedYet) {
    if (scenesNotScannedYet != null) {
        scenesNotScannedYet.remove(scene);
    }

    Node sceneNode = xmlDocument.selectSingleNode("//scene[@id='" + scene.getId() + "']");
    List<Node> pathNodes = sceneNode.selectNodes("./path");
    int i = 0;
    logger.debug("Scene=" + scene + ", pathNodes.sz=" + pathNodes.size());
    for (Node pathNode : pathNodes) {
        logger.debug(i);
        IPath p = scene.createPath(pathNode.getText());
        String orderStr = pathNode.valueOf("@order");
        if (orderStr == null || orderStr.length() == 0) {
            p.setOrder(i++);
        }
        String idToStr = pathNode.valueOf("@toScene");
        if (!GenericValidator.isBlankOrNull(idToStr)) {
            Scene to = adventure.getScene(Integer.parseInt(idToStr));
            boolean hadScenesFrom = !to.getScenesFrom().isEmpty();
            p.setTo(to);

            logger.debug(p);

            if (!hadScenesFrom) {
                logger.debug("BEFORE RECURSION: to=" + to);
                logger.debug("BEFORE RECURSION: all=" + scenesNotScannedYet);
                if (scenesNotScannedYet.contains(to)) {
                    findAllTos(to, scenesNotScannedYet);
                }
            }
        } else {
            logger.debug(p);
        }
    }
}

From source file:org.kuali.coeus.common.framework.person.PropAwardPersonRoleValuesFinder.java

protected void addKeyValue(List<KeyValue> keyValues, Collection<PropAwardPersonRole> roles, String roleId) {
    PropAwardPersonRole curRole = getRoleById(roles, roleId);
    if (curRole != null) {
        addKeyValue(keyValues, curRole);
        roles.remove(curRole);
    }/*  www .  j a  va  2s.  c om*/
}

From source file:com.sun.socialsite.business.impl.JPAListenerManagerImpl.java

/**
 * {@inheritDoc}/*w  w  w. ja  va  2  s . c o  m*/
 */
public void removeListener(Class entityClass, Object listener) {
    Collection<Object> listenersForClass = listenersMap.get(entityClass);
    if (listenersForClass != null) {
        listenersForClass.remove(listener);
    }
}

From source file:org.jactr.core.queue.collection.PrioritizedQueue.java

synchronized public boolean remove(T item) {
    double priority = _prioritizer.getPriority(item);
    if (Double.isNaN(priority))
        throw new IllegalArgumentException("Invalid priority of " + item + ", must not be NaN");

    Collection<T> itemsOfSamePriority = _backingMap.get(priority);
    if (itemsOfSamePriority == null)
        return false;

    itemsOfSamePriority.remove(item);
    _size--;/*from  ww w .  j  av a  2 s .co m*/
    return true;
}

From source file:com.silverpeas.gallery.dao.MediaDAO.java

/**
 * Adding all data of photos.//  w w  w. ja v  a2  s .  c  o m
 * @param con
 * @param media
 * @param photos
 * @throws SQLException
 */
private static void decoratePhotos(final Connection con, List<Media> media, Map<String, Photo> photos)
        throws SQLException {
    if (!photos.isEmpty()) {
        Collection<Collection<String>> idGroups = CollectionUtil.split(new ArrayList<String>(photos.keySet()));
        StringBuilder queryBase = new StringBuilder(SELECT_INTERNAL_MEDIA_PREFIX)
                .append("P.resolutionW, P.resolutionH from SC_Gallery_Internal I join SC_Gallery_Photo P on I"
                        + ".mediaId = P.mediaId where I.mediaId in ");
        for (Collection<String> mediaIds : idGroups) {
            PreparedStatement prepStmt = null;
            ResultSet rs = null;
            try {
                prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString());
                DBUtil.setParameters(prepStmt, mediaIds);
                rs = prepStmt.executeQuery();
                while (rs.next()) {
                    String mediaId = rs.getString(1);
                    mediaIds.remove(mediaId);
                    Photo currentPhoto = photos.get(mediaId);
                    decorateInternalMedia(rs, currentPhoto);
                    currentPhoto.setDefinition(Definition.of(rs.getInt(8), rs.getInt(9)));
                }
            } finally {
                DBUtil.close(rs, prepStmt);
            }
            // Not found
            for (String mediaIdNotFound : mediaIds) {
                Photo currentPhoto = photos.remove(mediaIdNotFound);
                media.remove(currentPhoto);
                SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decoratePhotos()",
                        "root.MSG_GEN_PARAM_VALUE",
                        "photo not found (removed from result): " + mediaIdNotFound);
            }
        }
    }
}

From source file:com.silverpeas.gallery.dao.MediaDAO.java

/**
 * Adding all data of sounds.//from  w  ww  .  j av  a2  s  . co m
 * @param con
 * @param media
 * @param sounds
 * @throws SQLException
 */
private static void decorateSounds(final Connection con, List<Media> media, Map<String, Sound> sounds)
        throws SQLException {
    if (!sounds.isEmpty()) {
        Collection<Collection<String>> idGroups = CollectionUtil.split(new ArrayList<String>(sounds.keySet()));
        StringBuilder queryBase = new StringBuilder(SELECT_INTERNAL_MEDIA_PREFIX)
                .append("S.bitrate, S.duration from SC_Gallery_Internal I join SC_Gallery_Sound S on I.mediaId "
                        + "= S.mediaId where I.mediaId in ");
        for (Collection<String> mediaIds : idGroups) {
            PreparedStatement prepStmt = null;
            ResultSet rs = null;
            try {
                prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString());
                DBUtil.setParameters(prepStmt, mediaIds);
                rs = prepStmt.executeQuery();
                while (rs.next()) {
                    String mediaId = rs.getString(1);
                    mediaIds.remove(mediaId);
                    Sound currentSound = sounds.get(mediaId);
                    decorateInternalMedia(rs, currentSound);
                    currentSound.setBitrate(rs.getLong(8));
                    currentSound.setDuration(rs.getLong(9));
                }
            } finally {
                DBUtil.close(rs, prepStmt);
            }
            // Not found
            for (String mediaIdNotFound : mediaIds) {
                Sound currentSound = sounds.remove(mediaIdNotFound);
                media.remove(currentSound);
                SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decorateSounds()",
                        "root.MSG_GEN_PARAM_VALUE",
                        "sound not found (removed from result): " + mediaIdNotFound);
            }
        }
    }
}