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.vmware.o11n.plugin.powershell.config.impl.ConfigurationServiceImpl.java

@Override
public synchronized void reload() {
    try {//from  w w  w . ja va2 s . c  o m
        HostConfigPersister persister = createPersister();
        List<PowerShellHostConfig> all = persister.getAll();
        for (PowerShellHostConfig hostConfig : all) {
            PowerShellHostConfig prev = hostsById.get(hostConfig.getId());
            if (prev == null || !hostConfig.equals(prev)) {
                hostsById.put(hostConfig.getId(), hostConfig);
                fireUpdate(hostConfig);
            }
        }

        //build difference between old available configs and new
        Set<String> old = new HashSet<String>(hostsById.keySet());
        for (PowerShellHostConfig config : all) {
            old.remove(config.getId());
        }

        //delete all configs that ware present before but are missing now
        for (String id : old) {
            remove(id);
        }
    } catch (RemoteException e) {
        log.warn("", e);
    } catch (LoginException e) {
        log.warn("", e);
    } catch (DunesServerException e) {
        log.warn("", e);
    }
}

From source file:base.Engine.java

static Set<TreeSet<PatternInstance>> addPair(Set<TreeSet<PatternInstance>> returnSet, PatternInstance p1,
        PatternInstance p2) {// w w  w . j  ava 2  s  . c  o m
    TreeSet<PatternInstance> t1 = null;
    TreeSet<PatternInstance> t2 = null;
    for (TreeSet<PatternInstance> aTree : returnSet) {
        if (aTree.contains(p1)) {
            t1 = aTree;
            break;
        }
    }
    for (TreeSet<PatternInstance> aTree : returnSet) {
        if (aTree.contains(p2)) {
            t2 = aTree;
            break;
        }
    }

    if (t1 == null && t2 == null) {
        TreeSet<PatternInstance> newTree = new TreeSet<>(new InstanceComparator());
        newTree.add(p1);
        newTree.add(p2);
        returnSet.add(newTree);
    } else if (t1 == null && t2 != null) {
        t2.add(p1);
    } else if (t1 != null && t2 == null) {
        t1.add(p2);
    } else if (t1 != t2) {
        t1.addAll(t2);
        returnSet.remove(t2);
    }
    return returnSet;
}

From source file:emlab.domain.technology.PowerGeneratingTechnology.java

public Set<Substance> getCoCombustionFuels() {
    Set<Substance> coFuels = new HashSet<Substance>(getFuels());
    coFuels.remove(getMainFuel());
    return coFuels;
}

From source file:gov.nih.nci.cabig.ctms.web.WebToolsTest.java

public void testRequestPropertiesToMapIsNotMissingAnything() throws Exception {
    Map<String, Object> actual = WebTools.requestPropertiesToMap(request);

    Set<String> missing = new LinkedHashSet<String>(EXPECTED_REQUEST_PROPERTIES);
    for (String property : EXPECTED_REQUEST_PROPERTIES) {
        if (actual.containsKey(property))
            missing.remove(property);
    }/*from   ww w  . j  ava 2 s  .c  o  m*/
    assertEquals("One or more expected properties missing: " + missing, 0, missing.size());
}

From source file:net.solarnetwork.domain.GeneralDatumSupport.java

/**
 * Remove a tag value.// w  ww. j  ava  2s  . c o  m
 * 
 * @param tag
 *        the tag value to add
 */
public void removeTag(String tag) {
    if (tag == null) {
        return;
    }
    Set<String> set = tags;
    if (set != null) {
        set.remove(tag);
    }
}

From source file:org.openmrs.module.dataexchange.DataExporter.java

private void addTable(DatabaseConnection connection, List<ITable> tables, TableDefinition tableDefinition,
        String key, Set<Integer> ids) throws SQLException, DataSetException {
    ids.remove(null);

    if (ids.isEmpty()) {
        return;//from   w  w w. j a  v a 2 s .co  m
    }

    StringBuilder select = new StringBuilder("select * from ").append(tableDefinition.getTableName())
            .append(" where ").append(key).append(" in (?");
    for (int i = 1; i < ids.size(); i++) {
        select.append(", ?");
    }
    select.append(")");

    PreparedStatement selectQuery = connection.getConnection().prepareStatement(select.toString());

    int index = 1;
    for (Integer id : ids) {
        selectQuery.setInt(index, id);
        index++;
    }

    ITable resultTable = connection.createTable(tableDefinition.getTableName(), selectQuery);

    if (resultTable.getRowCount() == 0) {
        return;
    }

    Set<Integer> notFetchedIds = new HashSet<Integer>();

    for (int i = 0; i < resultTable.getRowCount(); i++) {
        Integer id = (Integer) resultTable.getValue(i, tableDefinition.getPrimaryKey());
        if (tableDefinition.addFetchedId(id)) {
            notFetchedIds.add(id);
        }
    }

    for (Entry<String, TableDefinition> fk : tableDefinition.getForeignKeys().entrySet()) {
        Set<Integer> notFetchedForeignIds = new HashSet<Integer>();

        for (int i = 0; i < resultTable.getRowCount(); i++) {
            Integer id = (Integer) resultTable.getValue(i, tableDefinition.getPrimaryKey());
            if (!notFetchedIds.contains(id)) {
                continue;
            }

            Integer fkValue = (Integer) resultTable.getValue(i, fk.getKey());
            if (!fk.getValue().getFetchedIds().contains(fkValue)) {
                notFetchedForeignIds.add(fkValue);
            }
        }

        if (!notFetchedForeignIds.isEmpty()) {
            addTable(connection, tables, fk.getValue(), fk.getValue().getPrimaryKey(), notFetchedForeignIds);
        }
    }

    ColumnReplacementTable replacementTable = new ColumnReplacementTable(resultTable);
    replacementTable.addReplacement("creator", 1);
    replacementTable.addReplacement("retired_by", 1);
    replacementTable.addReplacement("changed_by", 1);

    resultTable = replacementTable;

    if (!tableDefinition.getExcludedColumns().isEmpty()) {
        resultTable = DefaultColumnFilter.excludedColumnsTable(resultTable,
                tableDefinition.getExcludedColumns().toArray(new String[0]));
    }

    tables.add(resultTable);

    if (!notFetchedIds.isEmpty()) {
        for (Reference reference : tableDefinition.getReferences()) {
            addTable(connection, tables, reference.getTable(), reference.getForeingKey(), notFetchedIds);
        }
    }
}

From source file:com.romeikat.datamessie.core.base.util.CollectionUtil.java

public <T> Set<T> getOthers(final Collection<T> objects, final T object) {
    final Set<T> others = Sets.newHashSet(objects);
    others.remove(object);
    return others;
}

From source file:com.puppycrawl.tools.checkstyle.XDocsPagesTest.java

private static void validatePropertySectionProperties(String fileName, String sectionName, Node subSection,
        Check check, Set<String> properties) {
    boolean skip = true;
    boolean didTokens = false;

    for (Node row : getChildrenElements(getFirstChildElement(subSection))) {
        if (skip) {
            skip = false;/*from  ww  w  .  ja  va 2  s  .  c om*/
            continue;
        }
        Assert.assertFalse(fileName + " section '" + sectionName + "' should have token properties last",
                didTokens);

        final List<Node> columns = new ArrayList<>(getChildrenElements(row));

        final String propertyName = columns.get(0).getTextContent();
        Assert.assertTrue(
                fileName + " section '" + sectionName + "' should not contain the property: " + propertyName,
                properties.remove(propertyName));

        if ("tokens".equals(propertyName)) {
            Assert.assertEquals(
                    fileName + " section '" + sectionName + "' should have the basic token description",
                    "tokens to check", columns.get(1).getTextContent());
            Assert.assertEquals(
                    fileName + " section '" + sectionName + "' should have all the acceptable tokens",
                    "subset of tokens " + getTokenText(check.getAcceptableTokens(), check.getRequiredTokens()),
                    columns.get(2).getTextContent().replaceAll("\\s+", " ").trim());
            Assert.assertEquals(fileName + " section '" + sectionName + "' should have all the default tokens",
                    getTokenText(check.getDefaultTokens(), check.getRequiredTokens()),
                    columns.get(3).getTextContent().replaceAll("\\s+", " ").trim());
            didTokens = true;
        } else {
            Assert.assertFalse(
                    fileName + " section '" + sectionName + "' should have a description for " + propertyName,
                    columns.get(1).getTextContent().trim().isEmpty());
            Assert.assertFalse(
                    fileName + " section '" + sectionName + "' should have a type for " + propertyName,
                    columns.get(2).getTextContent().trim().isEmpty());
            // default can be empty string
        }
    }
}

From source file:de.blizzy.documentr.subscription.SubscriptionStore.java

public void unsubscribe(String projectName, String branchName, String path, User user) throws IOException {
    ILockedRepository repo = null;/*from w w  w.  j  a v  a2  s .c  o m*/
    try {
        repo = getOrCreateRepository(user);
        String json = BlobUtils.getHeadContent(repo.r(), user.getLoginName() + SUBSCRIPTIONS_SUFFIX);
        if (StringUtils.isNotBlank(json)) {
            Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
            List<Page> pagesList = gson.fromJson(json, new TypeToken<List<Page>>() {
            }.getType());
            Set<Page> pages = Sets.newHashSet(pagesList);
            Page page = new Page(projectName, branchName, path);
            if (pages.remove(page)) {
                Git git = Git.wrap(repo.r());
                if (!pages.isEmpty()) {
                    json = gson.toJson(pages);
                    File workingDir = RepositoryUtil.getWorkingDir(repo.r());
                    File file = new File(workingDir, user.getLoginName() + SUBSCRIPTIONS_SUFFIX);
                    FileUtils.writeStringToFile(file, json, Charsets.UTF_8);
                    git.add().addFilepattern(user.getLoginName() + SUBSCRIPTIONS_SUFFIX).call();
                } else {
                    git.rm().addFilepattern(user.getLoginName() + SUBSCRIPTIONS_SUFFIX).call();
                }

                PersonIdent ident = new PersonIdent(user.getLoginName(), user.getEmail());
                git.commit().setAuthor(ident).setCommitter(ident)
                        .setMessage(user.getLoginName() + SUBSCRIPTIONS_SUFFIX).call();
            }
        }
    } catch (GitAPIException e) {
        throw new IOException(e);
    } finally {
        Closeables.closeQuietly(repo);
    }
}