List of usage examples for java.util Map equals
boolean equals(Object o);
From source file:org.elasticsearch.upgrades.FullClusterRestartIT.java
private void checkSnapshot(String snapshotName, int count, Version tookOnVersion) throws IOException { // Check the snapshot metadata, especially the version String response = toStr(//from www .j a va 2s . c o m client().performRequest("GET", "/_snapshot/repo/" + snapshotName, listSnapshotVerboseParams())); Map<String, Object> map = toMap(response); assertEquals(response, singletonList(snapshotName), XContentMapValues.extractValue("snapshots.snapshot", map)); assertEquals(response, singletonList("SUCCESS"), XContentMapValues.extractValue("snapshots.state", map)); assertEquals(response, singletonList(tookOnVersion.toString()), XContentMapValues.extractValue("snapshots.version", map)); // Remove the routing setting and template so we can test restoring them. HttpEntity clearRoutingSetting = new StringEntity( "{\"persistent\":{\"cluster.routing.allocation.exclude.test_attr\": null}}", ContentType.APPLICATION_JSON); client().performRequest("PUT", "/_cluster/settings", emptyMap(), clearRoutingSetting); client().performRequest("DELETE", "/_template/test_template", emptyMap(), clearRoutingSetting); // Restore XContentBuilder restoreCommand = JsonXContent.contentBuilder().startObject(); restoreCommand.field("include_global_state", true); restoreCommand.field("indices", index); restoreCommand.field("rename_pattern", index); restoreCommand.field("rename_replacement", "restored_" + index); restoreCommand.endObject(); client().performRequest("POST", "/_snapshot/repo/" + snapshotName + "/_restore", singletonMap("wait_for_completion", "true"), new StringEntity(Strings.toString(restoreCommand), ContentType.APPLICATION_JSON)); // Make sure search finds all documents String countResponse = toStr( client().performRequest("GET", "/restored_" + index + "/_search", singletonMap("size", "0"))); assertThat(countResponse, containsString("\"total\":" + count)); // Add some extra documents to the index to be sure we can still write to it after restoring it int extras = between(1, 100); StringBuilder bulk = new StringBuilder(); for (int i = 0; i < extras; i++) { bulk.append("{\"index\":{\"_id\":\"").append(count + i).append("\"}}\n"); bulk.append("{\"test\":\"test\"}\n"); } client().performRequest("POST", "/restored_" + index + "/doc/_bulk", singletonMap("refresh", "true"), new StringEntity(bulk.toString(), ContentType.APPLICATION_JSON)); // And count to make sure the add worked // Make sure search finds all documents countResponse = toStr( client().performRequest("GET", "/restored_" + index + "/_search", singletonMap("size", "0"))); assertThat(countResponse, containsString("\"total\":" + (count + extras))); // Clean up the index for the next iteration client().performRequest("DELETE", "/restored_*"); // Check settings added by the restore process map = toMap(client().performRequest("GET", "/_cluster/settings", singletonMap("flat_settings", "true"))); Map<String, Object> expected = new HashMap<>(); expected.put("transient", emptyMap()); expected.put("persistent", singletonMap("cluster.routing.allocation.exclude.test_attr", oldClusterVersion.toString())); if (expected.equals(map) == false) { NotEqualMessageBuilder builder = new NotEqualMessageBuilder(); builder.compareMaps(map, expected); fail("settings don't match:\n" + builder.toString()); } // Check that the template was restored successfully map = toMap(client().performRequest("GET", "/_template/test_template")); expected = new HashMap<>(); if (runningAgainstOldCluster && oldClusterVersion.before(Version.V_6_0_0_beta1)) { expected.put("template", "evil_*"); } else { expected.put("index_patterns", singletonList("evil_*")); } expected.put("settings", singletonMap("index", singletonMap("number_of_shards", "1"))); expected.put("mappings", singletonMap("doc", singletonMap("_source", singletonMap("enabled", true)))); expected.put("order", 0); Map<String, Object> aliases = new HashMap<>(); aliases.put("alias1", emptyMap()); aliases.put("alias2", singletonMap("filter", singletonMap("term", singletonMap("version", tookOnVersion.toString())))); expected.put("aliases", aliases); expected = singletonMap("test_template", expected); if (false == expected.equals(map)) { NotEqualMessageBuilder builder = new NotEqualMessageBuilder(); builder.compareMaps(map, expected); fail("template doesn't match:\n" + builder.toString()); } }
From source file:org.geowebcache.layer.TileLayer.java
/** * // w w w. java2s . co m * @param map * keys are parameter names, values are either a single string or an array of strings * as they come form httpservletrequest * @return Set of parameter filter keys and values, with keys normalized to upper case, or empty * map if they match the layer's parameter filters default values * @throws GeoWebCacheException * if {@link ParameterFilter#apply(String)} does */ public Map<String, String> getModifiableParameters(Map<String, ?> map, String encoding) throws GeoWebCacheException { final List<ParameterFilter> parameterFilters = getParameterFilters(); if (parameterFilters == null) { return Collections.emptyMap(); } Map<String, String> fullParameters = new HashMap<String, String>(); final String[] keys = new String[parameterFilters.size()]; for (int i = 0; i < parameterFilters.size(); i++) { ParameterFilter parameterFilter = parameterFilters.get(i); keys[i] = parameterFilter.getKey(); } final Map<String, String> requestValues; requestValues = ServletUtils.selectedStringsFromMap(map, encoding, keys); final Map<String, String> defaultValues = getDefaultParameterFilters(); for (ParameterFilter parameterFilter : parameterFilters) { String key = parameterFilter.getKey().toUpperCase(); String value = requestValues.get(key); value = decodeDimensionValue(value); String defaultValue = defaultValues.get(key); if (value == null || value.length() == 0 || (defaultValue != null && defaultValue.equals(value))) { fullParameters.put(key, defaultValue); } else { String appliedValue = parameterFilter.apply(value); fullParameters.put(key, appliedValue); } } if (defaultValues.equals(fullParameters)) { return Collections.emptyMap(); } return fullParameters; }
From source file:org.kuali.rice.kim.impl.role.RoleServiceBase.java
protected boolean doesMemberMatch(RoleMemberBo roleMember, String memberId, String memberTypeCode, Map<String, String> qualifier) { if (roleMember.getMemberId().equals(memberId) && roleMember.getType().getCode().equals(memberTypeCode)) { // member ID/type match Map<String, String> roleQualifier = roleMember.getAttributes(); if ((qualifier == null || qualifier.isEmpty()) && (roleQualifier == null || roleQualifier.isEmpty())) { return true; // blank qualifier match } else {//from w w w . j a v a2 s . c o m if (qualifier != null && roleQualifier != null && qualifier.equals(roleQualifier)) { return true; // qualifier match } } } return false; }
From source file:eu.sonata.nfv.nec.convert.BasicConverterTest.java
@Test public void convertToMap() { Map<String, Object> map = new HashMap<>(); map.put("foo", "bar"); map.put("corge", null); map.put("grault", 1); map.put("garply", true); map.put("waldo", "false"); map.put("fred", "undefined"); map.put("emptyString", ""); map.put("emptyArray", new ArrayList<>(0)); map.put("emptyObject", new HashMap<>(0)); map.put("baz", new ArrayList<>(Arrays.asList("qux", "quxx"))); Map<String, Object> jsonMap = conversionService.convertToMap(jsonString); Map<String, Object> yamlMap = conversionService.convertToMap(yamlString); /*/*from w w w . j a v a 2 s . co m*/ // Can be used to debug the test method. System.out.println("TEST1: " + map); System.out.println("TEST2: " + jsonMap); System.out.println("TEST3: " + jsonMap); for (Map.Entry<String, Object> entry : map.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); Object jsonValue = jsonMap.get(key); if (value != null && !value.equals(jsonValue)) { System.out.println("TEST4: " + key + " : " + value + " : " + jsonValue); System.out.println("TEST5: " + value.getClass()); System.out.println("TEST6: " + jsonValue.getClass()); } } */ assertTrue("The JSON map should be equal. ", map.equals(jsonMap)); assertTrue("The YAML map should be equal. ", map.equals(yamlMap)); }
From source file:com.opengamma.masterdb.batch.DbBatchWriter.java
public synchronized RiskRun startBatchInTransaction(ViewCycleMetadata cycleMetadata, Map<String, String> batchParameters, RunCreationMode runCreationMode, SnapshotMode snapshotMode) { s_logger.info("Starting batch ... {}", cycleMetadata); RiskRun run;/*from w w w. j a v a2 s .co m*/ switch (runCreationMode) { case AUTO: run = findRiskRunInDb(cycleMetadata.getValuationTime(), cycleMetadata.getVersionCorrection(), cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId()); if (run != null) { // also check parameter equality Map<String, String> existingProperties = run.getPropertiesMap(); if (!existingProperties.equals(batchParameters)) { Set<Map.Entry<String, String>> symmetricDiff = Sets .symmetricDifference(existingProperties.entrySet(), batchParameters.entrySet()); throw new IllegalStateException( "Run parameters stored in DB differ from new parameters with respect to: " + symmetricDiff); } } if (run == null) { run = createRiskRunInTransaction(cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId(), cycleMetadata.getVersionCorrection(), cycleMetadata.getValuationTime(), batchParameters, snapshotMode); } else { restartRunInTransaction(run); } break; case CREATE_NEW_OVERWRITE: run = findRiskRunInDb(cycleMetadata.getValuationTime(), cycleMetadata.getVersionCorrection(), cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId()); if (run != null) { deleteRunInTransaction(run); } run = createRiskRunInTransaction(cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId(), cycleMetadata.getVersionCorrection(), cycleMetadata.getValuationTime(), batchParameters, snapshotMode); break; case CREATE_NEW: run = createRiskRunInTransaction(cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId(), cycleMetadata.getVersionCorrection(), cycleMetadata.getValuationTime(), batchParameters, snapshotMode); break; case REUSE_EXISTING: run = findRiskRunInDb(cycleMetadata.getValuationTime(), cycleMetadata.getVersionCorrection(), cycleMetadata.getViewDefinitionId(), cycleMetadata.getMarketDataSnapshotId()); if (run == null) { throw new IllegalStateException("Cannot find run in database for " + cycleMetadata); } restartRunInTransaction(run); break; default: throw new RuntimeException("Unexpected run creation mode " + runCreationMode); } populateCalculationConfigurations(run.getId(), cycleMetadata); populateRiskValueRequirements(cycleMetadata); Collection<ComputationTargetSpecification> computationTargets = newArrayList(); for (final String configName : cycleMetadata.getAllCalculationConfigurationNames()) { for (com.opengamma.engine.ComputationTargetSpecification computationTarget : cycleMetadata .getComputationTargets(configName)) { computationTargets.add(computationTarget); } } populateComputationTargets(computationTargets); _statusCacheByRunId.put(run.getId(), new ConcurrentHashMap<Pair<Long, Long>, StatusEntry>()); _computeFailureCacheByRunId.put(run.getId(), new ConcurrentHashMap<ComputeFailureKey, ComputeFailure>()); _riskRunsByIds.put(run.getId(), run); return run; }
From source file:com.rapidminer.gui.new_plotter.configuration.PlotConfiguration.java
/** * @param colorScheme/* w ww. ja va2 s . com*/ * the colorScheme to set */ public void setColorSchemes(Map<String, ColorScheme> colorSchemes, String activeColorSchemeName) { boolean changed = false; ColorScheme oldActiveScheme = getActiveColorScheme(); if (!colorSchemes.equals(this.colorSchemes)) { this.colorSchemes = colorSchemes; changed = true; } if (!oldActiveScheme.equals(colorSchemes.get(activeColorSchemeName))) { setActiveScheme(activeColorSchemeName); changed = true; } if (changed) { firePlotConfigurationChanged(new PlotConfigurationChangeEvent(this, getActiveColorScheme())); } }
From source file:org.springframework.data.crate.core.convert.MappingCrateConverterTest.java
@Test public void shouldWriteCollectionOfMaps() { CollectionOfMaps entity = new CollectionOfMaps(); entity.maps = singletonList(singletonMap("STRING", 1)); CrateDocument map = new CrateDocument("STRING", 1); CrateArray collectionDocument = new CrateArray(map); Map<String, Object> expected = new HashMap<String, Object>(); expected.put(DEFAULT_TYPE_KEY, CollectionOfMaps.class.getName()); expected.put("maps", collectionDocument); CrateDocument document = new CrateDocument(); converter.write(entity, document);/*from w w w.j a v a2s . c o m*/ assertThat(expected.equals(document), is(true)); }
From source file:org.springframework.data.crate.core.convert.MappingCrateConverterTest.java
@Test public void shouldWriteWithComplexId() { Country country = new Country("aCountry", asList(new Language("aLanguage"))); Address address = new Address(); address.country = country;//from w ww. j av a 2s .c o m address.city = "aCity"; address.street = "aStreet"; Person person = new Person(); person.name = "aName"; person.address = address; person.emails = new HashSet<MappingCrateConverterTest.Email>(asList(new Email("email@test.com"))); ComplexId entity = new ComplexId(); entity.pk = person; entity.string = "STRING"; CrateDocument languageDocument = new CrateDocument("name", "aLanguage"); CrateDocument emailDocument = new CrateDocument("email", "email@test.com"); CrateArray languagesArray = new CrateArray(languageDocument); CrateArray emailsArray = new CrateArray(emailDocument); CrateDocument countryDocument = new CrateDocument(); countryDocument.put("name", "aCountry"); countryDocument.put("languages", languagesArray); CrateDocument addressDocument = new CrateDocument(); addressDocument.put("country", countryDocument); addressDocument.put("city", "aCity"); addressDocument.put("street", "aStreet"); CrateDocument personDocument = new CrateDocument(); personDocument.put("name", "aName"); personDocument.put("address", addressDocument); personDocument.put("emails", emailsArray); Map<String, Object> expected = new HashMap<String, Object>(); expected.put(DEFAULT_TYPE_KEY, ComplexId.class.getName()); expected.put("string", "STRING"); expected.put("pk", personDocument); CrateDocument document = new CrateDocument(); converter.write(entity, document); assertThat(expected.equals(document), is(true)); }
From source file:org.springframework.data.crate.core.convert.MappingCrateConverterTest.java
@Test public void shouldWriteComplexModel() { Country country = new Country("aCountry", asList(new Language("aLanguage"))); Address address = new Address(); address.country = country;/* w ww . j a v a2 s . com*/ address.city = "aCity"; address.street = "aStreet"; Person person = new Person(); person.name = "aName"; person.address = address; person.emails = new HashSet<MappingCrateConverterTest.Email>(asList(new Email("email@test.com"))); CrateDocument languageDocument = new CrateDocument("name", "aLanguage"); CrateDocument emailDocument = new CrateDocument("email", "email@test.com"); CrateArray languagesArray = new CrateArray(languageDocument); CrateArray emailsArray = new CrateArray(emailDocument); CrateDocument countryDocument = new CrateDocument(); countryDocument.put("name", "aCountry"); countryDocument.put("languages", languagesArray); CrateDocument addressDocument = new CrateDocument(); addressDocument.put("country", countryDocument); addressDocument.put("city", "aCity"); addressDocument.put("street", "aStreet"); Map<String, Object> expected = new HashMap<String, Object>(); expected.put(DEFAULT_TYPE_KEY, Person.class.getName()); expected.put("name", "aName"); expected.put("address", addressDocument); expected.put("emails", emailsArray); CrateDocument document = new CrateDocument(); converter.write(person, document); assertThat(expected.equals(document), is(true)); }
From source file:org.springframework.data.crate.core.convert.MappingCrateConverterTest.java
@Test public void shouldWriteNestedMaps() { Map<Integer, List<Boolean>> nested = new HashMap<Integer, List<Boolean>>(); nested.put(1, asList(true, false));/* w ww.ja va 2s . com*/ Map<String, Map<Integer, List<Boolean>>> map = new HashMap<String, Map<Integer, List<Boolean>>>(); map.put("Key", nested); Map<String, Object> expected = new HashMap<String, Object>(); expected.put(DEFAULT_TYPE_KEY, NestedMaps.class.getName()); expected.put("map", new CrateDocument("Key", new CrateDocument("1", asList(true, false)))); NestedMaps entity = new NestedMaps(); entity.map = map; CrateDocument document = new CrateDocument(); converter.write(entity, document); assertThat(expected.equals(document), is(true)); }