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.baifendian.swordfish.dao.model.ExecutionFlow.java
public Map<String, String> getUserDefinedParamMap() { List<Property> propList; if (userDefinedParamMap == null && StringUtils.isNotEmpty(userDefinedParams)) { propList = JsonUtil.parseObjectList(userDefinedParams, Property.class); if (propList != null) { userDefinedParamMap = propList.stream() .collect(Collectors.toMap(Property::getProp, Property::getValue)); }/* w ww .ja va2 s. com*/ } return userDefinedParamMap; }
From source file:energy.usef.core.service.business.CorePlanboardBusinessServiceTest.java
@Before public void init() { SequenceGeneratorService sequenceGeneratorService = new SequenceGeneratorService(); corePlanboardBusinessService = new CorePlanboardBusinessService(); Whitebox.setInternalState(corePlanboardBusinessService, sequenceGeneratorService); Whitebox.setInternalState(corePlanboardBusinessService, ptuContainerRepository); Whitebox.setInternalState(corePlanboardBusinessService, ptuFlexOfferRepository); Whitebox.setInternalState(corePlanboardBusinessService, ptuFlexOrderRepository); Whitebox.setInternalState(corePlanboardBusinessService, ptuPrognosisRepository); Whitebox.setInternalState(corePlanboardBusinessService, ptuFlexRequestRepository); Whitebox.setInternalState(corePlanboardBusinessService, planboardMessageRepository); Whitebox.setInternalState(corePlanboardBusinessService, connectionGroupRepository); Whitebox.setInternalState(corePlanboardBusinessService, brpConnectionGroupRepository); Whitebox.setInternalState(corePlanboardBusinessService, agrConnectionGroupRepository); Whitebox.setInternalState(corePlanboardBusinessService, congestionPointConnectionGroupRepository); Whitebox.setInternalState(corePlanboardBusinessService, connectionGroupStateRepository); Whitebox.setInternalState(corePlanboardBusinessService, connectionRepository); Whitebox.setInternalState(corePlanboardBusinessService, ptuStateRepository); Whitebox.setInternalState(corePlanboardBusinessService, config); PowerMockito.when(config.getIntegerProperty(Matchers.eq(ConfigParam.PTU_DURATION))).thenReturn(15); PowerMockito.when(ptuContainerRepository.findPtuContainersMap(Matchers.any(LocalDate.class))) .then(invocation -> IntStream.rangeClosed(1, 96).mapToObj(index -> { PtuContainer ptu = new PtuContainer(); ptu.setPtuIndex(index);// w w w . java2 s. co m ptu.setPtuDate((LocalDate) invocation.getArguments()[0]); return ptu; }).collect(Collectors.toMap(PtuContainer::getPtuIndex, Function.identity()))); }
From source file:io.yields.math.framework.kpi.ExplorerJsonExporter.java
private <T> Values toValues(PropertyVerifications<T> verifications) { Stream<PropertyVerification<T>> stream = verifications.getResults().stream() .filter(verification -> verification.getProperty().isPresent()); Map<String, Object> map = stream .collect(Collectors.toMap(verification -> verification.getProperty().get().getLabel(), propertyVerification -> propertyVerification.getResult().getCode())); return new Values(map); }
From source file:com.github.tddts.jet.service.impl.SearchOperationsImpl.java
@Override public Pair<List<ResultOrder>, Map<Integer, String>> extractTypeNames(List<ResultOrder> searchResults) { Map<Integer, String> typeNames = getUniverseNames(searchResults).getObject().stream() .collect(Collectors.toMap(UniverseName::getId, UniverseName::getName)); return Pair.of(searchResults, typeNames); }
From source file:com.oneops.cms.cm.service.CmsCmProcessor.java
private void populateRelCisLocal(List<CmsCIRelation> rels, boolean fromCis, boolean toCis, boolean populateAttrs) { if (rels.size() == 0) { return;//from w w w. j a v a 2s . c o m } Set<Long> ids = new HashSet<>(); if (fromCis) { ids.addAll(rels.stream().map(CmsCIRelation::getFromCiId).collect(Collectors.toList())); } if (toCis) { ids.addAll(rels.stream().map(CmsCIRelation::getToCiId).collect(Collectors.toList())); } Map<Long, CmsCI> ciMap = getCiByIdListLocal(new ArrayList<>(ids), populateAttrs).stream() .collect(Collectors.toMap(CmsCI::getCiId, Function.identity())); for (CmsCIRelation rel : rels) { if (fromCis) { rel.setFromCi(ciMap.get(rel.getFromCiId())); } if (toCis) { rel.setToCi(ciMap.get(rel.getToCiId())); } } }
From source file:nu.yona.server.analysis.service.ActivityService.java
private Map<ZonedDateTime, Set<WeekActivityDto>> mapWeekActivitiesToDtos( Map<ZonedDateTime, Set<WeekActivity>> weekActivityEntitiesByLocalDate) { return weekActivityEntitiesByLocalDate.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> mapWeekActivitiesToDtos(e.getValue()))); }
From source file:com.netflix.spinnaker.fiat.permissions.RedisPermissionsRepository.java
@Override public Map<String, UserPermission> getAllByRoles(List<String> anyRoles) { if (anyRoles == null) { return getAllById(); } else if (anyRoles.isEmpty()) { val unrestricted = get(UNRESTRICTED); if (unrestricted.isPresent()) { val map = new HashMap<String, UserPermission>(); map.put(UNRESTRICTED, unrestricted.get()); return map; }/* w w w . j a v a 2 s.c om*/ return new HashMap<>(); } try (Jedis jedis = jedisSource.getJedis()) { Pipeline p = jedis.pipelined(); List<Response<Set<String>>> responses = anyRoles.stream().map(role -> p.smembers(roleKey(role))) .collect(Collectors.toList()); p.sync(); Set<String> dedupedUsernames = responses.stream().flatMap(response -> response.get().stream()) .collect(Collectors.toSet()); dedupedUsernames.add(UNRESTRICTED); Table<String, ResourceType, Response<Map<String, String>>> responseTable = getAllFromRedis( dedupedUsernames); if (responseTable == null) { return new HashMap<>(0); } RawUserPermission rawUnrestricted = new RawUserPermission(responseTable.row(UNRESTRICTED)); UserPermission unrestrictedUser = getUserPermission(UNRESTRICTED, rawUnrestricted); return dedupedUsernames.stream().map(userId -> { RawUserPermission rawUser = new RawUserPermission(responseTable.row(userId)); return getUserPermission(userId, rawUser); }).collect(Collectors.toMap(UserPermission::getId, permission -> permission.merge(unrestrictedUser))); } }
From source file:gov.pnnl.goss.gridappsd.testmanager.CompareResults.java
/** * compareExpectedWithSimulation//w w w . j a va 2s. co m * @param simOutputPath * @param expectedOutputPath * @param simOutProperties */ public int compareExpectedWithSimulation(String simOutputPath, String expectedOutputPath, SimulationOutput simOutProperties) { int countTrue = 0; int countFalse = 0; Map<String, JsonElement> expectedOutputMap = getExpectedOutputMap(expectedOutputPath); Map<String, List<String>> propMap = simOutProperties.getOutputObjects().stream() .collect(Collectors.toMap(SimulationOutputObject::getName, e -> e.getProperties())); JsonObject jsonObject = getSimulationOutput(simOutputPath); JsonObject output = jsonObject.get("output").getAsJsonObject(); JsonObject simOutput = output.get("ieee8500").getAsJsonObject(); if (jsonObject != null) { Set<Entry<String, JsonElement>> simOutputSet = simOutput.entrySet(); for (Map.Entry<String, JsonElement> simOutputElement : simOutputSet) { System.out.println(simOutputElement); if (simOutputElement.getValue().isJsonObject()) { JsonObject simOutputObj = simOutputElement.getValue().getAsJsonObject(); JsonObject expectedOutputttObj = expectedOutputMap.get(simOutputElement.getKey()) .getAsJsonObject(); List<String> propsArray = propMap.get(simOutputElement.getKey()); for (String prop : propsArray) { if (simOutputObj.has(prop) && expectedOutputttObj.has(prop)) { Boolean comparison = compareObjectProperties(simOutputObj, expectedOutputttObj, prop); if (comparison) countTrue++; else countFalse++; } else System.out.println("No property"); } } else System.out.println(" Not object" + simOutputElement); } } System.out.println("Number of equals : " + countTrue + " Number of not equals : " + countFalse); return countFalse; }
From source file:io.bitgrillr.gocddockerexecplugin.DockerExecPluginTest.java
@Test public void handleExecute() throws Exception { UnitTestUtils.mockJobConsoleLogger(); PowerMockito.mockStatic(DockerUtils.class); PowerMockito.doNothing().when(DockerUtils.class); DockerUtils.pullImage(anyString());//from w w w .j a v a2 s.c om when(DockerUtils.createContainer(anyString(), anyString(), anyMap())).thenReturn("123"); when(DockerUtils.getContainerUid(anyString())).thenReturn("4:5"); when(DockerUtils.execCommand(anyString(), any(), any())).thenReturn(0); PowerMockito.doNothing().when(DockerUtils.class); DockerUtils.removeContainer(anyString()); when(DockerUtils.getCommandString(anyString(), any())).thenCallRealMethod(); PowerMockito.mockStatic(SystemHelper.class); when(SystemHelper.getSystemUid()).thenReturn("7:8"); DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(null, null, "execute"); JsonObject requestBody = Json.createObjectBuilder() .add("config", Json.createObjectBuilder() .add("IMAGE", Json.createObjectBuilder().add("value", "ubuntu:latest").build()) .add("COMMAND", Json.createObjectBuilder().add("value", "echo").build()) .add("ARGUMENTS", Json.createObjectBuilder().add("value", "Hello\nWorld").build()).build()) .add("context", Json.createObjectBuilder().add("workingDirectory", "pipelines/test") .add("environmentVariables", Json.createObjectBuilder().add("TEST1", "value1").add("TEST2", "value2").build()) .build()) .build(); request.setRequestBody(requestBody.toString()); final GoPluginApiResponse response = new DockerExecPlugin().handle(request); PowerMockito.verifyStatic(DockerUtils.class); DockerUtils.pullImage("ubuntu:latest"); PowerMockito.verifyStatic(DockerUtils.class); DockerUtils.createContainer("ubuntu:latest", Paths.get(System.getProperty("user.dir"), "pipelines/test").toAbsolutePath().toString(), Stream.<Map.Entry<String, String>>builder().add(new SimpleEntry<>("TEST1", "value1")) .add(new SimpleEntry<>("TEST2", "value2")).build() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); PowerMockito.verifyStatic(DockerUtils.class); DockerUtils.getContainerUid("123"); PowerMockito.verifyStatic(DockerUtils.class); DockerUtils.execCommand("123", "root", "chown", "-R", "4:5", "."); PowerMockito.verifyStatic(DockerUtils.class); DockerUtils.execCommand("123", null, "echo", "Hello", "World"); PowerMockito.verifyStatic(DockerUtils.class); DockerUtils.execCommand("123", "root", "chown", "-R", "7:8", "."); PowerMockito.verifyStatic(DockerUtils.class); DockerUtils.removeContainer("123"); assertEquals("Expected 2xx response", DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, response.responseCode()); final JsonObject responseBody = Json.createReader(new StringReader(response.responseBody())).readObject(); assertEquals("Expected success", Boolean.TRUE, responseBody.getBoolean("success")); assertEquals("Wrong message", "Command 'echo 'Hello' 'World'' completed with status 0", Json.createReader(new StringReader(response.responseBody())).readObject().getString("message")); }
From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java
public void initialise() { plotInfoByPlotId.clear();/*ww w.j a v a2s. c o m*/ try { KDSmartDatabase.WithPlotAttributesOption wpa = KDSmartDatabase.WithPlotAttributesOption.WITHOUT_PLOT_ATTRIBUTES; Map<Integer, Plot> plotById = kdxdb .getPlots(trial, SampleGroupChoice.create(sampleGroup.getSampleGroupId()), wpa).stream() .collect(Collectors.toMap(Plot::getPlotId, java.util.function.Function.identity())); traitById = kdxdb.getKDXploreKSmartDatabase().getTraitMap(); KDSmartDatabase.WithTraitOption wto = KDSmartDatabase.WithTraitOption.ALL_WITH_TRAITS; Predicate<TraitInstance> tiVisitor = new Predicate<TraitInstance>() { @Override public boolean evaluate(TraitInstance ti) { String key = makeTiKey(ti.getTraitId(), ti.getInstanceNumber()); tiByKey.put(key, ti); return true; } }; kdxdb.getKDXploreKSmartDatabase().visitTraitInstancesForTrial(trial.getTrialId(), wto, tiVisitor); Set<Integer> traitIdsSeen = new HashSet<>(); // sampleGroup.getTrialId(); java.util.function.Predicate<KdxSample> visitor = new java.util.function.Predicate<KdxSample>() { @Override public boolean test(KdxSample s) { Plot plot = plotById.get(s.getPlotId()); if (plot == null) { System.err.println("Missing Plot#" + s.getPlotId()); } else { PlotInfo pinfo = plotInfoByPlotId.get(plot.getPlotId()); if (pinfo == null) { pinfo = new PlotInfo(plot); plotInfoByPlotId.put(plot.getPlotId(), pinfo); } Integer traitId = s.getTraitId(); traitIdsSeen.add(traitId); pinfo.addSample(s); } return true; } }; boolean scored = false; kdxdb.visitKdxSamplesForSampleGroup(sampleGroup, KdxploreDatabase.SampleLevel.BOTH, scored, visitor); } catch (IOException e) { MsgBox.error(SampleGroupViewer.this, e, "Database Error"); return; } }