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.thinkbiganalytics.feedmgr.rest.controller.DatasourceController.java

@GET
@Path("{id}/actions/allowed")
@Produces(MediaType.APPLICATION_JSON)//from ww  w .  j ava2s . co  m
@ApiOperation("Gets the list of actions permitted for the given username and/or groups.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the actions.", response = ActionGroup.class),
        @ApiResponse(code = 404, message = "A data source with the given ID does not exist.", response = RestResponseStatus.class) })
public Response getAllowedActions(@PathParam("id") final String datasourceIdStr,
        @QueryParam("user") final Set<String> userNames, @QueryParam("group") final Set<String> groupNames) {
    log.debug("Get allowed actions for data source: {}", datasourceIdStr);

    Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames))
            .collect(Collectors.toSet());
    Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames))
            .collect(Collectors.toSet());

    return this.securityService
            .getAllowedDatasourceActions(datasourceIdStr,
                    Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet()))
            .map(g -> Response.ok(g).build())
            .orElseThrow(() -> new WebApplicationException(
                    "A data source with the given ID does not exist: " + datasourceIdStr,
                    Response.Status.NOT_FOUND));
}

From source file:it.greenvulcano.gvesb.iam.service.internal.GVUsersManager.java

@Override
public void updateUser(String username, UserInfo userInfo, Set<Role> grantedRoles, boolean enabled,
        boolean expired) throws UserNotFoundException, InvalidRoleException {
    User user = userRepository.get(username).orElseThrow(() -> new UserNotFoundException(username));
    user.setUserInfo(userInfo);//from   ww  w.j  a  v  a  2  s . co  m
    user.setEnabled(enabled);
    user.setExpired(expired);
    user.clearRoles();
    if (grantedRoles != null) {

        Predicate<Role> roleIsValid = role -> Optional.ofNullable(role.getName()).orElse("")
                .matches(Role.ROLE_PATTERN);

        Optional<Role> notValidRole = grantedRoles.stream().filter(roleIsValid.negate()).findAny();
        if (notValidRole.isPresent()) {
            throw new InvalidRoleException(notValidRole.get().getName());
        }

        for (Role r : grantedRoles) {
            user.addRole(roleRepository.get(r.getName()).orElse(r));
        }

    }
    userRepository.add(user);
}

From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.Renovator.java

private Stream<String> getAllActivationPaths() {
    Set<String> allPaths = new TreeSet<>();
    moves.forEach((n) -> {//from  w w w . j av  a  2s .c o  m
        n.visit(node -> {
            allPaths.addAll(node.getPublishedReferences());
        });
    });
    allPaths.addAll(replicatorQueue.getActivateOperations().keySet());
    return allPaths.stream();
}

From source file:com.spankingrpgs.model.characters.GameCharacter.java

/**
 * Reduces the duration of all statuses on this character by the amount specified.
 *
 * @param reduction  The amount to reduce the duration of each status by
 */// w  w  w .  j  av  a2s. c  o m
public void decrementAllStatusDurations(int reduction) {
    Set<Status> keys = new HashSet<>(statuses.keySet());
    keys.stream().forEach(status -> decrementStatusDuration(status, reduction));
}

From source file:fastcall.FastCallSNP.java

private ConcurrentHashMap<BufferedReader, List<String>> getReaderRemainderMap(
        HashMap<String, BufferedReader> bamPathPileupReaderMap) {
    ArrayList<String> empty = new ArrayList();
    ConcurrentHashMap<BufferedReader, List<String>> readerRemainderMap = new ConcurrentHashMap();
    Set<Map.Entry<String, BufferedReader>> enties = bamPathPileupReaderMap.entrySet();
    enties.stream().forEach(e -> {
        readerRemainderMap.put(e.getValue(), empty);
    });//from w  ww .  j ava2 s  . c om
    return readerRemainderMap;
}

From source file:com.spankingrpgs.model.characters.GameCharacter.java

/**
 * Cure all the statuses currently inflicting this character
 *//*from  w  ww . j a va 2  s . c  o  m*/
public void cureAllStatuses() {
    Set<Status> statusSet = new HashSet<>(statuses.keySet());
    statusSet.stream().forEach(this::cureStatus);
}

From source file:net.solarnetwork.node.setup.s3.S3SetupManager.java

/**
 * Get the S3 object for the {@link S3SetupConfiguration} to perform an
 * update to the highest available package version.
 * //w ww .  j a v a  2 s.  c  o m
 * <p>
 * If a {@code maxVersion} is configured, this method will find the highest
 * available package version less than or equal to {@code maxVersion}.
 * </p>
 * 
 * @return the S3 object that holds the setup metadata to update to, or
 *         {@literal null} if not available
 */
private S3ObjectReference getConfigObjectForUpdateToHighestVersion() throws IOException {
    final String metaDir = objectKeyForPath(META_OBJECT_KEY_PREFIX);
    Set<S3ObjectReference> objs = s3Client.listObjects(metaDir);
    S3ObjectReference versionObj = null;
    if (maxVersion == null) {
        // take the last (highest version), excluding the meta dir itself
        versionObj = objs.stream().filter(o -> !metaDir.equals(o.getKey())).reduce((l, r) -> r).orElse(null);
    } else {
        final String max = maxVersion;
        versionObj = objs.stream().max((l, r) -> {
            String vl = null;
            String vr = null;
            Matcher ml = VERSION_PAT.matcher(l.getKey());
            Matcher mr = VERSION_PAT.matcher(r.getKey());
            if (ml.find() && mr.find()) {
                vl = ml.group(1);
                if (vl.compareTo(max) > 0) {
                    vl = null;
                }
                vr = mr.group(1);
                if (vr.compareTo(max) > 0) {
                    vr = null;
                }
            }
            if (vl == null && vr == null) {
                return 0;
            } else if (vl == null) {
                return -1;
            } else if (vr == null) {
                return 1;
            }
            return vl.compareTo(vr);
        }).orElse(null);
    }
    return versionObj;
}

From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java

@Test
public void removeDuplicateDefaultDevices_singleDevice_noChange() {
    // Add devices
    String deviceName1 = "First";
    OperatingSystem operatingSystem1 = OperatingSystem.ANDROID;
    UserDevice device1 = addDeviceToRichard(0, deviceName1, operatingSystem1);

    // Verify two devices are present
    Set<UserDevice> devices = richard.getDevices();
    assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()),
            containsInAnyOrder(deviceName1));

    service.removeDuplicateDefaultDevices(createRichardUserDto(), device1.getId());

    // Assert success
    assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()),
            containsInAnyOrder(deviceName1));
}

From source file:eu.ggnet.dwoss.redtape.reporting.RedTapeCloserOperation.java

private Set<Document> findCloseableBlocker() {
    Collection<Long> receipts = receiptCustomers.getReceiptCustomers().values();
    List<Dossier> openDossiers = new DossierEao(redTapeEm).findByClosed(false).stream()
            .filter(d -> !receipts.contains(d.getCustomerId())).collect(Collectors.toList());

    //all active blockers from open dossiers
    Set<Document> blocker = openDossiers.stream().filter(d -> !d.getActiveDocuments(BLOCK).isEmpty())
            .map(d -> d.getActiveDocuments(BLOCK)).flatMap(Collection::stream).collect(Collectors.toSet());

    //directly closable, only comment positions
    Set<Document> closable = blocker.stream()
            .filter(d -> d.getPositions().values().stream().allMatch(p -> p.getType() == COMMENT))
            .collect(Collectors.toSet());

    //documents containing at least one unit type position
    Set<Document> containsUnit = blocker.stream()
            .filter(d -> d.getPositions().values().stream().anyMatch(p -> p.getType() == UNIT))
            .collect(Collectors.toSet());

    //remove all documents where at least one unit is still in stock
    containsUnit.removeIf(d -> d.getPositions().values().stream()
            .anyMatch(p -> p.getType() == UNIT && suEao.findByUniqueUnitId(p.getUniqueUnitId()) != null));

    closable.addAll(containsUnit);/*  w ww .  j a  va  2s.  c  o  m*/

    return closable;
}

From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java

@Test
public void getDeviceAnonymized_byIndex_tryGetNonExistingIndex_exception() {
    expectedException.expect(DeviceServiceException.class);
    expectedException.expect(hasMessageId("error.device.not.found.index"));

    // Add devices
    String deviceName1 = "First";
    OperatingSystem operatingSystem1 = OperatingSystem.ANDROID;
    addDeviceToRichard(0, deviceName1, operatingSystem1);

    String deviceName2 = "Second";
    OperatingSystem operatingSystem2 = OperatingSystem.IOS;
    addDeviceToRichard(1, deviceName2, operatingSystem2);

    // Verify two devices are present
    Set<UserDevice> devices = richard.getDevices();
    assertThat(devices.stream().map(UserDevice::getName).collect(Collectors.toSet()),
            containsInAnyOrder(deviceName1, deviceName2));

    // Try to get the anonymized ID for a nonexisting index
    service.getDeviceAnonymized(createRichardAnonymizedDto(), 2);
}