Example usage for java.util Set stream

List of usage examples for java.util Set stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:com.yqboots.security.web.form.RoleFormConverter.java

/**
 * Gets the id of groups./*w  ww .  j  av a 2 s. c om*/
 *
 * @param groups groups
 * @return id of groups
 */
private Long[] getGroups(Set<Group> groups) {
    List<Long> results = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(groups)) {
        results.addAll(groups.stream().map(Group::getId).collect(Collectors.toList()));
    }

    return results.toArray(new Long[results.size()]);
}

From source file:com.thoughtworks.go.server.service.AdminsConfigService.java

private BulkUpdateAdminsResult validateUsersAndRolesForBulkUpdate(List<String> usersToRemove,
        List<String> rolesToRemove, Set<Admin> existingAdmins) {
    Set<CaseInsensitiveString> existingAdminNames = existingAdmins.stream().map(Admin::getName)
            .collect(Collectors.toSet());
    Sets.SetView<CaseInsensitiveString> invalidUsersToRemove = Sets.difference(caseInsensitive(usersToRemove),
            existingAdminNames);//from  w w  w  . ja  v a 2s  .  com
    Sets.SetView<CaseInsensitiveString> invalidRolesToRemove = Sets.difference(caseInsensitive(rolesToRemove),
            existingAdminNames);
    BulkUpdateAdminsResult result = new BulkUpdateAdminsResult();
    if (invalidUsersToRemove.size() > 0) {
        result.setNonExistentUsers(invalidUsersToRemove);
        result.unprocessableEntity(
                "Update failed because some users or roles do not exist under super admins.");
    }
    if (invalidRolesToRemove.size() > 0) {
        result.setNonExistentRoles(invalidRolesToRemove);
        result.unprocessableEntity(
                "Update failed because some users or roles do not exist under super admins.");
    }
    return result;
}

From source file:org.openlmis.fulfillment.service.request.RequestParameters.java

/**
 * Split this request parameters into two smaller chunks.
 *///from www .  j av a  2 s. c o m
public Pair<RequestParameters, RequestParameters> split() {
    if (params.isEmpty()) {
        return Pair.of(this, null);
    }

    Set<Entry<String, List<String>>> entries = params.entrySet();

    if (entries.stream().noneMatch(entry -> entry.getValue().size() > 1)) {
        return Pair.of(this, null);
    }

    Map.Entry<String, List<String>> max = entries.iterator().next();
    for (Map.Entry<String, List<String>> entry : entries) {
        if (entry.getValue().size() > max.getValue().size()) {
            max = entry;
        }
    }

    RequestParameters left = init().setAll(this);
    RequestParameters right = init().setAll(this);

    left.params.remove(max.getKey());
    right.params.remove(max.getKey());

    List<String> list = max.getValue();
    int chunkSize = list.size() / 2;
    int leftOver = list.size() % 2;

    List<String> leftCollection = list.subList(0, chunkSize + leftOver);
    List<String> rightCollection = list.subList(chunkSize + leftOver, list.size());

    left.set(max.getKey(), leftCollection);
    right.set(max.getKey(), rightCollection);

    return Pair.of(left, right);
}

From source file:delfos.dataset.basic.item.ContentDatasetDefault.java

/**
 * Crea un dataset de contenido a partir de los items que contiene.
 *
 * @param items/*from w w  w  .ja va  2 s.  co  m*/
 */
public ContentDatasetDefault(Set<Item> items) {
    this();
    items.stream().forEach((item) -> add(item));
}

From source file:com.github.horrorho.inflatabledonkey.chunk.engine.ChunkEngine.java

default Map<ChunkServer.ChunkReference, Chunk> fetch(HttpClient httpClient,
        Set<StorageHostChunkListContainer> storageHostChunkListContainerList,
        Function<ChunkServer.ChunkReference, Optional<byte[]>> getKeyEncryptionKey) {

    return storageHostChunkListContainerList.stream()
            .map(storageHostChunkList -> fetch(httpClient, storageHostChunkList, getKeyEncryptionKey))
            .map(Map::entrySet).flatMap(Collection::stream)
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

From source file:org.n52.iceland.config.json.JsonSettingsEncoder.java

public Map<SettingDefinitionGroup, Set<SettingDefinition<?, ?>>> sortByGroup(
        Set<SettingDefinition<?, ?>> defs) {
    return defs.stream().collect(groupingBy(def -> def.getGroup(Datasource.ADVANCED_GROUP), toSet()));
}

From source file:nu.yona.server.test.util.BaseSpringIntegrationTest.java

@Before
public final void setUpPerTestBase() {
    MockitoAnnotations.initMocks(this);

    Map<Class<?>, Repository<?, ?>> repositoriesMap = new HashMap<>();
    repositoriesMap.put(User.class, userRepository);
    repositoriesMap.put(UserAnonymized.class, userAnonymizedRepository);
    repositoriesMap.putAll(getRepositories());
    Set<CrudRepository<?, ?>> crudRepositories = filterForCrudRepositories(repositoriesMap.values());
    crudRepositories.forEach(CrudRepository::deleteAll);
    crudRepositories.stream().filter(this::isMock).forEach(r -> JUnitUtil.setUpRepositoryMock(r));
    JUnitUtil.setUpRepositoryProviderMock(repositoriesMap);
}

From source file:org.n52.iceland.config.json.JsonSettingsEncoder.java

public ObjectNode encode(Set<SettingDefinition<?, ?>> settings) {
    return settings.stream().sorted().collect(nodeFactory::objectNode,
            (j, def) -> j.set(def.getKey(), encode(def)), ObjectNode::setAll);
}

From source file:pt.ist.fenix.ui.spring.NewsController.java

@RequestMapping
public String news(Model model, @RequestParam(defaultValue = "5", required = false) int posts) {
    model.addAttribute("posts", posts);
    Set<Category> bookmarks = Authenticate.getUser().getBookmarksSet();
    if (!bookmarks.isEmpty()) {
        model.addAttribute("allPosts",
                bookmarks.stream().flatMap(cat -> cat.getPostsSet().stream()).filter(Post::isVisible)
                        .filter(Post::isAccessible).sorted(Post.CREATION_DATE_COMPARATOR).limit(posts)
                        .collect(Collectors.toList()));
    } else if (Bennu.getInstance().getDefaultSite() != null) {
        model.addAttribute("allPosts",
                Bennu.getInstance().getDefaultSite().getPostSet().stream().filter(Post::isVisible)
                        .filter(Post::isAccessible).sorted(Post.CREATION_DATE_COMPARATOR).limit(posts)
                        .collect(Collectors.toList()));
    }//from  w w w .ja v a 2s . c o  m
    return "fenix-learning/news";
}

From source file:me.adaptive.core.data.api.AccountMemberEntityService.java

public List<Member> toMemberList(Set<AccountMemberEntity> accountMemberEntityList) {
    List<Member> members = new ArrayList<>(accountMemberEntityList.size());
    members.addAll(accountMemberEntityList.stream().map(this::toMember).collect(Collectors.toList()));
    return members;
}