List of usage examples for com.google.common.collect MapDifference areEqual
boolean areEqual();
From source file:com.github.jcustenborder.kafka.connect.utils.GenericAssertions.java
public static void assertMap(Map<String, ?> expected, Map<String, ?> actual, String message) { if (null == expected && null == actual) { return;// w ww .j a v a 2s . c om } String prefix = Strings.isNullOrEmpty(message) ? "" : message + ": "; assertNotNull(expected, prefix + "expected cannot be null"); assertNotNull(actual, prefix + "actual cannot be null"); MapDifference<String, ?> mapDifference = Maps.difference(expected, actual); assertTrue(mapDifference.areEqual(), new MapDifferenceSupplier(mapDifference, prefix)); }
From source file:com.github.jcustenborder.kafka.connect.cdc.ChangeAssertions.java
static void assertMap(Map<String, ?> expected, Map<String, ?> actual, String message) { if (null == expected && null == actual) { return;/* w ww . j a va 2s .c o m*/ } String prefix = Strings.isNullOrEmpty(message) ? "" : message + ": "; assertNotNull(expected, prefix + "expected cannot be null"); assertNotNull(actual, prefix + "actual cannot be null"); MapDifference<String, ?> mapDifference = Maps.difference(expected, actual); assertTrue(mapDifference.areEqual(), new MapDifferenceSupplier(mapDifference, prefix)); }
From source file:co.mitro.core.util.ParallelPhantomLoginMain.java
static synchronized final void addFlattenedSiteData(String key, Map<String, String> data) { newData.put(key, data);/*ww w . ja v a 2s . c om*/ if (oldData.containsKey(key)) { MapDifference<String, String> differences = Maps.difference(data, oldData.get(key)); if (differences.areEqual()) { safePrintln("data for " + key + " has not changed."); return; } else { safePrintln("data for " + key + " differs:"); for (String s : differences.entriesOnlyOnLeft().keySet()) { safePrintln("\tNew key " + s); } for (String s : differences.entriesOnlyOnRight().keySet()) { safePrintln("\tMissing key " + s); } for (String s : differences.entriesDiffering().keySet()) { safePrintln("\tKey[" + key + "]" + " old:" + differences.entriesDiffering().get(s).rightValue() + " new:" + differences.entriesDiffering().get(s).leftValue()); } } } else { safePrintln("no old data for " + key); } }
From source file:org.wso2.carbon.governance.comparator.utils.WSDLComparisonUtils.java
public static boolean isDiffrentMessages(Message left, Message right) { if (left.getQName().equals(right.getQName())) { Map<String, Part> leftParts = left.getParts(); Map<String, Part> rightParts = right.getParts(); MapDifference mapDiff = Maps.difference(leftParts, rightParts); if (mapDiff.areEqual()) { return false; } else {/*from w w w. j a v a 2s . co m*/ Map<String, MapDifference.ValueDifference<Part>> difference = mapDiff.entriesDiffering(); for (MapDifference.ValueDifference<Part> diff : difference.values()) { if (isDiffrentParts(diff.leftValue(), diff.rightValue())) { return true; } } } } return false; }
From source file:org.openengsb.core.util.ConfigUtils.java
/** * apply the differences to the given map (3-way-merge) * * @throws MergeException if the changes cannot be applied because of merge-conflicts *//*from w ww .ja v a 2 s .c o m*/ public static <K, V> Map<K, V> updateMap(final Map<K, V> original, MapDifference<K, V> diff) throws MergeException { Map<K, V> result = new HashMap<K, V>(original); if (diff.areEqual()) { return result; } for (Entry<K, V> entry : diff.entriesOnlyOnLeft().entrySet()) { V originalValue = original.get(entry.getKey()); if (ObjectUtils.equals(originalValue, entry.getValue())) { result.remove(entry.getKey()); } } for (Entry<K, V> entry : diff.entriesOnlyOnRight().entrySet()) { K key = entry.getKey(); if (original.containsKey(key)) { if (ObjectUtils.notEqual(original.get(key), entry.getValue())) { throw new MergeException( String.format("tried to introduce a new value, but it was already there: %s (%s,%s)", key, original.get(key), entry.getValue())); } } result.put(entry.getKey(), entry.getValue()); } for (Entry<K, ValueDifference<V>> entry : diff.entriesDiffering().entrySet()) { K key = entry.getKey(); V originalValue = original.get(entry.getKey()); if (ObjectUtils.equals(originalValue, entry.getValue().leftValue())) { // Map changed in diff only result.put(key, entry.getValue().rightValue()); } else if (ObjectUtils.equals(originalValue, entry.getValue().rightValue())) { // Diff would change value to value already in original Map result.put(key, originalValue); } else { // Merge conflict, got 3 different Values String errorMessage = String.format( "Changes could not be applied, because original value differes from left-side of the" + "MapDifference: %s (%s,%s)", entry.getKey(), original.get(entry.getKey()), entry.getValue()); throw new MergeException(errorMessage); } } return result; }
From source file:org.sonarsource.sonarlint.core.container.connected.update.check.ModuleStorageUpdateChecker.java
private static void checkForQualityProfilesUpdates(DefaultStorageUpdateCheckResult result, ModuleConfiguration serverModuleConfiguration, ModuleConfiguration storageModuleConfiguration) { MapDifference<String, String> qProfileDiff = Maps.difference( storageModuleConfiguration.getQprofilePerLanguageMap(), serverModuleConfiguration.getQprofilePerLanguageMap()); if (!qProfileDiff.areEqual()) { for (Map.Entry<String, String> entry : qProfileDiff.entriesOnlyOnLeft().entrySet()) { LOG.debug("Quality profile for language '{}' removed", entry.getKey()); }/* ww w .j a v a2 s . c o m*/ for (Map.Entry<String, String> entry : qProfileDiff.entriesOnlyOnRight().entrySet()) { LOG.debug("Quality profile for language '{}' added with value '{}'", entry.getKey(), entry.getValue()); } for (Map.Entry<String, ValueDifference<String>> entry : qProfileDiff.entriesDiffering().entrySet()) { LOG.debug("Quality profile for language '{}' changed from '{}' to '{}'", entry.getKey(), entry.getValue().leftValue(), entry.getValue().rightValue()); } // Don't report update when QP removed since this is harmless for the analysis if (!qProfileDiff.entriesOnlyOnRight().isEmpty() || !qProfileDiff.entriesDiffering().isEmpty()) { result.appendToChangelog("Quality profiles configuration changed"); } } }
From source file:org.jpmml.evaluator.BatchUtil.java
static public List<MapDifference<FieldName, ?>> difference(Batch batch, final double precision, final double zeroThreshold) throws Exception { List<? extends Map<FieldName, ?>> input = CsvUtil.load(batch.getInput()); List<? extends Map<FieldName, String>> output = CsvUtil.load(batch.getOutput()); Evaluator evaluator = PMMLUtil.createModelEvaluator(batch.getModel(), ModelEvaluatorFactory.getInstance()); List<FieldName> groupFields = evaluator.getGroupFields(); List<FieldName> targetFields = evaluator.getTargetFields(); if (groupFields.size() == 1) { FieldName groupField = groupFields.get(0); input = EvaluatorUtil.groupRows(groupField, input); } else//from w w w . jav a 2s . c o m if (groupFields.size() > 1) { throw new EvaluationException(); } Equivalence<Object> equivalence = new Equivalence<Object>() { @Override public boolean doEquivalent(Object expected, Object actual) { actual = EvaluatorUtil.decode(actual); return VerificationUtil.acceptable(TypeUtil.parseOrCast(TypeUtil.getDataType(actual), expected), actual, precision, zeroThreshold); } @Override public int doHash(Object object) { return object.hashCode(); } }; if (output.size() > 0) { if (input.size() != output.size()) { throw new EvaluationException(); } List<MapDifference<FieldName, ?>> differences = Lists.newArrayList(); for (int i = 0; i < input.size(); i++) { Map<FieldName, ?> arguments = input.get(i); Map<FieldName, ?> result = evaluator.evaluate(arguments); // Delete the synthetic target field if (targetFields.size() == 0) { result = Maps.newLinkedHashMap(result); result.remove(evaluator.getTargetField()); } MapDifference<FieldName, Object> difference = Maps.<FieldName, Object>difference(output.get(i), result, equivalence); if (!difference.areEqual()) { differences.add(difference); } } return differences; } else { for (int i = 0; i < input.size(); i++) { Map<FieldName, ?> arguments = input.get(i); evaluator.evaluate(arguments); } return Collections.emptyList(); } }
From source file:org.sonarsource.sonarlint.core.container.connected.update.check.ModuleStorageUpdateChecker.java
private static void checkForSettingsUpdates(DefaultStorageUpdateCheckResult result, ModuleConfiguration serverModuleConfiguration, ModuleConfiguration storageModuleConfiguration) { MapDifference<String, String> propDiff = Maps.difference( GlobalSettingsUpdateChecker.filter(storageModuleConfiguration.getPropertiesMap()), GlobalSettingsUpdateChecker.filter(serverModuleConfiguration.getPropertiesMap())); if (!propDiff.areEqual()) { result.appendToChangelog("Project settings updated"); for (Map.Entry<String, String> entry : propDiff.entriesOnlyOnLeft().entrySet()) { LOG.debug("Property '{}' removed", entry.getKey()); }//from w w w.j a va2 s . co m for (Map.Entry<String, String> entry : propDiff.entriesOnlyOnRight().entrySet()) { LOG.debug("Property '{}' added with value '{}'", entry.getKey(), GlobalSettingsUpdateChecker.formatValue(entry.getKey(), entry.getValue())); } for (Map.Entry<String, ValueDifference<String>> entry : propDiff.entriesDiffering().entrySet()) { LOG.debug("Value of property '{}' changed from '{}' to '{}'", entry.getKey(), GlobalSettingsUpdateChecker.formatLeftDiff(entry.getKey(), entry.getValue().leftValue(), entry.getValue().rightValue()), GlobalSettingsUpdateChecker.formatRightDiff(entry.getKey(), entry.getValue().leftValue(), entry.getValue().rightValue())); } } }
From source file:org.nuxeo.tools.esync.checker.TypeCardinalityChecker.java
@Override void check() {//www . j a va2s . co m Map<String, Long> esTypes = es.getTypeCardinality(); Map<String, Long> dbTypes = db.getTypeCardinality(); MapDifference<String, Long> diff = Maps.difference(dbTypes, esTypes); if (diff.areEqual()) { postMessage("Found same types cardinality"); return; } postMessage("Difference found in types cardinality."); for (String key : diff.entriesOnlyOnLeft().keySet()) { postError(String.format("Missing type on ES: %s, expected: %d", key, dbTypes.get(key))); } for (String key : diff.entriesOnlyOnRight().keySet()) { postError(String.format("Spurious type in ES: %s, actual: %d", key, esTypes.get(key))); } for (String key : diff.entriesDiffering().keySet()) { long esCount = 0; long dbCount = 0; if (esTypes.containsKey(key)) { esCount = esTypes.get(key); } if (dbTypes.containsKey(key)) { dbCount = dbTypes.get(key); } postError(String.format("Document type %s (including versions), expected: %d, actual: %d, diff: %d", key, dbCount, esCount, dbCount - esCount)); post(new DiffTypeEvent(key, "diff")); } }
From source file:org.sonarsource.sonarlint.core.container.connected.update.check.QualityProfilesUpdateChecker.java
public void checkForUpdates(DefaultStorageUpdateCheckResult result) { QProfiles serverQualityProfiles = qualityProfilesDownloader.fetchQualityProfiles(); QProfiles storageQProfiles = storageManager.readQProfilesFromStorage(); Map<String, QProfile> serverPluginHashes = serverQualityProfiles.getQprofilesByKeyMap(); Map<String, QProfile> storagePluginHashes = storageQProfiles.getQprofilesByKeyMap(); MapDifference<String, QProfile> pluginDiff = Maps.difference(storagePluginHashes, serverPluginHashes); if (!pluginDiff.areEqual()) { for (Map.Entry<String, QProfile> entry : pluginDiff.entriesOnlyOnLeft().entrySet()) { result.appendToChangelog(String.format("Quality profile '%s' for language '%s' removed", entry.getValue().getName(), entry.getValue().getLanguageName())); }/*from w w w . java2 s . c o m*/ for (Map.Entry<String, QProfile> entry : pluginDiff.entriesOnlyOnRight().entrySet()) { result.appendToChangelog(String.format("Quality profile '%s' for language '%s' added", entry.getValue().getName(), entry.getValue().getLanguageName())); } for (Map.Entry<String, ValueDifference<QProfile>> entry : pluginDiff.entriesDiffering().entrySet()) { result.appendToChangelog(String.format("Quality profile '%s' for language '%s' updated", entry.getValue().rightValue().getName(), entry.getValue().rightValue().getLanguageName())); } } }