List of usage examples for java.util Set stream
default Stream<E> stream()
From source file:com.ge.predix.acs.policy.evaluation.cache.AbstractPolicyEvaluationCache.java
@Override public void resetForSubjectsByIds(final String zoneId, final Set<String> subjectIds) { multisetForSubjects(zoneId, subjectIds.stream().collect(Collectors.toList())); }
From source file:io.pravega.client.stream.impl.ReaderGroupStateManager.java
/** * Given a set of segments returns one to release. The one returned is arbitrary. */// w w w. j a v a2s. c o m private Segment findSegmentToRelease() { Set<Segment> segments = sync.getState().getSegments(readerId); return segments.stream().max((s1, s2) -> Double.compare(hashHelper.hashToRange(s1.getScopedName()), hashHelper.hashToRange(s2.getScopedName()))).orElse(null); }
From source file:com.ge.predix.acs.policy.evaluation.cache.AbstractPolicyEvaluationCache.java
@Override public void resetForResourcesByIds(final String zoneId, final Set<String> resourceIds) { multisetForResources(zoneId, resourceIds.stream().collect(Collectors.toList())); }
From source file:ai.grakn.graql.internal.gremlin.GraqlTraversal.java
private GraqlTraversal(GraknGraph graph, Set<? extends List<Fragment>> fragments) { this.graph = graph; this.fragments = fragments.stream().map(ImmutableList::copyOf).collect(toImmutableSet()); }
From source file:com.devicehive.auth.rest.providers.JwtTokenAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String token = (String) authentication.getPrincipal(); try {/*from w ww . j a va 2 s .c o m*/ JwtPayload jwtPayload = jwtClientService.getPayload(token); if (jwtPayload == null || (jwtPayload.getExpiration() != null && jwtPayload.getExpiration().before(timestampService.getDate())) || jwtPayload.getTokenType().equals(TokenType.REFRESH)) { throw new BadCredentialsException("Unauthorized"); } logger.debug("Jwt token authentication successful"); HivePrincipal principal = new HivePrincipal(); if (jwtPayload.getUserId() != null) { UserVO userVO = userService.findById(jwtPayload.getUserId()); principal.setUser(userVO); } Set<String> networkIds = jwtPayload.getNetworkIds(); if (networkIds != null) { if (networkIds.contains("*")) { principal.setAllNetworksAvailable(true); } else { principal.setNetworkIds(networkIds.stream().map(Long::valueOf).collect(Collectors.toSet())); } } Set<String> deviceGuids = jwtPayload.getDeviceGuids(); if (deviceGuids != null) { if (deviceGuids.contains("*")) { principal.setAllDevicesAvailable(true); } else { principal.setDeviceGuids(deviceGuids); } } Set<String> availableActions = jwtPayload.getActions(); if (availableActions != null) { if (availableActions.contains("*")) { principal.setActions(AvailableActions.getAllHiveActions()); } else if (availableActions.isEmpty()) { principal.setActions(AvailableActions.getClientHiveActions()); } else { principal.setActions( availableActions.stream().map(HiveAction::fromString).collect(Collectors.toSet())); } } return new HiveAuthentication(principal, AuthorityUtils.createAuthorityList(HiveRoles.JWT)); } catch (Exception e) { throw new BadCredentialsException("Unauthorized"); } }
From source file:com.devicehive.service.DeviceCommandServiceTest.java
@Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.BEFORE_METHOD) public void testFindCommandsByGuid() throws Exception { final List<String> guids = IntStream.range(0, 5).mapToObj(i -> UUID.randomUUID().toString()) .collect(Collectors.toList()); final Date timestampSt = timestampService.getDate(); final Date timestampEnd = timestampService.getDate(); final String parameters = "{\"param1\":\"value1\",\"param2\":\"value2\"}"; final Set<String> guidsForSearch = new HashSet<>(Arrays.asList(guids.get(0), guids.get(2), guids.get(3))); final Map<String, DeviceCommand> commandMap = guidsForSearch.stream() .collect(Collectors.toMap(Function.identity(), guid -> { DeviceCommand command = new DeviceCommand(); command.setId(System.nanoTime()); command.setDeviceGuid(guid); command.setCommand(RandomStringUtils.randomAlphabetic(10)); command.setTimestamp(timestampService.getDate()); command.setParameters(new JsonStringWrapper(parameters)); command.setStatus(DEFAULT_STATUS); return command; }));//from ww w . j a v a2 s . co m when(requestHandler.handle(any(Request.class))).then(invocation -> { Request request = invocation.getArgumentAt(0, Request.class); String guid = request.getBody().cast(CommandSearchRequest.class).getGuid(); CommandSearchResponse response = new CommandSearchResponse(); response.setCommands(Collections.singletonList(commandMap.get(guid))); return Response.newBuilder().withBody(response).buildSuccess(); }); deviceCommandService.find(guidsForSearch, Collections.emptySet(), timestampSt, timestampEnd, DEFAULT_STATUS) .thenAccept(commands -> { assertEquals(3, commands.size()); assertEquals(new HashSet<>(commandMap.values()), new HashSet<>(commands)); }).get(15, TimeUnit.SECONDS); verify(requestHandler, times(3)).handle(argument.capture()); }
From source file:com.devicehive.dao.riak.NetworkDaoRiakImpl.java
@Override public List<NetworkWithUsersAndDevicesVO> getNetworksByIdsAndUsers(Long idForFiltering, Set<Long> networkdIds, Set<Long> permittedNetworks) { Set<Long> intersection = networkdIds; if (permittedNetworks != null) { intersection = networkdIds.stream().filter(permittedNetworks::contains).collect(Collectors.toSet()); }/* www .j a v a2s . c o m*/ Stream<NetworkWithUsersAndDevicesVO> networkStream = intersection.stream() .map(this::findWithUsersAndDevices).filter(Optional::isPresent).map(Optional::get); if (idForFiltering != null) { networkStream = networkStream .filter(n -> n.getUsers().stream().anyMatch(u -> u.getId().equals(idForFiltering))); } return networkStream.collect(Collectors.toList()); }
From source file:com.netflix.genie.core.jpa.services.JpaJobSearchServiceImplIntegrationTests.java
/** * Make sure we can get the correct number of jobs which are active on a given host. * * @throws GenieException on error// w w w . j ava2s . c o m */ @Test public void canFindActiveJobsByHostName() throws GenieException { final String hostA = "a.netflix.com"; final String hostB = "b.netflix.com"; final String hostC = "c.netflix.com"; Set<Job> jobs = this.service.getAllActiveJobsOnHost(hostA); Assert.assertThat(jobs.size(), Matchers.is(1)); Assert.assertThat( jobs.stream() .filter(jobExecution -> JOB_2_ID .equals(jobExecution.getId().orElseThrow(IllegalArgumentException::new))) .count(), Matchers.is(1L)); jobs = this.service.getAllActiveJobsOnHost(hostB); Assert.assertThat(jobs.size(), Matchers.is(1)); Assert.assertThat( jobs.stream() .filter(jobExecution -> JOB_3_ID .equals(jobExecution.getId().orElseThrow(IllegalArgumentException::new))) .count(), Matchers.is(1L)); jobs = this.service.getAllActiveJobsOnHost(hostC); Assert.assertTrue(jobs.isEmpty()); }
From source file:edu.zipcloud.cloudstreetmarket.api.services.StockProductServiceOnlineImpl.java
private void updateStocksAndQuotesFromYahoo(Set<StockProduct> askedContent) { if (askedContent.isEmpty()) { return;/* w w w . ja v a2 s . c om*/ } Set<StockProduct> recentlyUpdated = askedContent.stream() .filter(t -> t.getLastUpdate() != null && DateUtil.isRecent(t.getLastUpdate(), 1)) .collect(Collectors.toSet()); if (askedContent.size() != recentlyUpdated.size()) { String guid = AuthenticationUtil.getPrincipal().getUsername(); SocialUser socialUser = usersConnectionRepository.getRegisteredSocialUser(guid); if (socialUser == null) { return; } String token = socialUser.getAccessToken(); Connection<Yahoo2> connection = connectionRepository.getPrimaryConnection(Yahoo2.class); if (connection != null) { askedContent.removeAll(recentlyUpdated); Map<String, StockProduct> updatableTickers = askedContent.stream() .collect(Collectors.toMap(StockProduct::getId, Function.identity())); List<YahooQuote> yahooQuotes = connection.getApi().financialOperations() .getYahooQuotes(new ArrayList<String>(updatableTickers.keySet()), token); Set<StockProduct> updatableProducts = yahooQuotes.stream() .filter(yq -> StringUtils.isNotBlank(yq.getExchange())) .filter(yq -> updatableTickers.get(yq.getId()) != null).map(yq -> { StockQuote sq = new StockQuote(yq, updatableTickers.get((yq.getId()))); return syncProduct(updatableTickers.get((yq.getId())), sq); }).collect(Collectors.toSet()); if (!updatableProducts.isEmpty()) { stockProductRepository.save(updatableProducts); } //This job below should decrease with the time Set<StockProduct> removableProducts = yahooQuotes.stream() .filter(yq -> StringUtils.isBlank(yq.getExchange())).map(yq -> { StockQuote sq = new StockQuote(yq, updatableTickers.get((yq.getId()))); return syncProduct(updatableTickers.get((yq.getId())), sq); }).collect(Collectors.toSet()); if (!removableProducts.isEmpty()) { stockProductRepository.delete(removableProducts); } } } }
From source file:edu.zipcloud.cloudstreetmarket.core.services.StockProductServiceOfflineImpl.java
private void updateStocksAndQuotesFromYahoo(Set<StockProduct> askedContent) { if (askedContent.isEmpty()) { return;//from w w w . ja v a2s . co m } Set<StockProduct> recentlyUpdated = askedContent.stream() .filter(t -> t.getLastUpdate() != null && DateUtil.isRecent(t.getLastUpdate(), 1)) .collect(Collectors.toSet()); if (askedContent.size() != recentlyUpdated.size()) { String guid = AuthenticationUtil.getPrincipal().getUsername(); String token = usersConnectionRepository.getRegisteredSocialUser(guid).getAccessToken(); ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(guid); Connection<Yahoo2> connection = connectionRepository.getPrimaryConnection(Yahoo2.class); if (connection != null) { askedContent.removeAll(recentlyUpdated); Map<String, StockProduct> updatableTickers = askedContent.stream() .collect(Collectors.toMap(StockProduct::getId, Function.identity())); List<YahooQuote> yahooQuotes = connection.getApi().financialOperations() .getYahooQuotes(new ArrayList<String>(updatableTickers.keySet()), token); Set<StockProduct> updatableProducts = yahooQuotes.stream() .filter(yq -> StringUtils.isNotBlank(yq.getExchange())) .filter(yq -> updatableTickers.get(yq.getId()) != null).map(yq -> { StockQuote sq = new StockQuote(yq, updatableTickers.get((yq.getId()))); return syncProduct(updatableTickers.get((yq.getId())), sq); }).collect(Collectors.toSet()); if (!updatableProducts.isEmpty()) { stockProductRepository.save(updatableProducts); } //This job below should decrease with the time Set<StockProduct> removableProducts = yahooQuotes.stream() .filter(yq -> StringUtils.isBlank(yq.getExchange())).map(yq -> { StockQuote sq = new StockQuote(yq, updatableTickers.get((yq.getId()))); return syncProduct(updatableTickers.get((yq.getId())), sq); }).collect(Collectors.toSet()); if (!removableProducts.isEmpty()) { stockProductRepository.delete(removableProducts); } } } }