List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:io.gravitee.repository.redis.management.RedisApiKeyRepository.java
@Override public Set<ApiKey> findByPlan(String plan) throws TechnicalException { return apiKeyRedisRepository.findByPlan(plan).stream().map(this::convert).collect(Collectors.toSet()); }
From source file:io.gravitee.repository.redis.management.RedisUserRepository.java
@Override public Set<User> findAll() throws TechnicalException { Set<RedisUser> users = userRedisRepository.findAll(); return users.stream().map(this::convert).collect(Collectors.toSet()); }
From source file:com.thoughtworks.go.agent.common.util.JarUtilTest.java
@Test public void shouldExtractJars() throws Exception { File sourceFile = new File(PATH_WITH_HASHES + "test-agent.jar"); File outputTmpDir = temporaryFolder.newFolder(); Set<File> files = new HashSet<>(JarUtil.extractFilesInLibDirAndReturnFiles(sourceFile, jarEntry -> jarEntry.getName().endsWith(".class"), outputTmpDir)); Set<File> actualFiles = Files.list(outputTmpDir.toPath()).map(Path::toFile).collect(Collectors.toSet()); assertEquals(files, actualFiles);// ww w. j av a 2s . c o m assertEquals(files.size(), 2); Set<String> fileNames = files.stream().map(File::getName).collect(Collectors.toSet()); assertEquals(fileNames, new HashSet<>(Arrays.asList("ArgPrintingMain.class", "HelloWorldStreamWriter.class"))); }
From source file:com.nebhale.buildmonitor.web.AbstractControllerTest.java
final String toJson(String... pairs) { StringBuilder sb = new StringBuilder("{ "); Set<String> entries = Arrays.stream(pairs).map(pair -> { String[] parts = StringUtils.split(pair, ":"); return String.format("\"%s\" : \"%s\"", parts[0], parts[1]); }).collect(Collectors.toSet()); sb.append(StringUtils.collectionToDelimitedString(entries, ", ")); return sb.append(" }").toString(); }
From source file:io.pivotal.strepsirrhini.chaoslemur.task.TaskManager.java
@RequestMapping(method = RequestMethod.GET, value = "", produces = MediaType.APPLICATION_JSON_VALUE) Set<Resource<Task>> readAll() { return this.tasks.values().stream().map(this.resourceAssembler::toResource).collect(Collectors.toSet()); }
From source file:io.gravitee.repository.redis.management.RedisApiRepository.java
@Override public Set<Api> findByGroups(List<String> groupIds) throws TechnicalException { return apiRedisRepository.findByGroups(groupIds).stream().map(this::convert).collect(Collectors.toSet()); }
From source file:com.netflix.genie.web.data.services.jpa.JpaServiceUtils.java
/** * Convert an application entity to a DTO for external exposure. * * @param applicationEntity The entity to convert * @return The immutable DTO representation of the entity data */// w w w . j a v a 2 s . com static Application toApplicationDto(final ApplicationEntity applicationEntity) { final Application.Builder builder = new Application.Builder(applicationEntity.getName(), applicationEntity.getUser(), applicationEntity.getVersion(), applicationEntity.getStatus()) .withId(applicationEntity.getUniqueId()).withCreated(applicationEntity.getCreated()) .withUpdated(applicationEntity.getUpdated()) .withTags(applicationEntity.getTags().stream().map(TagEntity::getTag) .collect(Collectors.toSet())) .withConfigs(applicationEntity.getConfigs().stream().map(FileEntity::getFile) .collect(Collectors.toSet())) .withDependencies(applicationEntity.getDependencies().stream().map(FileEntity::getFile) .collect(Collectors.toSet())); applicationEntity.getType().ifPresent(builder::withType); applicationEntity.getDescription().ifPresent(builder::withDescription); applicationEntity.getSetupFile() .ifPresent(setupFileEntity -> builder.withSetupFile(setupFileEntity.getFile())); setDtoMetadata(builder, applicationEntity); return builder.build(); }
From source file:io.gravitee.repository.mongodb.management.MongoApiKeyRepository.java
private Set<ApiKey> map(Collection<ApiAssociationMongo> apiAssociationMongos) { if (apiAssociationMongos == null) { return Collections.emptySet(); }// www . j a v a2s. c om return apiAssociationMongos.stream().map(apiAssociationMongo -> { ApiKey key = mapper.map(apiAssociationMongo.getKey(), ApiKey.class); key.setApi(apiAssociationMongo.getApi().getId()); key.setApplication(apiAssociationMongo.getApplication().getId()); return key; }).collect(Collectors.toSet()); }
From source file:io.gravitee.repository.redis.management.RedisGroupRepository.java
@Override public Set<Group> findAll() throws TechnicalException { return internalRepository.findAll().stream().map(this::convert).collect(Collectors.toSet()); }
From source file:com.netflix.spinnaker.orca.clouddriver.tasks.providers.aws.AmazonImageTagger.java
@Override public ImageTagger.OperationContext getOperationContext(Stage stage) { StageData stageData = (StageData) stage.mapTo(StageData.class); Collection<MatchedImage> matchedImages = findImages(stageData.imageNames, stage); if (stageData.regions == null || stageData.regions.isEmpty()) { stageData.regions = matchedImages.stream().flatMap(matchedImage -> matchedImage.amis.keySet().stream()) .collect(Collectors.toSet()); }//from w w w. j a v a2s .c o m stageData.imageNames = matchedImages.stream().map(matchedImage -> matchedImage.imageName) .collect(Collectors.toList()); // Built-in tags are not updatable Map<String, String> tags = stageData.tags.entrySet().stream() .filter(entry -> !BUILT_IN_TAGS.contains(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); List<Image> targetImages = new ArrayList<>(); Map<String, Object> originalTags = new HashMap<>(); List<Map<String, Map>> operations = new ArrayList<>(); for (MatchedImage matchedImage : matchedImages) { Image targetImage = new Image(matchedImage.imageName, defaultBakeAccount, stageData.regions, tags); targetImages.add(targetImage); log.info(format("Tagging '%s' with '%s' (executionId: %s)", targetImage.imageName, targetImage.tags, stage.getExecution().getId())); // Update the tags on the image in the `defaultBakeAccount` operations.add(ImmutableMap.<String, Map>builder().put(OPERATION, ImmutableMap.builder().put("amiName", targetImage.imageName).put("tags", targetImage.tags) .put("regions", targetImage.regions).put("credentials", targetImage.account).build()) .build()); // Re-share the image in all other accounts (will result in tags being updated) matchedImage.accounts.stream().filter(account -> !account.equalsIgnoreCase(defaultBakeAccount)) .forEach(account -> { stageData.regions .forEach(region -> operations.add(ImmutableMap.<String, Map>builder() .put(ALLOW_LAUNCH_OPERATION, ImmutableMap.builder().put("account", account) .put("credentials", defaultBakeAccount).put("region", region) .put("amiName", targetImage.imageName).build()) .build())); }); originalTags.put(matchedImage.imageName, matchedImage.tagsByImageId); } Map<String, Object> extraOutput = objectMapper.convertValue(stageData, Map.class); extraOutput.put("targets", targetImages); extraOutput.put("originalTags", originalTags); return new ImageTagger.OperationContext(operations, extraOutput); }