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.camel.component.catalog.content.ContentProducerDataAccessObject.java

private void waitForAvailableSource(CatalogFramework catalogFramework) throws SourceUnavailableException {
    RetryPolicy retryPolicy = new RetryPolicy().withDelay(3, TimeUnit.SECONDS)
            .withMaxDuration(3, TimeUnit.MINUTES).retryIf((Predicate<Set>) Set::isEmpty)
            .retryIf((Set<SourceDescriptor> result) -> !result.stream().findFirst().get().isAvailable());

    Failsafe.with(retryPolicy)/*w w  w .j  a v a  2  s . c o m*/
            .get(() -> catalogFramework.getSourceInfo(new SourceInfoRequestLocal(false)).getSourceInfo());
}

From source file:io.galeb.router.handlers.completionListeners.StatsdCompletionListener.java

private void sendStatusCodeCount(Set<String> keys, Integer statusCode, boolean targetIsUndef) {
    int realStatusCode = targetIsUndef ? 503 : statusCode;
    keys.stream().forEach(key -> statsdClient.incr(key + ".httpCode" + realStatusCode));
}

From source file:com.yodle.vantage.functional.config.VantageFunctionalTest.java

protected void compareResolvedDependencies(Set<Dependency> expected, Set<Dependency> actual) {
    Set<Dependency> sanitized = expected.stream().map(this::sanitizeDependency).collect(Collectors.toSet());
    assertEquals(sanitized, actual);//from w  ww . j a  v a  2 s .c o  m
}

From source file:io.kodokojo.service.redis.RedisEntityStore.java

@Override
public String addEntity(Entity entity) {
    if (entity == null) {
        throw new IllegalArgumentException("entity must be defined.");
    }/*from   w  ww  .  ja  va  2 s  .c  o  m*/
    if (StringUtils.isNotBlank(entity.getIdentifier())) {
        throw new IllegalArgumentException("entity had already an id.");
    }
    try (Jedis jedis = pool.getResource()) {
        String id = generateId();
        List<User> admins = IteratorUtils.toList(entity.getAdmins());
        List<User> users = IteratorUtils.toList(entity.getUsers());
        Entity entityToWrite = new Entity(id, entity.getName(), entity.isConcrete(),
                IteratorUtils.toList(entity.getProjectConfigurations()), admins, users);

        List<User> allUsers = new ArrayList<>(users);
        allUsers.addAll(admins);
        Set<String> userIds = allUsers.stream().map(User::getIdentifier).collect(Collectors.toSet());

        userIds.stream().forEach(userId -> {
            addUserToEntity(userId, id);
        });

        byte[] encryptedObject = RSAUtils.encryptObjectWithAES(key, entityToWrite);
        jedis.set(RedisUtils.aggregateKey(ENTITY_PREFIX, id), encryptedObject);
        return id;
    }
}

From source file:pl.edu.icm.comac.vis.server.service.GraphToolkit.java

/**
 * Method to choose appropriate not-favourite nodes of the graph. It takes
 * all nodes outside the normal and large sets, and chooses only those, who
 * are not overflowing the normal nodes over 'itemLinkLimit'. Note, that if 
 * at most one normal node is not overflown by item, others may be.
 *
 * @param normal list of normal favaourite nodes.
 * @param large list of favourite nodes which are overflown, i.e. we have limited
 * knowledge of their links//from   w ww . ja v  a 2  s  .c  om
 * @param links map of all links for all items, normal and external
 * @param itemLinkLimit recommended size od the links
 * @return set of the items choosen for the graphs as not favourite nodes.
 */
public Set<String> calculateAdditions(Set<String> normal, Set<String> large, Map<String, Set<String>> links,
        long itemLinkLimit) {
    Map<String, Long> outgoingLinks = new HashMap<>();
    normal.stream().forEach(x -> outgoingLinks.put(x, 0l));
    List<String> leftovers = links.keySet().stream().filter(x -> !(normal.contains(x) || large.contains(x)))
            .collect(Collectors.toList());

    //now order list by the link count in each of each element:
    Collections.sort(leftovers, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            int res = -((Integer) links.get(o1).size()).compareTo(((Integer) links.get(o2).size()));
            if (res == 0) {
                return o1.compareToIgnoreCase(o2);
            } else {
                return res;
            }
        }
    });
    Set<String> approved = new HashSet<String>();
    for (String item : leftovers) {
        final Set<String> itemLinks = links.get(item);
        if (itemLinks.stream().anyMatch(x -> {
            return outgoingLinks.containsKey(x) && outgoingLinks.get(x) < itemLinkLimit;
        })) {
            approved.add(item);
            itemLinks.stream().filter(x -> outgoingLinks.containsKey(x))
                    .forEach(x -> outgoingLinks.put(x, outgoingLinks.get(x) + 1));
        }
    }
    return approved;
}

From source file:org.arrow.runtime.execution.MultipleEventExecution.java

/**
 * Returns a set of all expected event definition IDs.
 * // w  w w .jav a  2  s.com
 * @return Set
 */
private Set<String> getExpectedEvendIds() {
    MultipleEventAware mea = (MultipleEventAware) getEntity();
    Set<EventDefinition> definitions = mea.getEventDefinitions();

    if (definitions == null) {
        return Collections.emptySet();
    }
    return definitions.stream().map(EventDefinition::getId).collect(Collectors.toSet());
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java

public static boolean removeAllFromSetProperty(Node node, String name) {
    try {//from   ww  w . jav  a 2 s . c  o  m
        //            JcrVersionUtil.ensureCheckoutNode(node);
        if (node == null) {
            throw new IllegalArgumentException("Cannot remove a property from a null-node!");
        }
        if (name == null) {
            throw new IllegalArgumentException("Cannot remove a property without a provided name");
        }

        Set<Value> values = new HashSet<>();
        node.setProperty(name, (Value[]) values.stream().toArray(size -> new Value[size]));
        return true;

    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to remove set property: " + name, e);
    }
}

From source file:com.truthbean.demo.ssm.service.impl.EnrollServiceImpl.java

@Override
public Set<String> queryYearsOverPage(int begin, int size) {
    List<String> tmp = enrollMapper.queryYearsOverPage(begin, size);
    Set<String> temp = new HashSet<>();
    Set<String> result = new HashSet<>();
    temp.addAll(tmp);// w ww  .  j av a2s.  c  om
    temp.stream().filter((str) -> (str.contains(","))).map((str) -> str.split(",")).forEach((strs) -> {
        result.addAll(Arrays.asList(strs));
    });
    return result;
}

From source file:com.truthbean.demo.ssm.service.impl.EnrollServiceImpl.java

@Override
public Set<String> queryAllYears() {
    List<String> tmp = enrollMapper.queryAllYears();
    Set<String> temp = new HashSet<>();
    Set<String> result = new HashSet<>();
    temp.addAll(tmp);/*from ww w.j ava  2s. com*/
    temp.stream().filter((str) -> (str.contains(","))).map((str) -> str.split(",")).forEach((strs) -> {
        result.addAll(Arrays.asList(strs));
    });
    return result;
}

From source file:delfos.rs.contentbased.vsm.booleanvsm.SparseVector.java

public double multiply(SparseVector<Key> iuf) {

    Set<Key> intersectionDomain = map.keySet().stream().filter(key -> iuf.containsKey(key))
            .collect(Collectors.toSet());

    double sum = intersectionDomain.stream().mapToDouble(key -> map.get(key) * iuf.map.get(key)).sum();
    return sum;/*from   w w  w. ja v  a 2s . com*/
}