public static void main(String[] args) { MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>(); map.put("one", "A"); System.out.println(map); map.putAll("one", Arrays.asList("B", "C")); System.out.println(map); map.put("one", "D"); System.out.println(map); map.putAll("two", Arrays.asList("1", "2", "3")); System.out.println(map); System.out.printf("The value of the one key: %s\n", map.get("one")); }
public static BodyActivityProvider getInstance(BodyActivityType type, MultiValuedMap<Integer, Integer> bodyToLiterals, Map<Integer, Double> activityCounters, double defaultActivity) { switch (type) { case DEFAULT: return new DefaultBodyActivityProvider(bodyToLiterals, activityCounters, defaultActivity); case SUM: return new SumBodyActivityProvider(bodyToLiterals, activityCounters, defaultActivity); case AVG: return new AvgBodyActivityProvider(bodyToLiterals, activityCounters, defaultActivity); case MAX: return new MaxBodyActivityProvider(bodyToLiterals, activityCounters, defaultActivity); case MIN: return new MinBodyActivityProvider(bodyToLiterals, activityCounters, defaultActivity); default: throw new IllegalArgumentException("Unknown body activity type requested."); } }
private static List<AbstractObjectInstantiator> instantiateInstantiators(final Class<?> clazz, final MultiValuedMap<Class<?>, ConstructorParameters> constructorParameters) { final List<AbstractObjectInstantiator> instantiators = new ArrayList<>(); try { for (final Class<? extends AbstractObjectInstantiator> instantiator : INSTANTIATORS) { final Constructor<? extends AbstractObjectInstantiator> constructor = instantiator.getDeclaredConstructor(Class.class, MultiValuedMap.class); constructor.setAccessible(true); final AbstractObjectInstantiator abstractObjectInstantiator = constructor.newInstance(clazz, constructorParameters); instantiators.add(abstractObjectInstantiator); } } catch (final Exception e) { throw new RuntimeException("Cannot load instantiators form pl.pojo.tester.internal.instantiator package.", e); } return instantiators; }
@Test void Should_Use_User_Constructor_Parameters() { // given final Class[] classesToTest = { ClassWithSyntheticConstructor.class }; final ConstructorParameters parameters = new ConstructorParameters(new Object[]{ "string" }, new Class[]{ String.class }); final MultiValuedMap<Class<?>, ConstructorParameters> constructorParameters = spy(new ArrayListValuedHashMap<>()); constructorParameters.put(ClassWithSyntheticConstructor.class, parameters); final ConstructorTester constructorTester = new ConstructorTester(); constructorTester.setUserDefinedConstructors(constructorParameters); // when final Throwable result = catchThrowable(() -> constructorTester.testAll(classesToTest)); // then assertThat(result).isNull(); verify(constructorParameters).get(ClassWithSyntheticConstructor.class); }
@Test void Should_Create_Constructor_Parameters_When_Parameters_Are_Not_Provided() { // given final Class[] classesToTest = { ClassWithSyntheticConstructor.class }; final MultiValuedMap<Class<?>, ConstructorParameters> constructorParameters = spy(new ArrayListValuedHashMap<>()); final ConstructorTester constructorTester = new ConstructorTester(); constructorTester.setUserDefinedConstructors(constructorParameters); // when final Throwable result = catchThrowable(() -> constructorTester.testAll(classesToTest)); // then assertThat(result).isNull(); verify(constructorParameters, never()).get(ClassWithSyntheticConstructor.class); }
@Test void Should_Create_Constructor_Parameters_When_Could_Not_Find_Matching_Constructor_Parameters_Types() { // given final Class[] classesToTest = { ClassWithSyntheticConstructor.class }; final ConstructorParameters parameters = spy(new ConstructorParameters(new Object[]{ "to", "many", "parameters" }, new Class[]{ String.class, String.class, String.class })); final MultiValuedMap<Class<?>, ConstructorParameters> constructorParameters = spy(new ArrayListValuedHashMap<>()); constructorParameters.put(ClassWithSyntheticConstructor.class, parameters); final ConstructorTester constructorTester = new ConstructorTester(); constructorTester.setUserDefinedConstructors(constructorParameters); // when final Throwable result = catchThrowable(() -> constructorTester.testAll(classesToTest)); // then assertThat(result).isNull(); verify(parameters, never()).getParameters(); }
/** * Return a map that associates each value property with the set of bindings that provide it. */ private MultiValuedMap<String,VarBindingDef> createPropertyProviders( FunctionInputDef inputDef) { propertyProviders_ = MultiMapUtils.newListValuedHashMap(); for( VarDefIterator varDefs = new VarDefIterator( inputDef.getVarDefs()); varDefs.hasNext(); ) { VarDef varDef = varDefs.next(); for( Iterator<VarValueDef> values = varDef.getValidValues(); values.hasNext(); ) { VarValueDef value = values.next(); if( !value.getProperties().isEmpty()) { VarBindingDef binding = new VarBindingDef( varDef, value); for( Iterator<String> properties = value.getProperties().getProperties(); properties.hasNext(); ) { propertyProviders_.put( properties.next(), binding); } } } } return propertyProviders_; }
private void processMqscFiles(XMLConfiguration config, List<File> mqscFiles, String releaseFolder) { if(CollectionUtils.isNotEmpty(mqscFiles)){ List<ConfigurationNode> allMQSCEnvironments = config.getRootNode().getChildren(); if(CollectionUtils.isNotEmpty(allMQSCEnvironments)){ MultiValuedMap<String,String> allMQSCForEnvironment = new ArrayListValuedHashMap<>(); processMQSCForAllEnvironments(config, mqscFiles, allMQSCEnvironments, allMQSCForEnvironment); for(String key: allMQSCForEnvironment.keySet()){ List<String> mqscContentList = (List<String>)allMQSCForEnvironment.get(key); generateMQSCContent(config, mqscContentList, key, releaseFolder); } } } }
private void processMQSCForAllEnvironments(XMLConfiguration config, List<File> allMqscFiles, List<ConfigurationNode> allMQSCEnvironments, MultiValuedMap<String,String> allMQSCForEnvironment) { for(ConfigurationNode rootConfigNode: allMQSCEnvironments){ String environment = rootConfigNode.getName(); for(File mqscFile: allMqscFiles){ try { String originalfileContent = FileUtils.readFileToString(mqscFile, Charset.defaultCharset()); allMQSCForEnvironment.put(environment, originalfileContent); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } }
public static RequestBody parseBody(byte[] body, RequestHeader header) { if (body.length == 0) { return new RequestBody(); } String contentType = header.getContentType(); Map<String, MimeData> mimeMap = Collections.emptyMap(); MultiValuedMap<String, String> formMap = new ArrayListValuedHashMap<>(); if (contentType.contains("application/x-www-form-urlencoded")) { try { String bodyMsg = new String(body, "utf-8"); RequestParser.parseParameters(bodyMsg, formMap); } catch (UnsupportedEncodingException ignored) { } } else if (contentType.contains("multipart/form-data")) { int boundaryValueIndex = contentType.indexOf("boundary="); String bouStr = contentType.substring(boundaryValueIndex + 9); // 9是 `boundary=` 长度 mimeMap = parseFormData(body, bouStr); } RequestBody requestBody = new RequestBody(); requestBody.setFormMap(formMap); requestBody.setMimeMap(mimeMap); return requestBody; }
@Test public void cardsBySuit() { Map<Suit, SortedSet<Card>> jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); MultiValuedMap<Suit, Card> acCardsBySuit = this.acDeck.getCardsBySuit(); Assert.assertEquals(jdkCardsBySuit.get(Suit.CLUBS), new TreeSet<>(acCardsBySuit.get(Suit.CLUBS))); }
@Test public void cardsBySuit() { Map<Suit, List<Card>> jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); MultiValuedMap<Suit, Card> acCardsBySuit = this.acDeck.getCardsBySuit(); Assert.assertEquals(jdkCardsBySuit.get(Suit.CLUBS), new ArrayList<>(acCardsBySuit.get(Suit.CLUBS))); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof MultiValuedMap) { return asMap().equals(((MultiValuedMap<?, ?>) obj).asMap()); } return false; }
@Override public boolean putAll(final MultiValuedMap<? extends K, ? extends V> map) { if (map == null) { throw new NullPointerException("Map must not be null."); } boolean changed = false; for (Map.Entry<? extends K, ? extends V> entry : map.entries()) { changed |= put(entry.getKey(), entry.getValue()); } return changed; }
/** * Constructor that wraps (not copies). * * @param map the map to decorate, must not be null * @throws NullPointerException if the map is null */ protected AbstractMultiValuedMapDecorator(final MultiValuedMap<K, V> map) { if (map == null) { throw new NullPointerException("MultiValuedMap must not be null."); } this.map = map; }
/** * Sets the {@code WaySegment}s. * * @param edgeSegments * a collection of way segments to store */ public void setSegments(Collection<WaySegment> edgeSegments) { MultiValuedMap<WaySegmentId, WaySegment> res = new ArrayListValuedHashMap<>(); for (WaySegment segment : edgeSegments) { res.put(segment.getId(), segment); } this.segments = res; }
/** * Creates an new instance of {@code OSMData} of a {@link Set} of * {@link Entity}s. * * @param entities * set of {@code Entity}s to store */ public OSMData(Set<Entity> entities) { this.boundingBox = null; MultiValuedMap<Long, Entity> map = new ArrayListValuedHashMap<>(); for (Entity e : entities) { if (e instanceof Bound) this.boundingBox = (Bound) e; map.put(e.getId(), e); } this.entities = map; }
/** * Sets the entities * * @param entities */ protected void setEntities(Set<Entity> entities) { MultiValuedMap<Long, Entity> map = new ArrayListValuedHashMap<>(); for (Entity e : entities) { map.put(e.getId(), e); } this.entities = map; }
public ObjectGenerator(final AbstractFieldValueChanger abstractFieldValueChanger, final MultiValuedMap<Class<?>, ConstructorParameters> constructorParameters, final Permutator permutator) { this.abstractFieldValueChanger = abstractFieldValueChanger; this.constructorParameters = constructorParameters; this.permutator = permutator; }
static Object[] instantiateClasses(final Class<?>[] classes, final MultiValuedMap<Class<?>, ConstructorParameters> constructorParameters) { return Arrays.stream(classes) .map(clazz -> Instantiable.forClass(clazz, constructorParameters)) .map(AbstractObjectInstantiator::instantiate) .toArray(); }
static AbstractObjectInstantiator forClass(final Class<?> clazz, final MultiValuedMap<Class<?>, ConstructorParameters> constructorParameters) { return instantiateInstantiators(clazz, constructorParameters).stream() .filter(AbstractObjectInstantiator::canInstantiate) .findAny() .get(); }
@Override public boolean matches(final MultiValuedMap<Class<?>, ConstructorParameters> argument) { if (!argument.containsKey(expectedClass)) { return false; } return argument.get(expectedClass) .stream() .map(actualArgument -> Arrays.equals(actualArgument.getParameters(), expectedArguments.getParameters()) && Arrays.equals(actualArgument.getParametersTypes(), expectedArguments.getParametersTypes())) .findAny() .isPresent(); }
@Test public void testGetStoragePathsByStorageUnitIds() throws Exception { // Override configuration. Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.STORAGE_FILE_PATHS_QUERY_PAGINATION_SIZE.getKey(), LOCAL_FILES.size() / 2); modifyPropertySourceInEnvironment(overrideMap); try { // Create database entities required for testing. StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper .createStorageUnitEntity(STORAGE_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, true, BDATA_STATUS, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH); for (String file : LOCAL_FILES) { storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, file, FILE_SIZE_1_KB, ROW_COUNT_1000); } // Retrieve storage file paths by storage unit ids. MultiValuedMap<Integer, String> result = storageFileDao.getStorageFilePathsByStorageUnitIds(Arrays.asList(storageUnitEntity.getId())); // Validate the results. assertEquals(LOCAL_FILES.size(), result.get(storageUnitEntity.getId()).size()); } finally { // Restore the property sources so we don't affect other tests. restorePropertySourceInEnvironment(); } }
private static RequestHeader parseHeader(byte[] head) throws IOException { RequestHeader header = new RequestHeader(); try (BufferedReader reader = new BufferedReader(new StringReader(new String(head, "UTF-8")))) { Map<String, String> headMap = new HashMap<>(); String line = reader.readLine(); String[] lineOne = line.split("\\s"); String path = URLDecoder.decode(lineOne[1], "utf-8"); String method = lineOne[0]; HttpScheme scheme = HttpScheme.parseScheme(lineOne[2]); while ((line = reader.readLine()) != null) { String[] keyValue = line.split(":", 2); headMap.put(keyValue[0].trim().toLowerCase(), keyValue[1].trim()); } int index = path.indexOf('?'); MultiValuedMap<String, String> queryMap = new ArrayListValuedHashMap<>(); String queryString = StringUtils.EMPTY; if (index != -1) { queryString = path.substring(index + 1); RequestParser.parseParameters(queryString, queryMap); path = path.substring(0, index); } header.setURI(path); // 大小写敏感 header.setMethod(method); // 大小写敏感 header.setHead(headMap); header.setQueryString(queryString); header.setQueryMap(queryMap); header.setCookies(parseCookie(headMap)); header.setScheme(scheme); return header; } }
public MultiValuedMap<Suit, Card> getCardsBySuit() { return this.cardsBySuit; }
@Override public boolean putAll(final MultiValuedMap<? extends K, ? extends V> map) { throw new UnsupportedOperationException(); }
@Override public boolean putAll(MultiValuedMap<? extends K, ? extends V> map) { return decorated().putAll(map); }
private static void printTheNodesOrTestsMatchingSearchedText(ToolArgs toolArgs, MultiValuedMap<String, String> buildNodesArtifacts) { toolArgs.htmlGenerator.addParagraph("Print the nodes matching the searched text \"" + StringEscapeUtils.escapeHtml4(toolArgs.searchedText) + "\" in artifacts for ".concat(toolArgs.jobUrl).concat(": ")); System.out.println("\nPrint the nodes matching the searched text \"" + toolArgs.searchedText + "\" in artifacts: "); toolArgs.htmlGenerator.startTable(); toolArgs.htmlGenerator.startRow().addColumnValue("Build", true).addColumnValue("Nodes", true).addColumnValue("Artifacts", true).endRow(); System.out.println("-> Found the searched text in <b>".concat(String.valueOf(buildNodesArtifacts.keySet().size())).concat("</b> build nodes.")); // sort the results in ascending buildNumber_nodeUrl order Map.Entry<String, String>[] buildNodesArtifactsArray = buildNodesArtifacts.entries().toArray(new Map.Entry[0]); Arrays.parallelSort(buildNodesArtifactsArray, (o1, o2) -> o1.getKey().compareTo(o2.getKey())); String lastBuild = ""; String lastNode = ""; String artifactsColumnValue = ""; for (Map.Entry<String, String> buildNodeArtifact : buildNodesArtifactsArray) { String[] buildNodeTokens = buildNodeArtifact.getKey().split(KEYS_SEPARATOR); String currentBuild = buildNodeTokens[0]; String currentNode = buildNodeTokens[1]; boolean isDifferentNode = !currentNode.equals(lastNode); if (isDifferentNode && !artifactsColumnValue.isEmpty()) { toolArgs.htmlGenerator.addColumnValue(artifactsColumnValue).endRow(); } if (!currentBuild.equals(lastBuild)) { lastBuild = currentBuild; toolArgs.htmlGenerator.startRow().addColumnValue("#".concat(currentBuild)).addColumnValue("").addColumnValue("").endRow(); System.out.println("\nBuild: ".concat(currentBuild)); } if (isDifferentNode) { lastNode = currentNode; toolArgs.htmlGenerator.startRow().addColumnValue("").addColumnValue(currentNode.replace(toolArgs.jobUrl, ""), currentNode); artifactsColumnValue = ""; System.out.println("\tNode: ".concat(currentNode)); } if (toolArgs.searchInJUnitReports) { artifactsColumnValue += new HtmlGenerator().addLink(buildNodeArtifact.getValue(), buildTestReportLink(currentNode, buildNodeArtifact.getValue())).addNewLine().getContent(); System.out.println("\t\tFailed test report: ".concat(buildTestReportLink(currentNode, buildNodeArtifact.getValue()))); } else { artifactsColumnValue += new HtmlGenerator().addLink(buildNodeArtifact.getValue(), buildArtifactLink(currentNode, buildNodeArtifact.getValue())).addNewLine().getContent(); System.out.println("\t\tArtifact relative path: ".concat(buildNodeArtifact.getValue())); } } toolArgs.htmlGenerator.addColumnValue(artifactsColumnValue).endRow(); toolArgs.htmlGenerator.startRow().addColumnValue("Nodes count: ".concat(String.valueOf(buildNodesArtifacts.keySet().size())), true).addColumnValue("").addColumnValue("").endRow().endTable().addNewLine(); }
private static void printTheTestFailuresDifference(ToolArgs toolArgs, MultiValuedMap<String, TestFailure> buildNodesTestFailures, MultiValuedMap<String, TestFailure> buildNodesTestFailures2) { toolArgs.htmlGenerator.addParagraph("Comparison results for job ".concat(toolArgs.jobUrl).concat(", builds ").concat(toolArgs.builds.toString()).concat(", compared to ").concat(toolArgs.jobUrl2).concat(", builds ").concat(toolArgs.referenceBuilds.toString()).concat(":")); System.out.println("\nComparison results for job ".concat(toolArgs.jobUrl).concat(", builds ").concat(toolArgs.builds.toString()).concat(", compared to ").concat(toolArgs.jobUrl2).concat(", builds ").concat(toolArgs.referenceBuilds.toString()).concat(":")); toolArgs.htmlGenerator.addParagraph("-> Found <b>".concat(String.valueOf(buildNodesTestFailures.keySet().size())).concat("</b> instead of <b>").concat(String.valueOf(buildNodesTestFailures2.keySet().size())).concat("</b> failed tests.")); System.out.println("-> Found ".concat(String.valueOf(buildNodesTestFailures.keySet().size())).concat(" instead of ").concat(String.valueOf(buildNodesTestFailures2.keySet().size())).concat(" failed tests.")); // sort the results by testName in ascending order Map.Entry<String, TestFailure>[] buildNodesTestFailuresArray = buildNodesTestFailures.entries().toArray(new Map.Entry[0]); Arrays.parallelSort(buildNodesTestFailuresArray, (o1, o2) -> o1.getKey().compareTo(o2.getKey())); // compare the tests failures and print the differences toolArgs.htmlGenerator.addParagraph("New failed tests:"); toolArgs.htmlGenerator.startTable().startRow().addColumnValue("Test Name/Link", true).addColumnValue("Failure Message", true); toolArgs.htmlGenerator = toolArgs.integrateJira ? toolArgs.htmlGenerator.addColumnValue("Known Issues", true).endRow(): toolArgs.htmlGenerator.endRow(); HtmlGenerator differentFailuresReport = new HtmlGenerator(); differentFailuresReport.addParagraph("Failed tests with different failure:"); differentFailuresReport.startTable().startRow().addColumnValue("Test Name/Link", true).addColumnValue("Failure Message", true); differentFailuresReport = toolArgs.integrateJira ? differentFailuresReport.addColumnValue("Known Issues", true).endRow(): differentFailuresReport.endRow(); System.out.println("\n#TestUrl\t#Failure\t#ReferenceFailure"); int differencesCount = 0; int newFailuresCount = 0; int differentFailuresCount = 0; for (Map.Entry<String, TestFailure> buildTestFailure : buildNodesTestFailuresArray) { String currentKey = buildTestFailure.getKey(); List<TestFailure> referenceTestFailures = (List<TestFailure>) buildNodesTestFailures2.get(currentKey); boolean failureFound = false; for (TestFailure testFailure: referenceTestFailures) { if (failuresAreEqual(buildTestFailure.getValue().failureToCompare, testFailure.failureToCompare, toolArgs.diffThreshold)) { failureFound = true; break; } } if (!failureFound) { differencesCount++; TestFailure currentValue = buildTestFailure.getValue(); String referenceTestFailure = "N/A"; if (referenceTestFailures.size() == 0 ) { newFailuresCount++; toolArgs.htmlGenerator.startRow().addColumnValue(currentValue.testName, currentValue.testUrl).addColumnValue(StringEscapeUtils.escapeHtml4(currentValue.failureToDisplay)); toolArgs.htmlGenerator = toolArgs.integrateJira ? toolArgs.htmlGenerator.addColumnValue(getIssuesLinks(toolArgs, currentValue.shortTestName)).endRow(): toolArgs.htmlGenerator.endRow(); } else { differentFailuresCount++; differentFailuresReport.startRow().addColumnValue(currentValue.testName, currentValue.testUrl).addColumnValue(StringEscapeUtils.escapeHtml4(currentValue.failureToDisplay)); differentFailuresReport = toolArgs.integrateJira ? differentFailuresReport.addColumnValue(getIssuesLinks(toolArgs, currentValue.shortTestName)).endRow(): differentFailuresReport.endRow(); referenceTestFailure = referenceTestFailures.get(0).failureToDisplay; } System.out.println(currentValue.testUrl.concat("\t\"").concat(currentValue.failureToDisplay).concat("\"\t\"").concat(referenceTestFailure).concat("\"")); } } toolArgs.htmlGenerator.startRow().addColumnValue("<b>Failures differences count: ".concat(String.valueOf(newFailuresCount)).concat("</b>")).addColumnValue(""); toolArgs.htmlGenerator = toolArgs.integrateJira ? toolArgs.htmlGenerator.addColumnValue("").endRow().endTable().addNewLine(): toolArgs.htmlGenerator.endRow().endTable().addNewLine(); differentFailuresReport.startRow().addColumnValue("<b>Failures differences count: ".concat(String.valueOf(differentFailuresCount)).concat("</b>")).addColumnValue(""); differentFailuresReport = toolArgs.integrateJira ? differentFailuresReport.addColumnValue("").endRow().endTable().addNewLine(): differentFailuresReport.endRow().endTable().addNewLine(); toolArgs.htmlGenerator.addHtml(differentFailuresReport); System.out.println("-> Found ".concat(String.valueOf(differencesCount)).concat(" new test failures.")); }
public void setEntities(MultiValuedMap<Long, Entity> entities) { this.entities = entities; }
public MinBodyActivityProvider(MultiValuedMap<Integer, Integer> bodyToLiterals, Map<Integer, Double> activityCounters, double defaultActivity) { super(bodyToLiterals, activityCounters, defaultActivity); }
public AvgBodyActivityProvider(MultiValuedMap<Integer, Integer> bodyToLiterals, Map<Integer, Double> activityCounters, double defaultActivity) { super(bodyToLiterals, activityCounters, defaultActivity); }
public SumBodyActivityProvider(MultiValuedMap<Integer, Integer> bodyToLiterals, Map<Integer, Double> activityCounters, double defaultActivity) { super(bodyToLiterals, activityCounters, defaultActivity); }
public BodyActivityProvider(MultiValuedMap<Integer, Integer> bodyToLiterals, Map<Integer, Double> activityCounters, double defaultActivity) { this.bodyToLiterals = bodyToLiterals; this.activityCounters = activityCounters; this.defaultActivity = defaultActivity; }