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:ddf.catalog.validation.impl.validator.RequiredAttributesMetacardValidator.java

/**
 * Creates a {@code RequiredAttributesMetacardValidator} with the given metacard type name and
 * set of attribute names representing the required attributes.
 * <p>// ww w. ja  v a  2 s .co m
 * This validator will only validate {@link Metacard}s that have the type name specified by
 * {@code metacardTypeName} (case-sensitive).
 * <p>
 * Any missing required attributes will be flagged as metacard-level validation errors.
 *
 * @param metacardTypeName   the name of the metacard type this validator can validate, cannot
 *                           be null
 * @param requiredAttributes the names of the attributes this validator will check for, cannot
 *                           be null or empty
 * @throws IllegalArgumentException if {@code metacardTypeName} is null or if
 *                                  {@code requiredAttributes} is null or empty
 */
public RequiredAttributesMetacardValidator(final String metacardTypeName,
        final Set<String> requiredAttributes) {
    Preconditions.checkArgument(metacardTypeName != null, "The metacard type name cannot be null.");
    Preconditions.checkArgument(CollectionUtils.isNotEmpty(requiredAttributes),
            "Must specify at least one required attribute.");

    this.metacardTypeName = metacardTypeName;
    this.requiredAttributes = requiredAttributes.stream().filter(Objects::nonNull).collect(Collectors.toSet());
}

From source file:io.gravitee.management.service.impl.ApiKeyServiceImpl.java

@Override
public Optional<ApiKeyEntity> getCurrent(String applicationName, String apiName) {
    try {//from w  ww.jav  a 2 s  .c o m
        LOGGER.debug("Generate a new key for {} - {}", applicationName, apiName);
        // Current Api Key is the key with the latest createdAt value and which is not revoked
        final Set<ApiKey> apiKeys = apiKeyRepository.findByApplicationAndApi(applicationName, apiName);
        if (apiKeys == null || apiKeys.isEmpty()) {
            return Optional.empty();
        }
        return apiKeys.stream().filter(apiKey -> !apiKey.isRevoked())
                .max((o1, o2) -> o1.getCreatedAt().compareTo(o2.getCreatedAt()))
                .map(ApiKeyServiceImpl::convert);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while getting current API key for {} - {}", applicationName, apiName, ex);
        throw new TechnicalManagementException(
                "An error occurs while getting current API key for " + applicationName + " - " + apiName, ex);
    }
}

From source file:com.yqboots.security.core.RoleManagerImpl.java

/**
 * {@inheritDoc}/*from   w  w  w .j  a  v  a2s  . co  m*/
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_USERS_OF_ROLE)
public void updateUsers(final String path, final Long... userIds) throws RoleNotFoundException {
    Assert.hasText(path);

    final Role role = roleRepository.findByPath(path);
    if (role == null) {
        throw new RoleNotFoundException(path);
    }

    final Set<User> roleUsers = role.getUsers();
    if (CollectionUtils.isNotEmpty(roleUsers)) {
        roleUsers.stream().forEach(user -> user.getRoles().remove(role));
    }

    if (ArrayUtils.isNotEmpty(userIds)) {
        final List<User> users = userRepository.findAll(Arrays.asList(userIds));
        users.stream().forEach(user -> user.getRoles().add(role));
    }
}

From source file:com.yqboots.security.core.RoleManagerImpl.java

/**
 * {@inheritDoc}/*from  w w w .  j a v  a 2 s .com*/
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_USERS_OF_ROLE)
public void updateUsers(final String path, final String... usernames) throws RoleNotFoundException {
    Assert.hasText(path);

    final Role role = roleRepository.findByPath(path);
    if (role == null) {
        throw new RoleNotFoundException(path);
    }

    final Set<User> roleUsers = role.getUsers();
    if (CollectionUtils.isNotEmpty(roleUsers)) {
        roleUsers.stream().forEach(user -> user.getRoles().remove(role));
    }

    if (ArrayUtils.isNotEmpty(usernames)) {
        final List<User> users = userRepository.findByUsernameIn(Arrays.asList(usernames));
        users.stream().forEach(user -> user.getRoles().add(role));
    }
}

From source file:me.rkfg.xmpp.bot.plugins.FaggotOfTheDayPlugin.java

private void calculateFaggot() {
    occupants.removeIf(occupant -> occupant.getNick().equals(getBotNick()));

    if (occupants.isEmpty()) {
        log.info("No contenders for Faggot of the Day today.");
        if (faggot != null) {
            log.info("{} remains Faggot of the Day!", faggot.getNick());
        }/*w w w .java 2 s . c  o  m*/
        return;
    }

    final Set<String> uniqueJids = occupants.stream().map(Occupant::getJid).map(XmppStringUtils::parseBareJid)
            .collect(Collectors.toSet());
    log.info("Contenders for todays Faggot of the Day title: {}", uniqueJids);

    final int i = random.nextInt(uniqueJids.size());
    final String faggotJid = uniqueJids.stream().skip(i).findFirst().get();
    faggot = occupants.stream()
            .filter(occupant -> faggotJid.equals(XmppStringUtils.parseBareJid(occupant.getJid()))).findFirst()
            .get();
    log.info("{} becomes Faggot of the Day!", faggot.getNick());

    occupants.clear();
}

From source file:org.sardineproject.sbyod.rest.AppWebUser.java

/**
 * Disconnect a user from all services./*from   w  ww.  j a  v  a  2  s  .  c  o m*/
 * @param userIp_ the IP address of the user
 * @return PRECONDITION_FAILED if some parameter was wrong
 *          "enabled : false" if user is disconnected
 *          "enabled : true" if user disconnection went wrong
 */
@DELETE
@Path("/{userIp}")
public Response resetHostTraffic(@PathParam("userIp") String userIp_) {
    log.debug("AppWebUser: Removing all connections of user with ip = {}.", userIp_);

    if (userIp_ == null)
        return Response.status(Response.Status.PRECONDITION_FAILED).build();

    Set<Host> srcHosts;
    try {
        Ip4Address userIp = Ip4Address.valueOf(userIp_);
        // get all hosts with given ip
        srcHosts = get(HostService.class).getHostsByIp(userIp);
    } catch (Exception e) {
        return Response.status(Response.Status.PRECONDITION_FAILED).build();
    }

    if (srcHosts.isEmpty()) {
        log.debug("AppWebUser: No host found with IP = {}", userIp_);
        return Response.ok(ENABLED_FALSE).build();
    }

    // remove connection for every host
    for (Host user : srcHosts) {
        // get all connections of the host
        Set<Connection> connections = get(ConnectionStore.class).getConnections(user);
        // filter out portal and dns services
        connections = connections.stream()
                .filter(c -> !c.getService().equals(get(PortalService.class).getPortalService()))
                .filter(c -> !(get(DnsService.class).getDnsServices().contains(c.getService())))
                .collect(Collectors.toSet());

        // remove all connections in set
        for (Connection connection : connections) {
            log.debug("AppWebUser: Removing connection {}", connection.toString());
            get(ConnectionStore.class).removeConnection(connection);
        }
    }

    return Response.ok(ENABLED_FALSE).build();
}

From source file:com.yqboots.security.core.GroupManagerImpl.java

/**
 * {@inheritDoc}/*from  w  w  w.j  a  va 2  s  .c  o  m*/
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_USERS_OF_GROUP)
public void updateUsers(final String path, final Long... userIds) throws GroupNotFoundException {
    Assert.hasText(path);

    final Group group = groupRepository.findByPath(path);
    if (group == null) {
        throw new GroupNotFoundException(path);
    }

    final Set<User> groupUsers = group.getUsers();
    if (CollectionUtils.isNotEmpty(groupUsers)) {
        groupUsers.stream().forEach(user -> user.getGroups().remove(group));
    }

    if (ArrayUtils.isNotEmpty(userIds)) {
        final List<User> users = userRepository.findAll(Arrays.asList(userIds));
        users.stream().forEach(user -> user.getGroups().add(group));
    }
}

From source file:com.yqboots.security.core.GroupManagerImpl.java

/**
 * {@inheritDoc}/*from  w  w w .ja v  a  2 s . co  m*/
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_USERS_OF_GROUP)
public void updateUsers(final String path, final String... usernames) throws GroupNotFoundException {
    Assert.hasText(path);

    final Group group = groupRepository.findByPath(path);
    if (group == null) {
        throw new GroupNotFoundException(path);
    }

    final Set<User> groupUsers = group.getUsers();
    if (CollectionUtils.isNotEmpty(groupUsers)) {
        groupUsers.stream().forEach(user -> user.getGroups().remove(group));
    }

    if (ArrayUtils.isNotEmpty(usernames)) {
        final List<User> users = userRepository.findByUsernameIn(Arrays.asList(usernames));
        users.stream().forEach(user -> user.getGroups().add(group));
    }
}

From source file:com.yqboots.security.core.RoleManagerImpl.java

/**
 * {@inheritDoc}/*from  w w  w . ja v  a2  s . c o m*/
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_GROUPS_OF_ROLE)
public void updateGroups(final String path, final Long... groupIds) throws RoleNotFoundException {
    Assert.hasText(path);

    final Role role = roleRepository.findByPath(path);
    if (role == null) {
        throw new RoleNotFoundException(path);
    }

    final Set<Group> roleGroups = role.getGroups();
    if (CollectionUtils.isNotEmpty(roleGroups)) {
        roleGroups.stream().forEach(group -> group.getRoles().remove(role));
    }

    if (ArrayUtils.isNotEmpty(groupIds)) {
        final List<Group> groups = groupRepository.findAll(Arrays.asList(groupIds));
        groups.stream().forEach(group -> group.getRoles().add(role));
    }
}

From source file:com.yqboots.security.core.RoleManagerImpl.java

/**
 * {@inheritDoc}//  w w w . j a  v  a  2 s  .c om
 */
@Override
@Transactional
@Auditable(code = SecurityAudit.CODE_UPDATE_GROUPS_OF_ROLE)
public void updateGroups(final String path, final String... groupPaths) throws RoleNotFoundException {
    Assert.hasText(path);

    final Role role = roleRepository.findByPath(path);
    if (role == null) {
        throw new RoleNotFoundException(path);
    }

    final Set<Group> roleGroups = role.getGroups();
    if (CollectionUtils.isNotEmpty(roleGroups)) {
        roleGroups.stream().forEach(group -> group.getRoles().remove(role));
    }

    if (ArrayUtils.isNotEmpty(groupPaths)) {
        final List<Group> groups = groupRepository.findByPathIn(Arrays.asList(groupPaths));
        groups.stream().forEach(group -> group.getRoles().add(role));
    }
}