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.xwiki.filemanager.internal.job.MoveJob.java

/**
 * Moves and renames the given file.// ww w  .  j  a va 2s  .  c o  m
 * 
 * @param file the file to move and rename
 * @param parentReference the parent folder the file may be moved from (a file can have multiple parent folders so
 *            we need to specify the source parent folder)
 * @param newPath the new file path
 */
private void moveAndRenameFile(File file, DocumentReference parentReference, Path newPath) {
    // Move the file first, if needed, because the rename must be performed inside the right parents.
    if (newPath.getFolderReference() != null && parentReference != null
            && !newPath.getFolderReference().equals(parentReference)) {
        Collection<DocumentReference> parentReferences = file.getParentReferences();
        boolean save = parentReferences.remove(parentReference);
        save |= parentReferences.add(newPath.getFolderReference());
        if (save) {
            fileSystem.save(file);
        }
    }

    // Rename the file.
    if (!file.getReference().equals(newPath.getFileReference())) {
        renameFile(file, newPath.getFileReference());
    }
}

From source file:de.dhke.projects.cutil.collections.aspect.AspectMultiMapTest.java

/**
* Test of get method, of class AspectMultiMap.
*//*from w  w w .j a v a  2 s. c  o m*/
@Test
public void testGet_remove_veto() {
    _listener.vetoRemove = true;
    Collection<String> values = _aspectMap.get("1");
    TestHelper.assertSequenceEquals(Arrays.asList("a", "A"), values);
    try {
        values.remove("a");
        fail("Remove veto not raised");
    } catch (AssertionError ex) {
        /* ignore */
    }
    assertTrue(_aspectMap.containsValue("1", "a"));
    assertTrue(_listener.beforeRemoveEvents.isEmpty());
    assertTrue(_listener.afterRemoveEvents.isEmpty());
}

From source file:net.myrrix.common.collection.FastIDSetTest.java

@Test
public void testVersusHashSet() {
    FastIDSet actual = new FastIDSet(1);
    Collection<Integer> expected = new HashSet<Integer>(1000000);
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
        double d = r.nextDouble();
        Integer key = r.nextInt(100);
        if (d < 0.4) {
            assertEquals(expected.contains(key), actual.contains(key));
        } else {//from  ww w .  j a  v  a2  s  . com
            if (d < 0.7) {
                assertEquals(expected.add(key), actual.add(key));
            } else {
                assertEquals(expected.remove(key), actual.remove(key));
            }
            assertEquals(expected.size(), actual.size());
            assertEquals(expected.isEmpty(), actual.isEmpty());
        }
    }
}

From source file:org.odk.collect.android.utilities.SharedPreferencesUtils.java

private JSONObject getModifiedPrefs(Collection<String> keys) throws JSONException {
    JSONObject prefs = new JSONObject();
    JSONObject adminPrefs = new JSONObject();
    JSONObject generalPrefs = new JSONObject();

    //checking for admin password
    if (keys.contains(KEY_ADMIN_PW)) {
        String password = (String) AdminSharedPreferences.getInstance().get(KEY_ADMIN_PW);
        if (!password.equals("")) {
            adminPrefs.put(KEY_ADMIN_PW, password);
        }//  w ww.  j av a2 s.  c om
        keys.remove(KEY_ADMIN_PW);
    }

    for (String key : keys) {
        Object defaultValue = GENERAL_KEYS.get(key);
        Object value = GeneralSharedPreferences.getInstance().get(key);

        if (value == null) {
            value = "";
        }
        if (defaultValue == null) {
            defaultValue = "";
        }

        if (!defaultValue.equals(value)) {
            generalPrefs.put(key, value);
        }
    }
    prefs.put("general", generalPrefs);

    for (String key : ALL_KEYS) {

        Object defaultValue = AdminSharedPreferences.getInstance().getDefault(key);
        Object value = AdminSharedPreferences.getInstance().get(key);
        if (defaultValue != value) {
            adminPrefs.put(key, value);
        }
    }
    prefs.put("admin", adminPrefs);

    return prefs;
}

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

/**
 * Removes a specific value from map./* w ww  .  j  ava2s .  c om*/
 * <p/>
 * The item is removed from the collection mapped to the specified key. Other values attached to that key are unaffected.
 * <p/>
 * If the last value for a key is removed, <code>null</code> will be returned from a subsequant <code>get(key)</code>.
 * 
 * @param key
 *            the key to remove from
 * @param item
 *            the value to remove
 * @return the value removed (which was passed in), null if nothing removed
 */
@SuppressWarnings("unchecked")
public V remove(Object key, Object item) {
    Collection<V> valuesForKey = getCollection(key);
    if (valuesForKey == null) {
        return null;
    }
    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:com.cloudera.oryx.common.collection.LongSetTest.java

@Test
public void testVersusHashSet() {
    LongSet actual = new LongSet(1);
    Collection<Integer> expected = Sets.newHashSet();
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
        double d = r.nextDouble();
        Integer key = r.nextInt(100);
        if (d < 0.4) {
            assertEquals(expected.contains(key), actual.contains(key));
        } else {//w w w . j av  a 2  s  .  co m
            if (d < 0.7) {
                assertEquals(expected.add(key), actual.add(key));
            } else {
                assertEquals(expected.remove(key), actual.remove(key));
            }
            assertEquals(expected.size(), actual.size());
            assertEquals(expected.isEmpty(), actual.isEmpty());
        }
    }
}

From source file:org.apache.kylin.measure.extendedcolumn.ExtendedColumnMeasureType.java

@Override
public CapabilityResult.CapabilityInfluence influenceCapabilityCheck(Collection<TblColRef> unmatchedDimensions,
        Collection<FunctionDesc> unmatchedAggregations, SQLDigest digest, MeasureDesc measureDesc) {
    TblColRef extendedCol = getExtendedColumn(measureDesc.getFunction());

    if (!unmatchedDimensions.contains(extendedCol)) {
        return null;
    }//w ww.ja  va2 s .co m

    if (digest.filterColumns.contains(extendedCol)) {
        return null;
    }

    unmatchedDimensions.remove(extendedCol);

    return new CapabilityResult.CapabilityInfluence() {
        @Override
        public double suggestCostMultiplier() {
            return 0.9;
        }
    };
}

From source file:uk.ac.ebi.intact.editor.services.curate.participant.ParticipantEditorService.java

private <T extends Participant, F extends Feature> void initialiseFeatures(T parent, Collection<F> features,
        EditorCloner featureCloner) {// w  w  w  .ja v a 2  s  . c  o m
    List<F> originalFeatures = new ArrayList<F>(features);
    for (F r : originalFeatures) {
        if (!isFeatureInitialised(r)) {
            F reloaded = initialiseFeature(r, featureCloner);
            if (reloaded != r) {
                features.remove(r);
                parent.addFeature(reloaded);
            }
        }
    }
}

From source file:org.entermedia.websocket.annotation.AnnotationServer.java

public void annotationRemoved(AnnotationConnection annotationConnection, JSONObject command, String message,
        String catalogid, String inCollectionId, String inAssetId) {
    JSONObject obj = loadAnnotatedAsset(catalogid, inCollectionId, inAssetId);
    Collection annotations = (Collection) obj.get("annotations");

    String removed = (String) command.get("annotationid");
    for (Iterator iterator = annotations.iterator(); iterator.hasNext();) {
        JSONObject existing = (JSONObject) iterator.next();
        String annotationid = (String) existing.get("id");
        if (removed.equals(annotationid)) {
            annotations.remove(existing);
            break;
        }//from   w ww.  j a v  a  2s  . c om
    }
    Searcher searcher = getSearcherManager().getSearcher(catalogid, "annotation");
    Data data = (Data) searcher.searchById(removed);
    searcher.delete(data, null);
    for (Iterator iterator = connections.iterator(); iterator.hasNext();) {
        AnnotationConnection annotationConnection2 = (AnnotationConnection) iterator.next();
        annotationConnection2.sendMessage(command);
    }
}

From source file:com.xpn.xwiki.stats.impl.XWikiStatsServiceImpl.java

@Override
public void onEvent(Event event, Object source, Object data) {
    if (Utils.getComponent(RemoteObservationManagerContext.class).isRemoteState()) {
        // we do nothing when the event comes from remote instance since the remote instance is supposed to already
        // take care of this
        return;//from  w  w w. j ava 2s .  co m
    }

    ActionExecutedEvent actionEvent = (ActionExecutedEvent) event;
    XWikiDocument document = (XWikiDocument) source;
    XWikiContext context = (XWikiContext) data;

    // If the server is in read-only mode, forget about the statistics (since it's in read only mode we don't write
    // anything in the database)
    if (context.getWiki().isReadOnly()) {
        return;
    }

    // Initialize cookie used as unique identifier of a user visit and put it in the context
    StatsUtil.findCookie(context);

    String action = actionEvent.getActionName();

    // Let's save in the session the last elements view, saved
    synchronized (this) {
        if (!action.equals(DownloadAction.ACTION_NAME)) {
            Collection actions = StatsUtil.getRecentActionFromSessions(context, action);
            if (actions == null) {
                actions = new CircularFifoBuffer(StatsUtil.getRecentVisitSize(context));
                StatsUtil.setRecentActionsFromSession(context, action, actions);
            }

            String element = document.getPrefixedFullName();
            if (actions.contains(element)) {
                actions.remove(element);
            }
            actions.add(element);
        }
    }

    try {
        if (StatsUtil.isWikiStatsEnabled(context) && !StatsUtil.getStorageFilteredUsers(context)
                .contains(this.currentDocumentReferenceResolver.resolve(context.getUser()))) {
            this.statsRegister.addStats(document, action, context);
        }
    } catch (Exception e) {
        LOGGER.error("Faild to get filter users list", e);
    }
}