Example usage for java.util Set addAll

List of usage examples for java.util Set addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:de.micromata.genome.gwiki.model.GWikiSettingsPropsArtefakt.java

private void cleanupEmptyProps(GWikiProps props) {
    Set<String> keys = new HashSet<String>();
    keys.addAll(props.getMap().keySet());
    for (String key : keys) {
        if (StringUtils.isEmpty(props.getStringValue(key)) == true) {
            props.remove(key);/*from  ww w.  java 2s  .  com*/
        }
    }
}

From source file:net.lldp.checksims.submission.Submission.java

/**
 * Recursively find all files matching in a directory.
 *
 * @param directory Directory to search in
 * @param glob Match pattern used to identify files to include
 * @return List of all matching files in this directory and subdirectories
 *//*from w  w  w .ja  v  a  2 s  . c  om*/
static Set<File> getAllMatchingFiles(File directory, String glob, boolean recursive)
        throws NoSuchFileException, NotDirectoryException {
    checkNotNull(directory);
    checkNotNull(glob);
    checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty");

    if (!directory.exists()) {
        throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath());
    } else if (!directory.isDirectory()) {
        throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath());
    }

    PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob);

    Set<File> allFiles = new HashSet<>();
    Logger logs = LoggerFactory.getLogger(Submission.class);

    if (recursive) {
        logs.trace("Recursively traversing directory " + directory.getName());
    }

    // Get files in this directory
    File[] contents = directory
            .listFiles((f) -> matcher.matches(Paths.get(f.getAbsolutePath()).getFileName()) && f.isFile());

    // TODO consider mapping to absolute paths?

    // Add this directory
    Collections.addAll(allFiles, contents);

    // Get subdirectories
    File[] subdirs = directory.listFiles(File::isDirectory);

    // Recursively call on all subdirectories if specified
    if (recursive) {
        for (File subdir : subdirs) {
            allFiles.addAll(getAllMatchingFiles(subdir, glob, true));
        }
    }

    return allFiles;
}

From source file:org.openlmis.fulfillment.ExposedMessageSourceIntegrationTest.java

@Test
public void shouldBePairsOfConstantValueAndPropertyKey() throws IllegalAccessException {
    Set<String> propertyKeys = getPropertyKeys();
    Set<String> constantValues = getConstantValues(MessageKeys.class);

    Set<String> all = new HashSet<>();
    all.addAll(propertyKeys);
    all.addAll(constantValues);//w w  w .  j  ava 2s .c o  m

    for (String key : all) {
        assertThat("Missing constant value for key: " + key, constantValues.contains(key), is(true));
        assertThat("Missing property entry in messages.properties for key: " + key, propertyKeys.contains(key),
                is(true));
    }
}

From source file:com.netflix.loadbalancer.ServerListLoabBalancerTest.java

@Test
public void testChooseServer() {
    assertNotNull(lb);/*from w  w w. j av  a2  s  .c o  m*/
    Set<Server> result = new HashSet<Server>();
    for (int i = 0; i < 100; i++) {
        Server s = lb.chooseServer(null);
        result.add(s);
    }
    Set<Server> expected = new HashSet<Server>();
    expected.addAll(serverList);
    assertEquals(expected, result);
}

From source file:net.eusashead.hateoas.response.impl.OptionsResponseBuilderImplTest.java

@Test
public void testAllHeaders() throws Exception {
    Entity entity = new Entity("foo");
    ResponseEntity<Entity> response = builder.entity(entity).allow(HttpMethod.GET, HttpMethod.PUT).build();
    Assert.assertNotNull(response);//from   w ww  .  j ava2 s.co m
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    Assert.assertEquals(entity, response.getBody());
    Assert.assertNotNull(response.getHeaders().getAllow());
    Set<HttpMethod> allow = new HashSet<HttpMethod>();
    allow.addAll(Arrays.asList(HttpMethod.GET, HttpMethod.PUT));
    Assert.assertEquals(allow, response.getHeaders().getAllow());
}

From source file:net.hillsdon.reviki.web.vcintegration.SpecialPagePopulatingPageStore.java

@Override
public Set<PageReference> list() throws PageStoreException {
    Set<PageReference> list = super.list();
    list.addAll(SPECIAL_PAGES_WITH_CONTENT);
    list.addAll(SPECIAL_PAGES_WITHOUT_CONTENT);
    return list;/*from  ww w.  j  av  a2s. com*/
}

From source file:dk.nsi.haiba.lprimporter.dao.impl.LPRDAOComposite.java

@Override
public Collection<Date> getInDatesForSygehusKoder(String code, String secondaryCode) {
    Set<Date> returnValue = new HashSet<Date>();
    returnValue.addAll(minipasLPRDAO.getInDatesForSygehusKoder(code, secondaryCode));
    returnValue.addAll(ssiLPRDAO.getInDatesForSygehusKoder(code, secondaryCode));
    return new ArrayList<Date>(returnValue);
}

From source file:hyldap.HyHcNewUserGroupBean.java

public List<Long> groups(String username, LdapConfig config, LdapOperations ldap, RoleProvider provider,
        AttributeSet attrSet) {/*from   ww  w  .  j  ava2  s. c  o  m*/

    log.debug("groups for " + username);
    Set<String> groupNames = new HashSet<String>();
    groupNames.addAll(attrSet.getAll(GROUP_MEMBER));
    groupNames.addAll(attrSet.getAll(GROUP_OWNER));
    if (groupNames.isEmpty()) {
        throw new ValidationException(username + " has no attributes " + GROUP_MEMBER + " or " + GROUP_OWNER);
    }

    List<Long> groups = new ArrayList<Long>();
    for (String grpName : groupNames) {
        log.debug("grpName " + grpName);
        if (allowedGroups.containsKey(grpName)) {
            log.debug("grpName matched " + grpName);
            String grpOmeName = (String) allowedGroups.get(grpName);
            log.debug("grpName matched " + grpOmeName);
            groups.add(provider.createGroup(grpOmeName, null, false));
            log.debug("grpName matched, adding group 'user'");
            groups.add(new Long(1));
        }
    }
    return groups;

}

From source file:com.aurel.track.admin.customize.lists.systemOption.IssueTypeBL.java

/**
 * Load all possible item types which can be created by the user
 * @param personID/*from  w  w w  . j  a  v a2s . c o  m*/
 * @param locale
 * @return
 */
public static List<TListTypeBean> loadAllByPerson(Integer personID, Locale locale) {
    //get all create item role assignments for person
    List<TAccessControlListBean> accessControlListBeans = AccessBeans.loadByPersonAndRight(personID,
            new int[] { AccessFlagIndexes.CREATETASK, AccessFlagIndexes.PROJECTADMIN }, true);
    Map<Integer, Set<Integer>> projectsToRolesMap = new HashMap<Integer, Set<Integer>>();
    Set<Integer> allPersonRolesSet = new HashSet<Integer>();
    if (accessControlListBeans != null) {
        for (TAccessControlListBean accessControlListBean : accessControlListBeans) {
            Integer projectID = accessControlListBean.getProjectID();
            Integer roleID = accessControlListBean.getRoleID();
            allPersonRolesSet.add(roleID);
            Set<Integer> rolesInProject = projectsToRolesMap.get(projectID);
            if (rolesInProject == null) {
                rolesInProject = new HashSet<Integer>();
                projectsToRolesMap.put(projectID, rolesInProject);
            }
            rolesInProject.add(roleID);
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(accessControlListBeans.size() + " assignments found for person " + personID + ": "
                    + allPersonRolesSet.size() + " roles " + " in " + projectsToRolesMap.size() + " projects ");
        }
    } else {
        return new LinkedList<TListTypeBean>();
    }
    //gets the itemType assignments for the assigned roles 
    Map<Integer, Set<Integer>> roleToItemTypesMap = new HashMap<Integer, Set<Integer>>();
    List<TRoleListTypeBean> itemTypesInRoles = RoleBL
            .loadByRoles(GeneralUtils.createIntegerListFromCollection(allPersonRolesSet));
    if (itemTypesInRoles != null) {
        for (TRoleListTypeBean roleListTypeBean : itemTypesInRoles) {
            Integer roleID = roleListTypeBean.getRole();
            Integer itemTypeID = roleListTypeBean.getListType();
            Set<Integer> itemTypesInRoleSet = roleToItemTypesMap.get(roleID);
            if (itemTypesInRoleSet == null) {
                itemTypesInRoleSet = new HashSet<Integer>();
                roleToItemTypesMap.put(roleID, itemTypesInRoleSet);
            }
            itemTypesInRoleSet.add(itemTypeID);
        }
    }
    Set<Integer> projectSet = projectsToRolesMap.keySet();
    if (projectSet.isEmpty()) {
        LOGGER.info("No project assignment for person " + personID);
        return new LinkedList<TListTypeBean>();
    }
    //gets the project to projectType map
    List<TProjectBean> projectList = ProjectBL
            .loadByProjectIDs(GeneralUtils.createIntegerListFromCollection(projectSet));
    Map<Integer, Integer> projectToProjectTypeMap = new HashMap<Integer, Integer>();
    Set<Integer> projectTypesSet = new HashSet<Integer>();
    for (TProjectBean projectBean : projectList) {
        Integer projectTypeID = projectBean.getProjectType();
        projectToProjectTypeMap.put(projectBean.getObjectID(), projectTypeID);
        projectTypesSet.add(projectTypeID);
    }
    //gets the item type assignments for project types
    List<TPlistTypeBean> plistTypes = loadByProjectTypes(projectTypesSet.toArray());
    Map<Integer, Set<Integer>> projectTypeToItemTypesMap = new HashMap<Integer, Set<Integer>>();
    if (plistTypes != null) {
        for (TPlistTypeBean plistTypeBean : plistTypes) {
            Integer projectTypeID = plistTypeBean.getProjectType();
            Integer itemTypeID = plistTypeBean.getCategory();
            Set<Integer> itemTypesSet = projectTypeToItemTypesMap.get(projectTypeID);
            if (itemTypesSet == null) {
                itemTypesSet = new HashSet<Integer>();
                projectTypeToItemTypesMap.put(projectTypeID, itemTypesSet);
            }
            itemTypesSet.add(itemTypeID);
        }
    }
    Set<Integer> allowedItemTypeIDs = new HashSet<Integer>();
    List<TListTypeBean> allSelectableitemTypeBeans = IssueTypeBL.loadAllSelectable(locale);
    Set<Integer> allSelectableItemTypeIDs = GeneralUtils
            .createIntegerSetFromBeanList(allSelectableitemTypeBeans);
    for (Map.Entry<Integer, Set<Integer>> rolesInProjectEntry : projectsToRolesMap.entrySet()) {
        Integer projectID = rolesInProjectEntry.getKey();
        Set<Integer> roleIDs = rolesInProjectEntry.getValue();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(roleIDs.size() + " roles found in project " + projectID);
        }
        Integer projectTypeID = projectToProjectTypeMap.get(projectID);
        Set<Integer> projectTypeLimitedItemTypes = projectTypeToItemTypesMap.get(projectTypeID);
        Set<Integer> rolesLimitedItemTypes = new HashSet<Integer>();
        //get the item types limited in all roles
        for (Integer roleID : roleIDs) {
            Set<Integer> roleLimitedItemTypes = roleToItemTypesMap.get(roleID);
            if (roleLimitedItemTypes != null) {
                rolesLimitedItemTypes.addAll(roleLimitedItemTypes);
            } else {
                //at least one role has no item type limitations
                rolesLimitedItemTypes.clear();
                break;
            }
        }
        if ((projectTypeLimitedItemTypes == null || projectTypeLimitedItemTypes.isEmpty())
                && rolesLimitedItemTypes.isEmpty()) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("No roles or project type specific limitation found for project " + projectID);
            }
            return allSelectableitemTypeBeans;
        } else {
            if (projectTypeLimitedItemTypes == null || projectTypeLimitedItemTypes.isEmpty()) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Add role specific item type limitations for project " + projectID);
                }
                allowedItemTypeIDs.addAll(rolesLimitedItemTypes);
            } else {
                if (rolesLimitedItemTypes.isEmpty()) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug(
                                "Add project type specific item type limitations for project " + projectID);
                    }
                    allowedItemTypeIDs.addAll(projectTypeLimitedItemTypes);
                } else {
                    Collection<Integer> intersection = CollectionUtils.intersection(projectTypeLimitedItemTypes,
                            rolesLimitedItemTypes);
                    if (intersection != null) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug(
                                    "Add project type specific and role specific item type limitations for project "
                                            + projectID);
                        }
                        allowedItemTypeIDs.addAll(intersection);
                    }
                }
            }
        }
    }
    allowedItemTypeIDs.retainAll(allSelectableItemTypeIDs);
    if (allowedItemTypeIDs.isEmpty()) {
        return new LinkedList<TListTypeBean>();
    } else {
        return LocalizeUtil.localizeDropDownList(
                loadByIssueTypeIDs(GeneralUtils.createIntegerListFromCollection(allowedItemTypeIDs)), locale);
    }
}

From source file:com.miravtech.SBGNUtils.SBGNUtils.java

/**
 * Returns the list of the symbols for node Goes recursively for the inner
 * nodes/*  www  . j a  v  a 2s .  com*/
 * 
 * @param organism
 * @param db
 * @param filterExcludedSelection
 * @param n
 * @return
 */
public static Set<String> getSymbols(final String organism, final String db,
        final boolean filterExcludedSelection, SBGNNodeType n) {
    Set<String> ret = new HashSet<String>();
    if (n instanceof StatefulEntiyPoolNodeType) {
        StatefulEntiyPoolNodeType sepnt = (StatefulEntiyPoolNodeType) n;
        if (!(filterExcludedSelection && n.getSelected() == SelectType.EXCLUDE))
            ret.addAll(getSymbols(organism, db, sepnt));
        for (SBGNNodeType n1 : n.getInnerNodes()) {
            ret.addAll(getSymbols(organism, db, filterExcludedSelection, n1));
        }
    }
    return ret;
}