private static <K, V> void doDifference( Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) { for (Entry<? extends K, ? extends V> entry : left.entrySet()) { K leftKey = entry.getKey(); V leftValue = entry.getValue(); if (right.containsKey(leftKey)) { V rightValue = onlyOnRight.remove(leftKey); if (valueEquivalence.equivalent(leftValue, rightValue)) { onBoth.put(leftKey, leftValue); } else { differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue)); } } else { onlyOnLeft.put(leftKey, leftValue); } } }
private BiFunction<Entry<ImmutableMap<String, Object>, Collection<Blob>>, Entry<ImmutableMap<String, Object>, Collection<Blob>>, Boolean> isPageBreak(Path path) { if (!path.isPaging()) { return (a,b) -> false; } return (a,b) -> { ImmutableMap<String, Object> keysA = a.getKey(); ImmutableMap<String, Object> keysB = b.getKey(); Map<String, ValueDifference<Object>> diff = Maps.difference(keysA, keysB).entriesDiffering(); Set<String> keySet = diff.keySet(); boolean onlyDifferentPage = keySet.size()==1 && keySet.contains(Path.PAGE); return !onlyDifferentPage; }; }
private void handleChangedLocalIps(Map<String, ValueDifference<String>> changedEntries, BigInteger dpId, Set<String> zonePrefixes, Map<String, List<String>> tepTzMap, WriteTransaction tx) { if (changedEntries == null || changedEntries.isEmpty()) { LOG.trace("No changed local_ips found for DPN {}", dpId); return; } LOG.debug("Changing underlay network mapping for local_ips {} on DPN {}", changedEntries.keySet(), dpId); changedEntries.forEach((ipAddress, underlayNetworkDiff) -> { List<String> zoneNames = tepTzMap.get(ipAddress); if (zoneNames != null) { for (String zoneName : zoneNames) { String removedUnderlayNetwork = underlayNetworkDiff.leftValue(); String addedUnderlayNetwork = underlayNetworkDiff.rightValue(); Optional<String> zonePrefixOpt = getZonePrefixForUnderlayNetwork(zoneName, removedUnderlayNetwork); if (zonePrefixOpt.isPresent()) { String zonePrefix = zonePrefixOpt.get(); removeVtep(zoneName, dpId, ipAddress, tx); zonePrefixes.add(zonePrefix); String newZoneName = getTzNameForUnderlayNetwork(zonePrefix, addedUnderlayNetwork); updateTransportZone(newZoneName, dpId, ipAddress, tx); } } } }); }
private static <K, V> void doDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) { for (Entry<? extends K, ? extends V> entry : left.entrySet()) { K leftKey = entry.getKey(); V leftValue = entry.getValue(); if (right.containsKey(leftKey)) { V rightValue = onlyOnRight.remove(leftKey); if (valueEquivalence.equivalent(leftValue, rightValue)) { onBoth.put(leftKey, leftValue); } else { differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue)); } } else { onlyOnLeft.put(leftKey, leftValue); } } }
protected void describeMismatchSafely(String prefix, MapDifference<TestHistoryDifferenceKey, Collection<TestHistoryDifferenceDescription>> difference, Description mismatchDescription) { appendIfNonEmpty(mismatchDescription, prefix, "missing: ", difference.entriesOnlyOnLeft()); appendIfNonEmpty(mismatchDescription, prefix, "unexpected: ", difference.entriesOnlyOnRight()); for (Entry<TestHistoryDifferenceKey, ValueDifference<Collection<TestHistoryDifferenceDescription>>> entryDiffering : difference.entriesDiffering().entrySet()) { mismatchDescription.appendText(prefix).appendText("differing from expected: ") .appendValue(entryDiffering.getKey()); ValueDifference<Collection<TestHistoryDifferenceDescription>> valueDifference = entryDiffering.getValue(); Collection<TestHistoryDifferenceDescription> expectedCollection = valueDifference.leftValue(); Collection<TestHistoryDifferenceDescription> actualCollection = valueDifference.rightValue(); String newPrefix = prefix + "\t\t"; if (expectedCollection.size() == 1 && actualCollection.size() == 1) { TestHistoryDifferenceDescription expected = Iterables.getOnlyElement(expectedCollection); TestHistoryDifferenceDescription actual = Iterables.getOnlyElement(actualCollection); describeMismatchSafely(newPrefix, expected, actual, mismatchDescription); } else { mismatchDescription.appendText(newPrefix).appendText("expected: ").appendValue(valueDifference.leftValue()); mismatchDescription.appendText(newPrefix).appendText("actual: ").appendValue(valueDifference.rightValue()); } } }
private static <K, V> void doDifference( Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) { for (Entry<? extends K, ? extends V> entry : left.entrySet()) { K leftKey = entry.getKey(); V leftValue = entry.getValue(); if (right.containsKey(leftKey)) { V rightValue = onlyOnRight.remove(leftKey); if (valueEquivalence.equivalent(leftValue, rightValue)) { onBoth.put(leftKey, leftValue); } else { differences.put( leftKey, ValueDifferenceImpl.create(leftValue, rightValue)); } } else { onlyOnLeft.put(leftKey, leftValue); } } }
private SectionParsingResult parseSection(List<String> lines) { Map<String, String> properties = newHashMap(); lines.stream().forEach((String line) -> { if (lineHasProperties(line)) { Map<String, String> lineProperties = parseLineProperties(line); Map<String, ValueDifference<String>> difference = difference(properties, lineProperties).entriesDiffering(); checkState(difference.isEmpty(), "Different properties: ", difference); properties.putAll(lineProperties); } }); List<String> contentFiltered = filterContent(lines); Optional<String> sectionName = Optional.ofNullable(properties.get(SECTION_NAME_KEY)); return new SectionParsingResult(sectionName, lines, properties, contentFiltered); }
/** * This method has been copied from org.eclipse.xtext.builder.preferences.BuilderPreferencePage. */ private void scheduleCleanerJobIfNecessary(IPreferencePageContainer preferencePageContainer) { Map<String, ValueDifference<String>> changes = getPreferenceChanges(); for (String key : changes.keySet()) { if (key.matches("^" + CompilerProperties.OUTPUT_PREFERENCE_TAG + "\\.\\w+\\." + CompilerProperties.OUTPUT_PREFERENCE_TAG + "$")) { ValueDifference<String> difference = changes.get(key); scheduleCleanerJob(preferencePageContainer, difference.rightValue()); } } }
/** * @param outputName * the output name that identifies the output configuration but in our case also the registered compiler. * @param compilerDescriptor * the compiler descriptor holding the values either stored last time this details page was used or the * default values for the compiler */ public void populateCompilerConfiguration(String outputName, T compilerDescriptor) { // defaults preferenceInitializer.initialize(scopedAccessor); boolean initialLoad = false; ComponentDescriptor currentlyStoredCompilerDescriptor = compilerDescriptor .getCurrentlyStoredComponentDescriptor(); if (currentlyStoredCompilerDescriptor == null) { currentlyStoredCompilerDescriptor = compilerDescriptor; // default configuration initialLoad = true; } Map<String, String> originalSettings = currentlyStoredCompilerDescriptor.fillMap(outputName); IPreferenceStore preferenceStore = getPreferenceStore(); // populate // use a copy here has we don't want to change the default values provided by the registered compilers @SuppressWarnings("unchecked") T newCompilerDescriptor = (T) compilerDescriptor.copy(); for (IComponentProperties<T> prop : getComponentPropertiesValues()) { if (prop.getType() == Boolean.class) { prop.setValueInCompilerDescriptor(newCompilerDescriptor, outputName, preferenceStore.getBoolean(prop.getKey(outputName))); } else { prop.setValueInCompilerDescriptor(newCompilerDescriptor, outputName, preferenceStore.getString(prop.getKey(outputName))); } } Map<String, String> currentSettings = newCompilerDescriptor.fillMap(outputName); Map<String, ValueDifference<String>> changes = getPreferenceChanges(originalSettings, currentSettings); if (!initialLoad) { compilerDescriptor.setChanges(changes); } compilerDescriptor.setCurrentlyStoredComponentDescriptor(newCompilerDescriptor); }
MapDifferenceImpl( Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, ValueDifference<V>> differences) { this.onlyOnLeft = unmodifiableMap(onlyOnLeft); this.onlyOnRight = unmodifiableMap(onlyOnRight); this.onBoth = unmodifiableMap(onBoth); this.differences = unmodifiableMap(differences); }
@Override public boolean equals(@Nullable Object object) { if (object instanceof MapDifference.ValueDifference) { MapDifference.ValueDifference<?> that = (MapDifference.ValueDifference<?>) object; return Objects.equal(this.left, that.leftValue()) && Objects.equal(this.right, that.rightValue()); } return false; }
SortedMapDifferenceImpl( SortedMap<K, V> onlyOnLeft, SortedMap<K, V> onlyOnRight, SortedMap<K, V> onBoth, SortedMap<K, ValueDifference<V>> differences) { super(onlyOnLeft, onlyOnRight, onBoth, differences); }
private void handleTepIpsUpdateEvent(OpenvswitchOtherConfigs origLocalIps, OpenvswitchOtherConfigs updatedLocalIps, String nodeId) { Map<String, String> origLocalIpMap = Optional .ofNullable(bridgeMgr.getMultiValueMap(origLocalIps.getOtherConfigValue())) .orElse(Collections.emptyMap()); Map<String, String> updatedLocalIpMap = Optional .ofNullable(bridgeMgr.getMultiValueMap(updatedLocalIps.getOtherConfigValue())) .orElse(Collections.emptyMap()); MapDifference<String, String> mapDiff = Maps.difference(origLocalIpMap, updatedLocalIpMap); // Handling only underlay network updates for existing for TEP ips // Added and removed TEP ips will be handled by // TunnelStateChangeListener Map<String, ValueDifference<String>> entriesDiffering = mapDiff.entriesDiffering(); if (entriesDiffering == null || entriesDiffering.isEmpty()) { LOG.trace("No underlay network changes detected for for node {}", nodeId); return; } Optional<BigInteger> dpIdOpt = bridgeMgr.getDpIdFromManagerNodeId(nodeId); if (!dpIdOpt.isPresent()) { LOG.debug("Failed to get DPN id for node {}", nodeId); return; } BigInteger dpId = dpIdOpt.get(); for (Entry<String, ValueDifference<String>> entry : entriesDiffering.entrySet()) { String srcTepIp = entry.getKey(); ValueDifference<String> valueDiff = entry.getValue(); String origUnderlayNetwork = valueDiff.leftValue(); String updatedUnderlayNetwork = valueDiff.rightValue(); handleTepIpChangeEvent(dpId, srcTepIp, origUnderlayNetwork, updatedUnderlayNetwork); } }
public Map<String, ValueDifference<String>> getPreferenceChanges() { Map<String, String> currentSettings = Maps.newHashMapWithExpectedSize(keys.length); for (String key : keys) { currentSettings.put(key, preferenceStore.getString(key)); } MapDifference<String, String> mapDifference = Maps.difference(currentSettings, originalSettings); Map<String, ValueDifference<String>> entriesDiffering = mapDifference.entriesDiffering(); return entriesDiffering; }