List of usage examples for java.util.stream Collectors toMap
public static <T, K, U> Collector<T, ?, Map<K, U>> toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper)
From source file:com.epam.ta.reportportal.core.launch.impl.GetLaunchHandler.java
@Override public Map<String, String> getStatuses(String projectName, String[] ids) { return launchRepository.find(Arrays.asList(ids)).stream() .filter(launch -> launch.getProjectRef().equals(projectName)) .collect(Collectors.toMap(Launch::getId, launch -> launch.getStatus().toString())); }
From source file:com.vmware.admiral.compute.container.volume.VolumeUtil.java
private static <T extends ResourceState> Map<String, T> filterDescriptions(Class<T> clazz, Collection<ComponentDescription> componentDescriptions) { return componentDescriptions.stream().filter(cd -> clazz.isInstance(cd.getServiceDocument())) .map(cd -> clazz.cast(cd.getServiceDocument())).collect(Collectors.toMap(c -> c.name, c -> c)); }
From source file:com.epam.catgenome.manager.FeatureIndexManager.java
/** * Filer chromosomes that contain variations, specified by filter * * @param filterForm a {@code VcfFilterForm} to filter out chromosomes * @param projectId a {@code Project}s ID to filter * @return a {@code List} of {@code Chromosome} that corresponds to specified filter * @throws IOException/* w w w . ja va 2 s . c om*/ */ public List<Chromosome> filterChromosomes(VcfFilterForm filterForm, long projectId) throws IOException { Assert.isTrue(filterForm.getVcfFileIds() != null && !filterForm.getVcfFileIds().isEmpty(), MessageHelper.getMessage(MessagesConstants.ERROR_NULL_PARAM, VCF_FILE_IDS_FIELD)); Project project = projectManager.loadProject(projectId); List<VcfFile> vcfFiles = project.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.VCF) .map(i -> (VcfFile) i.getBioDataItem()).collect(Collectors.toList()); List<Chromosome> chromosomes = referenceGenomeManager.loadChromosomes(vcfFiles.get(0).getReferenceId()); Map<Long, Chromosome> chromosomeMap = chromosomes.parallelStream() .collect(Collectors.toMap(BaseEntity::getId, chromosome -> chromosome)); List<Long> chromosomeIds = featureIndexDao.getChromosomeIdsWhereVariationsPresentFacet(vcfFiles, filterForm.computeQuery(FeatureType.VARIATION)); return chromosomeIds.stream().map(chromosomeMap::get).collect(Collectors.toList()); }
From source file:com.cpjit.swagger4j.APIParser.java
private Map<String, Item> parseItem() throws Exception { return packages.stream().filter(pk -> pk.getAnnotation(Items.class) != null) .map(pk -> pk.getAnnotation(Items.class)).flatMap(items -> Arrays.stream(items.items())) .collect(Collectors.toMap(item -> item.value(), item -> item)); }
From source file:com.qq.tars.service.config.ConfigService.java
public List<ConfigFile> getNodeConfigFile(String application, String serverName, String setName, String setArea, String setGroup, long configId) { boolean enableSet = StringUtils.isNoneBlank(setName, setArea, setGroup); List<ServerConf> servers = serverMapper.getServerConf(application, serverName, enableSet, setName, setArea, setGroup, new RowBounds(0, 0)); ConfigFile configFile = loadConfigFile(configId); Map<String, ConfigFile> map = configMapper .getNodeConfigFile(application, serverName, setName, setArea, setGroup).stream() .filter(config -> config.getFilename().equals(configFile.getFilename())) .collect(Collectors.toMap(config -> String.format("%s.%s.%s.%s_%s", config.getServerName(), config.getSetName(), config.getSetArea(), config.getSetGroup(), config.getHost()), config -> config)); List<ConfigFile> exists = new ArrayList<>(map.values()); servers.stream().filter(server -> { String key = String.format("%s.%s.%s.%s.%s_%s", application, serverName, enableSet ? setName : StringUtils.EMPTY, enableSet ? setArea : StringUtils.EMPTY, enableSet ? setGroup : StringUtils.EMPTY, server.getNodeName()); return !map.containsKey(key); }).forEach(server -> {/* w ww . jav a 2 s . c o m*/ ConfigFile newone = new ConfigFile(); newone.setServerName(String.format("%s.%s", application, serverName)); newone.setSetName(setName); newone.setSetArea(setArea); newone.setSetGroup(setGroup); newone.setHost(server.getNodeName()); newone.setFilename(configFile.getFilename()); newone.setConfig(""); newone.setLevel(3); newone.setPosttime(DateTime.now()); configMapper.insertConfigFile(newone); log.info("insert default node config file, id={}, server_name={}, host={}, filename={}", newone.getId(), newone.getServerName(), newone.getHost(), newone.getFilename()); ConfigFileHistory history = new ConfigFileHistory(); history.setConfigId(newone.getId()); history.setReason("?"); history.setContent(newone.getConfig()); history.setPosttime(newone.getPosttime()); configMapper.insertConfigFileHistory(history); exists.add(newone); }); return exists; }
From source file:com.epam.catgenome.manager.gene.GffManager.java
/** * Creates a feature index for {@link GeneFile}. If an index already exists, it will be deleted and created * from scratch//from w w w . j a v a 2 s. co m * @param geneFileId an ID of gene file to reindex. * @param full * @return a {@link GeneFile}, for which index was created * @throws IOException if an error occurred while writing index */ public GeneFile reindexGeneFile(long geneFileId, boolean full) throws IOException { GeneFile geneFile = geneFileManager.loadGeneFile(geneFileId); Reference reference = referenceGenomeManager.loadReferenceGenome(geneFile.getReferenceId()); Map<String, Chromosome> chromosomeMap = reference.getChromosomes().stream() .collect(Collectors.toMap(BaseEntity::getName, chromosome -> chromosome)); fileManager.deleteFileFeatureIndex(geneFile); featureIndexManager.processGeneFile(geneFile, chromosomeMap, full); return geneFile; }
From source file:com.devicehive.service.DeviceNotificationServiceTest.java
@Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.BEFORE_METHOD) public void testFindWithResponse() throws Exception { final List<String> guids = IntStream.range(0, 5).mapToObj(i -> UUID.randomUUID().toString()) .collect(Collectors.toList()); final Date timestampSt = new Date(); final Date timestampEnd = new Date(); final String parameters = "{\"param1\":\"value1\",\"param2\":\"value2\"}"; final Set<String> guidsForSearch = new HashSet<>(Arrays.asList(guids.get(0), guids.get(2), guids.get(3))); // return response for any request Map<String, DeviceNotification> notificationMap = guidsForSearch.stream() .collect(Collectors.toMap(Function.identity(), guid -> { DeviceNotification notification = new DeviceNotification(); notification.setId(System.nanoTime()); notification.setDeviceGuid(guid); notification.setNotification(RandomStringUtils.randomAlphabetic(10)); notification.setTimestamp(new Date()); notification.setParameters(new JsonStringWrapper(parameters)); return notification; }));/* w w w .java 2 s. c o m*/ when(requestHandler.handle(any(Request.class))).then(invocation -> { Request request = invocation.getArgumentAt(0, Request.class); String guid = request.getBody().cast(NotificationSearchRequest.class).getGuid(); return Response.newBuilder() .withBody(new NotificationSearchResponse(Collections.singletonList(notificationMap.get(guid)))) .buildSuccess(); }); notificationService.find(guidsForSearch, Collections.emptySet(), timestampSt, timestampEnd) .thenAccept(notifications -> { assertEquals(3, notifications.size()); assertEquals(new HashSet<>(notificationMap.values()), new HashSet<>(notifications)); // using HashSet to ignore order }).exceptionally(ex -> { fail(ex.toString()); return null; }).get(30, TimeUnit.SECONDS); verify(requestHandler, times(3)).handle(argument.capture()); }
From source file:com.github.aptd.simulation.datamodel.CXMLReader.java
/** * create the station list//from w w w .jav a 2 s . c o m * * @param p_network network component * @param p_agents map with agent asl scripts * @param p_factory factory * @param p_time time reference * @param p_platforms map with already generated platforms * @return unmodifyable map with stations */ private static Map<String, IStation<?>> station(final Network p_network, final Map<String, String> p_agents, final IFactory p_factory, final ITime p_time, final Map<String, IPlatform<?>> p_platforms) { final Map<String, IElement.IGenerator<IStation<?>>> l_generators = new ConcurrentHashMap<>(); final Set<IAction> l_actions = CCommon.actionsFromPackage().collect(Collectors.toSet()); final ListMultimap<String, IPlatform<?>> l_platformbystationid = Multimaps.index(p_platforms.values(), IPlatform::stationid); return Collections.<String, IStation<?>>unmodifiableMap(p_network .getInfrastructure().getOperationControlPoints().getOcp().parallelStream().filter( i -> hasagentname(i.getAny())) .map(i -> agentname(i, i.getAny())) .map(i -> l_generators .computeIfAbsent(i.getRight(), a -> stationgenerator(p_factory, p_agents.get(i.getRight()), l_actions, p_time)) .generatesingle(i.getLeft().getId(), i.getLeft().getGeoCoord().getCoord().get(0), i.getLeft().getGeoCoord().getCoord().get(1), l_platformbystationid.get(i.getLeft().getId()))) .collect(Collectors.toMap(IElement::id, i -> i))); }
From source file:com.github.ambry.commons.BlobIdTest.java
/** * Tests blobIds comparisons. Among other things, ensures the following requirements are met: * <br>//from w ww.j av a 2s .c o m * V1s are always less than V2s and V3s. * V2s are always less than V3s. */ @Test public void testComparisons() { // the version check is to do this inter-version test just once (since this is a parametrized test). assumeTrue(version == BLOB_ID_V1); for (int i = 0; i < 100; i++) { Map<Short, Pair<BlobId, BlobId>> blobIds = Arrays.stream(BlobId.getAllValidVersions()).collect( Collectors.toMap(Function.identity(), v -> new Pair<>(getRandomBlobId(v), getRandomBlobId(v)))); for (short version : BlobId.getAllValidVersions()) { BlobId blobId = blobIds.get(version).getFirst(); BlobId altBlobId = blobIds.get(version).getSecond(); assertEquals("blobIdV" + version + " should be equal to itself", 0, blobId.compareTo(blobId)); assertEquals("blobIdV" + version + " should be equal to itself", blobId, blobId); assertThat("Two randomly generated blobIdV" + version + "s should be unequal", blobId.compareTo(altBlobId), not(0)); assertThat("Two randomly generated blobIdV" + version + "s should be unequal", blobId, not(altBlobId)); for (short otherVersion = 1; otherVersion < version; otherVersion++) { BlobId otherBlobId = blobIds.get(otherVersion).getFirst(); assertThat("blobIdV" + otherVersion + " should not equal blobIdV" + version, otherBlobId, not(blobId)); assertThat("blobIdV" + version + " should not equal blobIdV" + otherVersion, blobId, not(otherBlobId)); boolean differentVersionGroup = version < BLOB_ID_V3 || (version < BLOB_ID_V6 ? otherVersion < BLOB_ID_V3 : otherVersion < BLOB_ID_V6); if (differentVersionGroup) { assertTrue("blobIdV" + otherVersion + " should be less than blobIdV" + version, otherBlobId.compareTo(blobId) < 0); assertTrue("blobIdV" + version + " should be greater than blobIdV" + otherVersion, blobId.compareTo(otherBlobId) > 0); } else { assertEquals( "Comparison between blobIdV" + version + " and blobIDV" + otherVersion + " are based on uuid only", blobId.getUuid().compareTo(otherBlobId.getUuid()), blobId.compareTo(otherBlobId)); assertEquals( "Comparison between blobIdV" + otherVersion + " and blobIDV" + version + " are based on uuid only", otherBlobId.getUuid().compareTo(blobId.getUuid()), otherBlobId.compareTo(blobId)); } } } } }
From source file:nu.yona.server.analysis.rest.UserActivityController.java
private Map<UUID, String> buildDeviceAnonymizedIdToDeviceNameMap(UUID userId) { return userService.getPrivateUser(userId).getOwnPrivateData().getOwnDevices().stream() .collect(Collectors.toMap(UserDeviceDto::getDeviceAnonymizedId, UserDeviceDto::getName)); }