Example usage for java.util Set clear

List of usage examples for java.util Set clear

Introduction

In this page you can find the example usage for java.util Set clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this set (optional operation).

Usage

From source file:org.apache.syncope.core.rest.data.AbstractAttributableDataBinder.java

public PropagationByResource fillVirtual(final AbstractAttributable attributable,
        final Set<String> vAttrsToBeRemoved, final Set<AttributeMod> vAttrsToBeUpdated,
        final AttributableUtil attrUtil) {

    PropagationByResource propByRes = new PropagationByResource();

    final Set<ExternalResource> externalResources = new HashSet<ExternalResource>();
    if (attributable instanceof AbstractSubject) {
        externalResources.addAll(((AbstractSubject) attributable).getResources());
    }//w ww  .j a v  a  2 s .c o m

    if (attributable instanceof Membership) {
        externalResources.clear();
        externalResources.addAll(((Membership) attributable).getSyncopeUser().getResources());
    }

    // 1. virtual attributes to be removed
    for (String vAttrToBeRemoved : vAttrsToBeRemoved) {
        AbstractVirSchema virSchema = getVirSchema(vAttrToBeRemoved, attrUtil.virSchemaClass());
        if (virSchema != null) {
            AbstractVirAttr virAttr = attributable.getVirAttr(virSchema.getName());
            if (virAttr == null) {
                LOG.debug("No virtual attribute found for schema {}", virSchema.getName());
            } else {
                attributable.removeVirAttr(virAttr);
                virAttrDAO.delete(virAttr);
            }

            for (ExternalResource resource : resourceDAO.findAll()) {
                for (AbstractMappingItem mapItem : attrUtil.getMappingItems(resource,
                        MappingPurpose.PROPAGATION)) {
                    if (virSchema.getName().equals(mapItem.getIntAttrName())
                            && mapItem.getIntMappingType() == attrUtil.virIntMappingType()
                            && externalResources.contains(resource)) {

                        propByRes.add(ResourceOperation.UPDATE, resource.getName());

                        // Using virtual attribute as AccountId must be avoided
                        if (mapItem.isAccountid() && virAttr != null && !virAttr.getValues().isEmpty()) {
                            propByRes.addOldAccountId(resource.getName(), virAttr.getValues().get(0));
                        }
                    }
                }
            }
        }
    }

    LOG.debug("Virtual attributes to be removed:\n{}", propByRes);

    // 2. virtual attributes to be updated
    for (AttributeMod vAttrToBeUpdated : vAttrsToBeUpdated) {
        AbstractVirSchema virSchema = getVirSchema(vAttrToBeUpdated.getSchema(), attrUtil.virSchemaClass());
        AbstractVirAttr virAttr = null;
        if (virSchema != null) {
            virAttr = attributable.getVirAttr(virSchema.getName());
            if (virAttr == null) {
                virAttr = attrUtil.newVirAttr();
                setVirAttrSchema(attributable, virAttr, virSchema);
                if (virAttr.getSchema() == null) {
                    LOG.debug("Ignoring {} because no valid schema or template was found", vAttrToBeUpdated);
                } else {
                    attributable.addVirAttr(virAttr);
                }
            }
        }

        if (virSchema != null && virAttr != null && virAttr.getSchema() != null) {
            for (ExternalResource resource : resourceDAO.findAll()) {
                for (AbstractMappingItem mapItem : attrUtil.getMappingItems(resource,
                        MappingPurpose.PROPAGATION)) {
                    if (virSchema.getName().equals(mapItem.getIntAttrName())
                            && mapItem.getIntMappingType() == attrUtil.virIntMappingType()
                            && externalResources.contains(resource)) {

                        propByRes.add(ResourceOperation.UPDATE, resource.getName());
                    }
                }
            }

            final List<String> values = new ArrayList<String>(virAttr.getValues());
            values.removeAll(vAttrToBeUpdated.getValuesToBeRemoved());
            values.addAll(vAttrToBeUpdated.getValuesToBeAdded());

            virAttr.setValues(values);

            // Owner cannot be specified before otherwise a virtual attribute remove will be invalidated.
            virAttr.setOwner(attributable);
        }
    }

    LOG.debug("Virtual attributes to be added:\n{}", propByRes);

    return propByRes;
}

From source file:com.ah.ui.actions.admin.UsersAction.java

private void setOptions4GMOperator() throws Exception {
    if (getDataSource().getUserGroup().getGroupName().equals(HmUserGroup.GM_OPERATOR)) {
        // local user group
        if (updateLocalUserGroup) {
            Set<LocalUserGroup> groups = getDataSource().getLocalUserGroups();
            getDataSource().removeLocalUserGroups();
            groups.clear();

            if (localUserGroups != null) {

                for (Long id : localUserGroups) {
                    LocalUserGroup group = findBoById(LocalUserGroup.class, id);
                    if (group != null) {
                        groups.add(group);
                    }/*  w ww  .ja v  a  2 s . c  o m*/
                }

                if (groups.size() != localUserGroups.size()) {
                    String tempStr[] = { getText("admin.user.avaliable.pskUserGroup") };
                    addActionError(getText("info.ssid.warning.deleteRecord", tempStr));
                }
            }
            if (groups.size() > 0) {
                getDataSource().setLocalUserGroups(groups);
                getDataSource().addLocalUserGroups();
            }
        } else {
            getDataSource().removeLocalUserGroups();
            getDataSource().getLocalUserGroups().clear();
        }

        // ssid profile
        if (updateSSIDProfile) {
            Set<SsidProfile> profiles = getDataSource().getSsidProfiles();
            getDataSource().removeSsidProfiles();
            profiles.clear();

            if (ssidProfiles != null) {

                for (Long id : ssidProfiles) {
                    SsidProfile profile = findBoById(SsidProfile.class, id);
                    if (profile != null) {
                        profiles.add(profile);
                    }
                }

                if (profiles.size() != ssidProfiles.size()) {
                    String tempStr[] = { getText("admin.user.avaliable.ssidProfile") };
                    addActionError(getText("info.ssid.warning.deleteRecord", tempStr));
                }
            }
            if (profiles.size() > 0) {
                getDataSource().setSsidProfiles(profiles);
                getDataSource().addSsidProfiles();
            }
        } else {
            getDataSource().removeSsidProfiles();
            getDataSource().getSsidProfiles().clear();
        }
    } else {
        getDataSource().removeLocalUserGroups();
        getDataSource().getLocalUserGroups().clear();
        getDataSource().removeSsidProfiles();
        getDataSource().getSsidProfiles().clear();
    }

    if (isEasyMode()) {
        getDataSource().removeSsidProfiles();
        getDataSource().getSsidProfiles().clear();
    }
}

From source file:org.apache.ctakes.ytex.kernel.metric.ConceptSimilarityServiceImpl.java

@Override
public Object[] getBestLCS(Set<String> lcses, boolean intrinsicIC, Map<String, Double> conceptFilter) {
    Map<String, Double> lcsICMap = new HashMap<String, Double>(lcses.size());
    // if (isPreload()) {
    // look in conceptInfoMap for info content
    for (String lcs : lcses) {
        lcsICMap.put(lcs, getIC(lcs, intrinsicIC));
        // }/*from w  w w  .j ava 2 s.  co  m*/
        // } else {
        // // load info content on demand
        // Map<String, FeatureRank> frMap = getICOnDemand(lcses,
        // intrinsicIC);
        // for (Map.Entry<String, FeatureRank> frMapEntry :
        // frMap.entrySet()) {
        // lcsICMap.put(frMapEntry.getKey(), frMapEntry.getValue()
        // .getEvaluation());
        // }
    }
    if (conceptFilter != null) {
        double currentBest = -1;
        Set<String> bestLcses = new HashSet<String>();
        for (String lcs : lcses) {
            if (conceptFilter.containsKey(lcs)) {
                double lcsEval = conceptFilter.get(lcs);
                if (currentBest == -1 || lcsEval > currentBest) {
                    bestLcses.clear();
                    bestLcses.add(lcs);
                    currentBest = lcsEval;
                } else if (currentBest == lcsEval) {
                    bestLcses.add(lcs);
                }
            }
        }
        if (currentBest < 0)
            currentBest = 0d;
        if (bestLcses.size() > 0) {
            return this.getBestLCS(bestLcses, lcsICMap);
        } else {
            // no lcses made the cut
            return null;
        }
    } else {
        // unfiltered - get the lowest ic
        return this.getBestLCS(lcses, lcsICMap);
    }
}

From source file:tools.xor.logic.DefaultUpdate3Set.java

public void testCase13() {
    C = taskDao.findById(C.getId());//  w ww  .  j  a  va2  s  .c  o m
    Set<Task> children = new HashSet<Task>();
    children.add(C);

    // Setup the bi-directional link
    A = taskDao.findById(A.getId());
    A.setTaskChildren(children);
    C.setTaskParent(A);
    taskDao.saveOrUpdate(A);

    A = (Task) aggregateService.read(A, getSettings());
    C = A.getTaskChildren().iterator().next();
    assert (C.getTaskParent() != null);

    // Remove child1 and add child2
    children = A.getTaskChildren();
    children.clear();
    children.add(B);
    B.setTaskParent(null);

    Settings settings = getSettings();
    settings.setInterceptor(new Interceptor() {
        // check the number of actions in each object
        private void checkNumber(BusinessObject dataObject, List<Executable> actions) {
            assert (actions.size() == 1);
        }

        @Override
        public void preBiDirActionStage(Map<PropertyKey, List<Executable>> actions) {
            // check the action queue to see if the correct number of actions are present
            assert (actions.size() == 3);

            for (Map.Entry<PropertyKey, List<Executable>> entry : actions.entrySet())
                checkNumber(entry.getKey().getDataObject(), entry.getValue());
        }
    });
    A = (Task) aggregateService.update(A, settings);

    A = taskDao.findById(A.getId());
    B = taskDao.findById(B.getId());
    C = taskDao.findById(C.getId());

    A = (Task) aggregateService.read(A, getSettings());
    B = (Task) aggregateService.read(B, getSettings());
    C = (Task) aggregateService.read(C, getSettings());

    assert (C.getTaskParent() == null);
    assert (A.getTaskChildren() != null && A.getTaskChildren().size() == 1);
    assert (B.getId() == A.getTaskChildren().iterator().next().getId());
}

From source file:org.apache.geode.distributed.internal.SharedConfiguration.java

public Object[] getAllJars(Set<String> groups) throws Exception {
    Set<String> jarsAdded = new HashSet<String>();
    Object[] jars = new Object[2];

    for (String group : groups) {
        Configuration configuration = getConfiguration(group);
        if (configuration != null) {
            jarsAdded.addAll(configuration.getJarNames());
        }//from w w w.  j av  a  2s  .  c  o m
    }
    int numJars = jarsAdded.size();
    jarsAdded.clear();

    if (numJars > 0) {
        String[] jarNames = new String[numJars];
        byte[][] jarBytes = new byte[numJars][];
        int ctr = 0;

        for (String group : groups) {
            Configuration configuration = getConfiguration(group);
            if (configuration != null) {
                Set<String> jarNameSet = configuration.getJarNames();
                for (String jarName : jarNameSet) {
                    String groupDirPath = FilenameUtils.concat(configDirPath, group);
                    if (!jarsAdded.contains(jarName)) {
                        String jarFilePath = FilenameUtils.concat(groupDirPath, jarName);
                        jarNames[ctr] = jarName;
                        jarBytes[ctr] = FileUtils.readFileToByteArray(new File(jarFilePath));
                        ctr++;
                    }
                }
            }
        }

        jars[0] = jarNames;
        jars[1] = jarBytes;
    }
    return jars;
}

From source file:org.apache.geode.internal.cache.IncrementalBackupDUnitTest.java

/**
 * Invokes {@link DistributedSystem#disconnect()} on a member.
 * // ww  w .j a v  a  2  s.com
 * @param disconnectVM a member of the distributed system to disconnect.
 * @param testVM a member of the distributed system to test for the missing member (just
 *        disconnected).
 */
private PersistentID disconnect(final VM disconnectVM, final VM testVM) {
    final PersistentID id = disconnectVM.invoke(() -> {
        PersistentID persistentID = null;
        Collection<DiskStore> diskStores = ((InternalCache) getCache()).listDiskStores();
        for (DiskStore diskStore : diskStores) {
            if (diskStore.getName().equals("fooStore")) {
                persistentID = ((DiskStoreImpl) diskStore).getPersistentID();
                break;
            }
        }

        getSystem().disconnect();

        return persistentID;
    });

    final Set<PersistentID> missingMembers = new HashSet<>();
    Wait.waitForCriterion(new WaitCriterion() {
        @Override
        public boolean done() {
            missingMembers.clear();
            missingMembers.addAll(getMissingMembers(testVM));

            return missingMembers.contains(id);
        }

        @Override
        public String description() {
            return "[IncrementalBackupDUnitTest] Waiting for missing member " + id;
        }
    }, 10000, 500, false);

    return id;
}

From source file:tools.xor.logic.DefaultUpdate3Set.java

public void testCase4() {
    C = taskDao.findById(C.getId());/*from   w w  w. java  2  s.c  o  m*/
    Set<Task> children = new HashSet<Task>();
    children.add(C);

    // Setup the bi-directional link
    A = taskDao.findById(A.getId());
    A.setTaskChildren(children);
    C.setTaskParent(A);
    taskDao.saveOrUpdate(A);

    A = (Task) aggregateService.read(A, getSettings());
    C = A.getTaskChildren().iterator().next();
    assert (C.getTaskParent() != null);

    // Remove child1 and add child2
    children = A.getTaskChildren();
    children.clear();
    children.add(B);
    A.setAlternateTask(C);
    C.setTaskParent(null);
    B.setTaskParent(A);

    Settings settings = getSettings();
    settings.setInterceptor(new Interceptor() {
        // check the number of actions in each object
        private void checkNumber(BusinessObject dataObject, List<Executable> actions) {
            Task task = (Task) dataObject.getInstance();
            if (task.getName().equals(A_NAME)) {
                assert (actions.size() == 1); // SetUpdateAction
                assert (SetUpdateAction.class.isAssignableFrom(actions.get(0).getClass()));
            } else
                assert (actions.size() == 2);
        }

        @Override
        public void preBiDirActionStage(Map<PropertyKey, List<Executable>> actions) {
            // check the action queue to see if the correct number of actions are present
            assert (actions.size() == 3);

            for (Map.Entry<PropertyKey, List<Executable>> entry : actions.entrySet())
                checkNumber(entry.getKey().getDataObject(), entry.getValue());
        }
    });
    A = (Task) aggregateService.update(A, settings);

    A = taskDao.findById(A.getId());
    B = taskDao.findById(B.getId());

    A = (Task) aggregateService.read(A, getSettings());
    B = (Task) aggregateService.read(B, getSettings());

    assert (A.getTaskChildren() != null && A.getTaskChildren().size() == 1);
    assert (B.getId() == A.getTaskChildren().iterator().next().getId());
}

From source file:tools.xor.logic.DefaultUpdate3Set.java

public void testCase12() {
    C = taskDao.findById(C.getId());/*www .j a v a2 s  . c  om*/
    Set<Task> children = new HashSet<Task>();
    children.add(C);

    // Setup the bi-directional link
    A = taskDao.findById(A.getId());
    A.setTaskChildren(children);
    C.setTaskParent(A);
    taskDao.saveOrUpdate(A);

    A = (Task) aggregateService.read(A, getSettings());
    C = A.getTaskChildren().iterator().next();
    assert (C.getTaskParent() != null);

    // Remove child1 and add child2
    children = A.getTaskChildren();
    children.clear();
    children.add(B);
    B.setTaskParent(A);

    Settings settings = getSettings();
    settings.setInterceptor(new Interceptor() {
        // check the number of actions in each object
        private void checkNumber(BusinessObject dataObject, List<Executable> actions) {
            Task task = (Task) dataObject.getInstance();
            if (task.getName().equals(B_NAME)) {
                assert (actions.size() == 2);
            } else
                assert (actions.size() == 1);
        }

        @Override
        public void preBiDirActionStage(Map<PropertyKey, List<Executable>> actions) {
            // check the action queue to see if the correct number of actions are present
            assert (actions.size() == 3);

            for (Map.Entry<PropertyKey, List<Executable>> entry : actions.entrySet())
                checkNumber(entry.getKey().getDataObject(), entry.getValue());
        }
    });
    A = (Task) aggregateService.update(A, settings);

    A = taskDao.findById(A.getId());
    B = taskDao.findById(B.getId());
    C = taskDao.findById(C.getId());

    A = (Task) aggregateService.read(A, getSettings());
    B = (Task) aggregateService.read(B, getSettings());
    C = (Task) aggregateService.read(C, getSettings());

    assert (C.getTaskParent() == null);
    assert (A.getTaskChildren() != null && A.getTaskChildren().size() == 1);
    assert (B.getId() == A.getTaskChildren().iterator().next().getId());
}

From source file:tools.xor.logic.DefaultUpdate3Set.java

public void testCase5() {
    C = taskDao.findById(C.getId());//from  ww  w . ja  v  a2  s.c  om
    Set<Task> children = new HashSet<Task>();
    children.add(C);

    // Setup the bi-directional link
    A = taskDao.findById(A.getId());
    A.setTaskChildren(children);
    C.setTaskParent(A);
    taskDao.saveOrUpdate(A);

    A = (Task) aggregateService.read(A, getSettings());
    C = A.getTaskChildren().iterator().next();
    assert (C.getTaskParent() != null);

    // Remove child1 and add child2
    children = A.getTaskChildren();
    children.clear();
    children.add(B);
    A.setAlternateTask(C);
    C.setTaskParent(null);
    B.setTaskParent(null); // We are explicitly not setting the backRef in the input. This should automatically be set by the framework.

    Settings settings = getSettings();
    settings.setInterceptor(new Interceptor() {
        // check the number of actions in each object
        private void checkNumber(BusinessObject dataObject, List<Executable> actions) {
            Task task = (Task) dataObject.getInstance();
            if (task.getName().equals(A_NAME)) {
                assert (actions.size() == 1); // SetUpdateAction
                assert (SetUpdateAction.class.isAssignableFrom(actions.get(0).getClass()));
            } else if (task.getName().equals(B_NAME))
                assert (actions.size() == 1);
            else
                assert (actions.size() == 2);
        }

        @Override
        public void preBiDirActionStage(Map<PropertyKey, List<Executable>> actions) {
            // check the action queue to see if the correct number of actions are present
            assert (actions.size() == 3);

            for (Map.Entry<PropertyKey, List<Executable>> entry : actions.entrySet())
                checkNumber(entry.getKey().getDataObject(), entry.getValue());
        }
    });
    A = (Task) aggregateService.update(A, settings);

    A = taskDao.findById(A.getId());
    B = taskDao.findById(B.getId());

    A = (Task) aggregateService.read(A, getSettings());
    B = (Task) aggregateService.read(B, getSettings());

    assert (A.getTaskChildren() != null && A.getTaskChildren().size() == 1);
    assert (B.getId() == A.getTaskChildren().iterator().next().getId());
    assert (B.getTaskParent() != null && B.getTaskParent().getName().equals(A.getName()));
}

From source file:jp.go.nict.langrid.serviceexecutor.db.DictionaryDataBase.java

/**
 * //  ww w .  j a  v a 2s  .c om
 * 
 */
public Collection<Translation> getTranslation(Language headLang, Language targetLang, String headword,
        MatchingMethod matchingMethod) throws SQLException {
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    String sql = null;
    try {
        String hl = headLang.getCode();
        String tl = targetLang.getCode();
        Collection<Translation> collection = new ArrayList<Translation>();
        con = manager.getConnection();
        sql = createBilingualDictionarySQL(hl, tl, headword, matchingMethod);
        //         System.out.println(sql);      //###
        st = con.createStatement();
        rs = st.executeQuery(sql);
        Translation current = new Translation();
        Set<String> currentTargetWords = new HashSet<String>();
        while (rs.next()) {
            String head = rs.getString(hl);
            String target = rs.getString(tl);
            if (head == null || head.trim().length() == 0)
                continue;
            if (target == null || target.trim().length() == 0)
                continue;

            if (!head.equals(current.getHeadWord())) {
                if (current.getHeadWord() != null) {
                    current.setTargetWords(currentTargetWords.toArray(new String[] {}));
                    collection.add(current);
                    if (collection.size() == maxCount)
                        break;
                }
                current = new Translation(head, new String[] {});
                currentTargetWords.clear();
            }
            currentTargetWords.add(target);
        }
        if (current.getHeadWord() != null && collection.size() < maxCount) {
            current.setTargetWords(currentTargetWords.toArray(new String[] {}));
            collection.add(current);
        }
        //         System.out.println(collection.size() + " hits.");   //###
        return collection;
    } catch (SQLException e) {
        logger.log(Level.WARNING, "exception at SQL: " + sql, e);
        throw e;
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
            }
        }
        if (st != null) {
            try {
                st.close();
            } catch (SQLException e) {
            }
        }
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
            }
        }
    }
}