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:de.thischwa.pmcms.gui.dialog.pojo.DialogFieldsPageComp.java

private void initializeTitleAndName() {
    String filename = StringUtils.defaultString(page.getName());
    GridData gridDataLabel = new GridData();
    gridDataLabel.widthHint = 100;/*  ww  w  .  j  ava  2s. c o m*/
    gridDataLabel.verticalAlignment = GridData.CENTER;
    gridDataLabel.horizontalAlignment = GridData.END;
    GridData gridDataText = new GridData();
    gridDataText.heightHint = -1;
    gridDataText.widthHint = 150;
    Label labelTitle = new Label(this, SWT.RIGHT);
    labelTitle.setText(LabelHolder.get("dialog.pojo.page.fields.title")); //$NON-NLS-1$
    labelTitle.setLayoutData(gridDataLabel);
    textTitle = new Text(this, SWT.BORDER);
    textTitle.setTextLimit(256);
    textTitle.setLayoutData(gridDataText);
    textTitle.setText(StringUtils.defaultString(page.getTitle()));
    Label labelName = new Label(this, SWT.RIGHT);
    labelName.setText("*   ".concat(LabelHolder.get("dialog.pojo.page.fields.name"))); //$NON-NLS-1$ //$NON-NLS-2$
    labelName.setLayoutData(gridDataLabel);
    textName = new Text(this, SWT.BORDER);
    textName.setTextLimit(256);
    textName.setLayoutData(gridDataText);
    textName.setText(filename);
    textName.addVerifyListener(new FileNameVerifier());
    textName.addModifyListener(new ModifyListenerClearErrorMessages(dialogCreator));

    Collection<String> forbiddenNames = new ArrayList<String>();
    Collection<Page> sisters = page.getParent().getPages();
    if (CollectionUtils.isNotEmpty(sisters))
        for (Page page : sisters)
            forbiddenNames.add(page.getName());
    if (StringUtils.isNotBlank(filename))
        forbiddenNames.remove(filename);
    if (page.getId() == APoormansObject.UNSET_VALUE) // suggestion of the file name should work just with new  objects
        textTitle.addModifyListener(new FilenameSuggestorListener(dialogCreator, textName, forbiddenNames));
}

From source file:dk.nsi.haiba.lprimporter.importer.ImportExecutor.java

private Collection<Codes> testNewKoder(Collection<Codes> allUsed, Collection<Codes> allRegistered) {
    Collection<Codes> returnValue = new ArrayList<Codes>(allUsed);
    for (Codes used : allUsed) {
        for (Codes registered : allRegistered) {
            if (registered.getCode().startsWith(used.getCode())
                    && equals(registered.getSecondaryCode(), used.getSecondaryCode())) {
                returnValue.remove(used);
            }/*ww  w  .  j ava2  s . co  m*/
        }
    }
    log.debug("testNewKoder: returnValue=" + returnValue);
    return returnValue;
}

From source file:org.biopax.validator.rules.DanglingElementRule.java

public void check(final Validation validation, Model model) {

    // get all the root elements
    final Collection<BioPAXElement> rootElements = new HashSet<BioPAXElement>(model.getObjects());

    // extends traverser ;)
    AbstractTraverser checker = new AbstractTraverser(SimpleEditorMap.get(model.getLevel())) {
        @Override/*from  w  w w.  j ava  2 s  .  com*/
        protected void visit(Object value, BioPAXElement parent, Model model, PropertyEditor editor) {
            if (value instanceof BioPAXElement)
                rootElements.remove(value); // found, i.e., it is used by another element.
        }
    };

    // this removes those elements that are referenced from others
    for (BioPAXElement e : model.getObjects()) {
        checker.traverse(e, model);
    }

    // those left are in fact dangling!
    for (BioPAXElement thing : rootElements) {
        if (!(thing instanceof Pathway))
            error(validation, thing, "dangling.element", false);
    }

}

From source file:de.thischwa.pmcms.gui.dialog.pojo.DialogFieldsLevelComp.java

private void initialize() {
    String filename = StringUtils.defaultString(level.getName());
    GridData gridDataLabel = new GridData();
    gridDataLabel.widthHint = 100;//w  w w. jav a  2s  . c o m
    gridDataLabel.verticalAlignment = GridData.CENTER;
    gridDataLabel.horizontalAlignment = GridData.END;
    GridData gridDataText = new GridData();
    gridDataText.heightHint = -1;
    gridDataText.widthHint = 150;
    GridLayout gridLayoutMy = new GridLayout();
    gridLayoutMy.numColumns = 2;
    gridLayoutMy.marginWidth = 25;
    gridLayoutMy.verticalSpacing = 5;
    gridLayoutMy.horizontalSpacing = 20;
    gridLayoutMy.marginHeight = 25;
    gridLayoutMy.makeColumnsEqualWidth = false;
    GridData gridDataMy = new GridData();
    gridDataMy.grabExcessHorizontalSpace = true;
    gridDataMy.verticalAlignment = GridData.CENTER;
    gridDataMy.horizontalSpan = 1;
    gridDataMy.horizontalAlignment = GridData.FILL;
    this.setLayoutData(gridDataMy);
    this.setLayout(gridLayoutMy);
    Label labelTitle = new Label(this, SWT.RIGHT);
    labelTitle.setText("*   ".concat(LabelHolder.get("dialog.pojo.level.fields.title"))); //$NON-NLS-1$
    labelTitle.setLayoutData(gridDataLabel);
    textTitle = new Text(this, SWT.BORDER);
    textTitle.setTextLimit(256);
    textTitle.setLayoutData(gridDataText);
    textTitle.setText(StringUtils.defaultString(level.getTitle()));
    Label labelName = new Label(this, SWT.RIGHT);
    labelName.setText("*   ".concat(LabelHolder.get("dialog.pojo.level.fields.name"))); //$NON-NLS-1$
    labelName.setLayoutData(gridDataLabel);
    textName = new Text(this, SWT.BORDER);
    textName.setTextLimit(256);
    textName.setLayoutData(gridDataText);
    textName.setText(filename);
    textName.addVerifyListener(new FileNameVerifier());
    textName.addModifyListener(new ModifyListenerClearErrorMessages(dialogCreator));

    Collection<String> forbiddenNames = new ArrayList<String>();
    Collection<Level> sisters = level.getParent().getSublevels();
    if (CollectionUtils.isNotEmpty(sisters))
        for (Level otherLevel : sisters)
            forbiddenNames.add(otherLevel.getName());
    if (StringUtils.isNotBlank(filename))
        forbiddenNames.remove(filename);
    if (level.getId() == APoormansObject.UNSET_VALUE) // suggestion of the file name should work just with new  objects
        textTitle.addModifyListener(new FilenameSuggestorListener(dialogCreator, textName, forbiddenNames));
}

From source file:tds.itempreview.ConfigBuilder.java

public Config removeFile(String fileName) throws Exception {
    Collection<IrisITSDocument> itsDocuments = _documentLookup.values();
    String key = getRemoveKey(fileName);
    IrisITSDocument documentRemove = _documentLookup.get(key);

    Collection<IrisITSDocument> newDocs = new ArrayList<>();
    newDocs.addAll(itsDocuments);/*from ww w.j  a v  a 2  s. c o  m*/
    newDocs.remove(documentRemove);

    return reloadContent(newDocs);

}

From source file:org.opendatakit.persistence.table.UserGrantedAuthority.java

public static final void assertUserGrantedAuthorities(String uriUser, Collection<String> desiredGroups,
        CallingContext cc) throws ODKDatastoreException {

    Datastore ds = cc.getDatastore();/*from   w  w  w .j a v a2  s  . c om*/
    User user = cc.getCurrentUser();

    boolean hasNotChanged = true;

    try {
        UserGrantedAuthority relation = UserGrantedAuthority.assertRelation(ds, user);

        // get the members as currently defined for this group
        List<? extends CommonFieldsBase> groupsList;
        Query query = ds.createQuery(relation, "UserGrantedAuthority.assertUserGrantedAuthorities", user);
        query.addFilter(UserGrantedAuthority.USER, FilterOperation.EQUAL, uriUser);
        groupsList = query.executeQuery();

        // OK we have the desired and actual groups lists for this username.
        // find the set of groups to remove...
        List<EntityKey> deleted = new ArrayList<EntityKey>();
        for (CommonFieldsBase b : groupsList) {
            UserGrantedAuthority t = (UserGrantedAuthority) b;
            String groupName = t.getGrantedAuthority().getAuthority();
            if (desiredGroups.contains(groupName)) {
                desiredGroups.remove(groupName);
            } else {
                deleted.add(t.getEntityKey());
            }
        }
        // we now have the list of desiredGroups to insert, and the list of
        // existing records to delete...
        List<UserGrantedAuthority> added = new ArrayList<UserGrantedAuthority>();
        for (String group : desiredGroups) {
            UserGrantedAuthority t = ds.createEntityUsingRelation(relation, user);
            t.setUser(uriUser);
            t.setGrantedAuthority(new SimpleGrantedAuthority(group));
            added.add(t);
        }

        // nothing has changed if there are no adds and no deletes.
        hasNotChanged = added.isEmpty() && deleted.isEmpty();

        // we now have the list of EntityKeys to delete, and the list of records to add -- do it.
        ds.putEntities(added, user);
        ds.deleteEntities(deleted, user);
    } finally {
        if (!hasNotChanged) {
            // we've changed, so we need to reload permissions tree
            cc.getUserService().reloadPermissions();
        }
    }
}

From source file:org.ambraproject.rhino.service.impl.IngestionServiceTest.java

@Test(dataProvider = "getPackageEntryNames", expectedExceptions = RestClientException.class, expectedExceptionsMessageRegExp = "Archive has no manifest file")
public void testGetManifestXml_missingManifest(Collection<String> entryNames) throws Exception {
    entryNames.remove(MANIFEST_XML);
    Archive invalidTestArchive = createStubArchive(null, entryNames);
    ingestionService.getManifestXml(invalidTestArchive);
}

From source file:com.google.enterprise.connector.persist.MigrateStore.java

@Override
public void run(CommandLine commandLine) throws Exception {
    initStandAloneContext(false);//from   ww w .j a  va  2 s . com
    // Since we did not start the Context, we need to init TypeMap
    // for PersistentStores to function correctly.
    getTypeMap().init();

    try {
        // If user asks for a list of available PersitentStores,
        // print it and exit.
        if (commandLine.hasOption("list")) {
            listStores();
            return;
        }

        // Get then names of the source and destination PersitentStores.
        String sourceName = null;
        String destName = null;
        String[] args = commandLine.getArgs();
        if ((args.length == 1) || (args.length > 2)) {
            printUsageAndExit(-1);
        }
        if (args.length == 2) {
            sourceName = args[0];
            destName = args[1];
        } else {
            Collection<String> storeNames = getStoreNames();
            sourceName = selectStoreName("source", storeNames);
            if (sourceName == null) {
                return;
            }
            storeNames.remove(sourceName);
            destName = selectStoreName("destination", storeNames);
            if (destName == null) {
                return;
            }
        }
        if (sourceName.equals(destName)) {
            System.err.println("Source and destination PersistentStores must be different.");
            return;
        }

        PersistentStore sourceStore = getPersistentStoreByName(sourceName);

        // Determine which connectors to migrate.
        Collection<String> connectors = null;
        String[] connectorNames = commandLine.getOptionValues('c');
        if (connectorNames != null) {
            connectors = ImmutableSortedSet.copyOf(connectorNames);
        } else if (args.length != 2) {
            // If no connectors were specified on the command line, and we had
            // to prompt the user for the source and destination stores, then also
            // prompt the user for a connector to migrate.
            String name = selectConnectorName(getConnectorNames(sourceStore));
            if (name != null) {
                connectors = ImmutableSortedSet.of(name);
            }
        }

        // Actually perform the migration.
        PersistentStore destStore = getPersistentStoreByName(destName);
        if (sourceStore != null && destStore != null) {
            // Adjust the logging levels so that StoreMigrator messages are logged
            // to the Console.
            Logger.getLogger(StoreMigrator.class.getName()).setLevel(Level.INFO);
            StoreMigrator.migrate(sourceStore, destStore, connectors, commandLine.hasOption("force"));
            StoreMigrator.checkMissing(destStore, connectors);
        }
    } finally {
        shutdown();
    }
}

From source file:org.kuali.rice.krad.data.provider.impl.ProviderRegistryImpl.java

/**
 * {@inheritDoc}/*w w  w  . j ava 2  s .  c  om*/
 */
@Override
public synchronized boolean unregisterProvider(Provider provider) {
    Validate.notNull(provider, "Provider must be non-null");
    boolean removed = false;
    Collection<Provider> providers = providersByType.values();

    // {@link java.util.Collection#remove} semantics for multimap is to remove a *single* occurrence of the given object
    // so we need to keep removing the provider until all mapped instances have been removed
    while (providers.remove(provider)) {
        removed = true;
    }

    return removed;
}

From source file:org.springsource.ide.eclipse.commons.browser.javafx.JavaFxBrowserManager.java

/**
 * Calls Javascript functions <i>to</i> the browser, refreshing the browser
 * when all calls have completed./* w  w w.ja v  a 2  s  .c o  m*/
 * @param functions
 */
public void callOnBrowser(final Collection<IEclipseToBrowserFunction> functions) {
    final Collection<IEclipseToBrowserFunction> waitingFunctions = new CopyOnWriteArrayList<IEclipseToBrowserFunction>();
    IEclipseToBrowserFunction.Callback callback = new IEclipseToBrowserFunction.Callback() {
        @Override
        public void ready(IEclipseToBrowserFunction function) {
            waitingFunctions.remove(function);
            if (waitingFunctions.isEmpty() && !disposed) {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        JSObject js = (JSObject) getEngine().executeScript("window");
                        for (IEclipseToBrowserFunction provider : functions) {
                            js.call(provider.getFunctionName(), (Object[]) provider.getArguments());
                        }
                        getView().requestLayout();
                        getView().setVisible(true);
                        if (DEBUG) {
                            printPageHtml();
                        }
                    }
                });
            }
        }
    };
    for (IEclipseToBrowserFunction function : functions) {
        if (!function.isReady()) {
            waitingFunctions.add(function);
            function.setCallback(callback);
        }
    }
    callback.ready(null);
}