List of usage examples for com.google.common.collect MapDifference entriesDiffering
Map<K, ValueDifference<V>> entriesDiffering();
From source file:org.apache.fluo.recipes.core.map.it.DocumentObserver.java
private static Map<String, Long> calculateChanges(Map<String, Long> newCounts, Map<String, Long> currCounts) { Map<String, Long> changes = new HashMap<>(); // guava Maps class MapDifference<String, Long> diffs = Maps.difference(currCounts, newCounts); // compute the diffs for words that changed changes.putAll(//from w ww . j av a 2 s. c o m Maps.transformValues(diffs.entriesDiffering(), vDiff -> vDiff.rightValue() - vDiff.leftValue())); // add all new words changes.putAll(diffs.entriesOnlyOnRight()); // subtract all words no longer present changes.putAll(Maps.transformValues(diffs.entriesOnlyOnLeft(), l -> l * -1)); return changes; }
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 {//www.j a v a2s . c o 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.apache.aurora.scheduler.updater.JobDiff.java
private static JobDiff computeUnscoped(Map<Integer, ITaskConfig> currentState, IJobKey job, Map<Integer, ITaskConfig> proposedState) { requireNonNull(job);//from www . j a v a 2s . com requireNonNull(proposedState); MapDifference<Integer, ITaskConfig> diff = Maps.difference(currentState, proposedState); Map<Integer, ITaskConfig> removedInstances = ImmutableMap.<Integer, ITaskConfig>builder() .putAll(diff.entriesOnlyOnLeft()) .putAll(Maps.transformValues(diff.entriesDiffering(), JobDiff.leftValue())).build(); Set<Integer> addedInstances = ImmutableSet.<Integer>builder().addAll(diff.entriesOnlyOnRight().keySet()) .addAll(diff.entriesDiffering().keySet()).build(); return new JobDiff(removedInstances, addedInstances, ImmutableMap.copyOf(diff.entriesInCommon())); }
From source file:co.mitro.core.util.ParallelPhantomLoginMain.java
static synchronized final void addFlattenedSiteData(String key, Map<String, String> data) { newData.put(key, data);//from www . j a va 2 s . co m 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.apache.cassandra.db.DefsTables.java
private static Set<String> mergeKeyspaces(Map<DecoratedKey, ColumnFamily> before, Map<DecoratedKey, ColumnFamily> after) { List<Row> created = new ArrayList<>(); List<String> altered = new ArrayList<>(); Set<String> dropped = new HashSet<>(); /*/*from ww w . ja v a 2 s .c o m*/ * - we don't care about entriesOnlyOnLeft() or entriesInCommon(), because only the changes are of interest to us * - of all entriesOnlyOnRight(), we only care about ones that have live columns; it's possible to have a ColumnFamily * there that only has the top-level deletion, if: * a) a pushed DROP KEYSPACE change for a keyspace hadn't ever made it to this node in the first place * b) a pulled dropped keyspace that got dropped before it could find a way to this node * - of entriesDiffering(), we don't care about the scenario where both pre and post-values have zero live columns: * that means that a keyspace had been recreated and dropped, and the recreated keyspace had never found a way * to this node */ MapDifference<DecoratedKey, ColumnFamily> diff = Maps.difference(before, after); for (Map.Entry<DecoratedKey, ColumnFamily> entry : diff.entriesOnlyOnRight().entrySet()) if (entry.getValue().getColumnCount() > 0) created.add(new Row(entry.getKey(), entry.getValue())); for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> entry : diff.entriesDiffering() .entrySet()) { String keyspaceName = AsciiType.instance.compose(entry.getKey().key); ColumnFamily pre = entry.getValue().leftValue(); ColumnFamily post = entry.getValue().rightValue(); if (pre.getColumnCount() > 0 && post.getColumnCount() > 0) altered.add(keyspaceName); else if (pre.getColumnCount() > 0) dropped.add(keyspaceName); else if (post.getColumnCount() > 0) // a (re)created keyspace created.add(new Row(entry.getKey(), post)); } for (Row row : created) addKeyspace(KSMetaData.fromSchema(row, Collections.<CFMetaData>emptyList())); for (String name : altered) updateKeyspace(name); return dropped; }
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()); }/* w w w .jav a 2 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.apache.cassandra.db.DefsTables.java
private static void mergeColumnFamilies(Map<DecoratedKey, ColumnFamily> before, Map<DecoratedKey, ColumnFamily> after) { List<CFMetaData> created = new ArrayList<>(); List<CFMetaData> altered = new ArrayList<>(); List<CFMetaData> dropped = new ArrayList<>(); MapDifference<DecoratedKey, ColumnFamily> diff = Maps.difference(before, after); for (Map.Entry<DecoratedKey, ColumnFamily> entry : diff.entriesOnlyOnRight().entrySet()) if (entry.getValue().getColumnCount() > 0) created.addAll(// w w w . j av a2 s.co m KSMetaData.deserializeColumnFamilies(new Row(entry.getKey(), entry.getValue())).values()); for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> entry : diff.entriesDiffering() .entrySet()) { String keyspaceName = AsciiType.instance.compose(entry.getKey().key); ColumnFamily pre = entry.getValue().leftValue(); ColumnFamily post = entry.getValue().rightValue(); if (pre.getColumnCount() > 0 && post.getColumnCount() > 0) { MapDifference<String, CFMetaData> delta = Maps.difference( Schema.instance.getKSMetaData(keyspaceName).cfMetaData(), KSMetaData.deserializeColumnFamilies(new Row(entry.getKey(), post))); dropped.addAll(delta.entriesOnlyOnLeft().values()); created.addAll(delta.entriesOnlyOnRight().values()); Iterables.addAll(altered, Iterables.transform(delta.entriesDiffering().values(), new Function<MapDifference.ValueDifference<CFMetaData>, CFMetaData>() { public CFMetaData apply(MapDifference.ValueDifference<CFMetaData> pair) { return pair.rightValue(); } })); } else if (pre.getColumnCount() > 0) { dropped.addAll(Schema.instance.getKSMetaData(keyspaceName).cfMetaData().values()); } else if (post.getColumnCount() > 0) { created.addAll(KSMetaData.deserializeColumnFamilies(new Row(entry.getKey(), post)).values()); } } for (CFMetaData cfm : created) addColumnFamily(cfm); for (CFMetaData cfm : altered) updateColumnFamily(cfm.ksName, cfm.cfName); for (CFMetaData cfm : dropped) dropColumnFamily(cfm.ksName, cfm.cfName); }
From source file:components.cells.Cells.java
private static <T> Map<IPosition, T> merge(final T initialSymbol, final Map<IPosition, T> left, final Map<IPosition, T> right) { final Builder<IPosition, T> builder = new ImmutableSortedMap.Builder<IPosition, T>(Ordering.natural()); final MapDifference<IPosition, T> difference = Maps.difference(left, right); for (final Entry<IPosition, T> mutation : difference.entriesInCommon().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation);//from w ww. j a v a 2s . co m for (final Entry<IPosition, T> mutation : difference.entriesOnlyOnLeft().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation); for (final Entry<IPosition, T> mutation : difference.entriesOnlyOnRight().entrySet()) if (!mutation.getValue().equals(initialSymbol)) builder.put(mutation); for (final Entry<IPosition, ValueDifference<T>> mutation : difference.entriesDiffering().entrySet()) { final T rightValue = mutation.getValue().rightValue(); if (!rightValue.equals(initialSymbol)) builder.put(mutation.getKey(), rightValue); } return builder.build(); }
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 ww w .ja va2 s . c o 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.eclipse.mdht.uml.common.util.ModelCompare.java
static public void compare(NamedElement element1, NamedElement element2, CompareResultVisitor compareResults) { compareResults.startElement(element1); HashMap<String, Element> umlPackage1HashMap = createElementHashMap(element1); HashMap<String, Element> umlPackage2HashMap = createElementHashMap(element2); MapDifference<String, Element> diff = Maps.difference(umlPackage1HashMap, umlPackage2HashMap, ValueEquivalence.ElementEquivalence); ArrayList<Element> leftElements = getSortedElements(diff.entriesOnlyOnLeft().values()); for (Element eee : leftElements) { compareResults.addedElement(element1, eee); if (eee instanceof Package || eee instanceof org.eclipse.uml2.uml.Class) { compare((NamedElement) eee, null, compareResults); }/*from w w w. ja va 2s. c o m*/ } ArrayList<Element> rightElements = getSortedElements(diff.entriesOnlyOnRight().values()); for (Element eee : rightElements) { compareResults.deletedElement(element1, eee); } ArrayList<ValueDifference<Element>> differences = getSortedValueDifference( diff.entriesDiffering().values()); for (ValueDifference<Element> valueDifference : differences) { compareResults.changedElement(element1, valueDifference.leftValue(), valueDifference.rightValue()); if ((valueDifference.leftValue() instanceof Class) || (valueDifference.leftValue() instanceof Package)) { compare((NamedElement) valueDifference.leftValue(), (NamedElement) valueDifference.rightValue(), compareResults); } } compareResults.endElement(element1); }