List of usage examples for com.google.common.collect Maps difference
public static <K, V> SortedMapDifference<K, V> difference(SortedMap<K, ? extends V> left, Map<? extends K, ? extends V> right)
From source file:org.wso2.carbon.governance.comparator.wsdl.WSDLBindingsComparator.java
protected void compareBindings(Definition base, Definition changed, DefaultComparison comparison) { Map<QName, Binding> baseBinding = base.getAllBindings(); Map<QName, Binding> changedBinding = changed.getAllBindings(); DefaultComparison.DefaultSection section = null; MapDifference<QName, Binding> mapDiff = Maps.difference(baseBinding, changedBinding); //If both side imports are equal, return if (mapDiff.areEqual()) { return;/*from ww w . j ava2 s.co m*/ } Map<QName, Binding> additions = mapDiff.entriesOnlyOnRight(); if (section == null && additions.size() > 0) { section = comparison.newSection(); } processAdditions(section, additions, changed); Map<QName, Binding> removals = mapDiff.entriesOnlyOnLeft(); if (section == null && removals.size() > 0) { section = comparison.newSection(); } processRemovals(section, removals, changed); Map<QName, MapDifference.ValueDifference<Binding>> changes = mapDiff.entriesDiffering(); if (section == null && changes.size() > 0) { section = comparison.newSection(); } processChanges(section, additions, changes); if (section != null) { comparison.addSection(ComparatorConstants.WSDL_IMPORTS, section); } }
From source file:org.wso2.carbon.governance.comparator.wsdl.WSDLImportsComparator.java
protected void compareImports(Map<String, Vector<Import>> base, Map<String, Vector<Import>> changed, DefaultComparison comparison) {//ww w . j av a 2s .c om DefaultComparison.DefaultSection section = null; MapDifference<String, Vector<Import>> mapDiff = Maps.difference(base, changed); //If both side imports are equal, return if (mapDiff.areEqual()) { return; } Map<String, Vector<Import>> additions = mapDiff.entriesOnlyOnRight(); if (section == null && additions.size() > 0) { section = comparison.newSection(); } processAdditions(comparison, section, additions); Map<String, Vector<Import>> removals = mapDiff.entriesOnlyOnLeft(); if (section == null && removals.size() > 0) { section = comparison.newSection(); } processRemovals(comparison, section, removals); Map<String, MapDifference.ValueDifference<Vector<Import>>> changes = mapDiff.entriesDiffering(); if (section == null && changes.size() > 0) { section = comparison.newSection(); } processChanges(comparison, section, changes); if (section != null) { comparison.addSection(ComparatorConstants.WSDL_IMPORTS, section); } }
From source file:org.wso2.carbon.governance.comparator.wsdl.WSDLServicesComparator.java
protected void compareServices(Definition base, Definition changed, DefaultComparison comparison) { DefaultComparison.DefaultSection section = null; Map<QName, Service> baseService = base.getAllServices(); Map<QName, Service> changedService = changed.getAllServices(); MapDifference<QName, Service> mapDiff = Maps.difference(baseService, changedService); //If both side services are equal, return if (mapDiff.areEqual()) { return;/*from w ww .j av a 2 s .com*/ } Map<QName, Service> additions = mapDiff.entriesOnlyOnRight(); if (section == null && additions.size() > 0) { section = comparison.newSection(); } processAdditions(section, additions, changed); Map<QName, Service> removals = mapDiff.entriesOnlyOnLeft(); if (section == null && removals.size() > 0) { section = comparison.newSection(); } processRemovals(section, removals, base); Map<QName, MapDifference.ValueDifference<Service>> changes = mapDiff.entriesDiffering(); section = processChanges(section, comparison, changes, base, changed); if (section != null) { comparison.addSection(ComparatorConstants.WSDL_SERVICE, section); } }
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 ww. jav a 2 s. c om 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())); } } }
From source file:com.ning.metrics.collector.processing.db.model.FeedEvent.java
@JsonIgnore public static Predicate<FeedEvent> isAnyKeyValuMatching(final Map<String, Object> filterMap) { Predicate<FeedEvent> feedEventPredicate = new Predicate<FeedEvent>() { @Override/*from w ww . j a v a2 s .com*/ public boolean apply(FeedEvent input) { if (filterMap == null || filterMap.isEmpty()) { return true; } return !Maps.difference(filterMap, input.getEvent().getData()).entriesInCommon().isEmpty(); } }; return feedEventPredicate; }
From source file:io.druid.query.select.EventHolder.java
@Override public boolean equals(Object o) { if (this == o) { return true; }/*from w w w.ja v a 2 s .co m*/ if (o == null || getClass() != o.getClass()) { return false; } EventHolder that = (EventHolder) o; if (offset != that.offset) { return false; } if (!Maps.difference(event, ((EventHolder) o).event).areEqual()) { return false; } if (segmentId != null ? !segmentId.equals(that.segmentId) : that.segmentId != null) { return false; } return true; }
From source file:org.ow2.sirocco.cloudmanager.api.openstack.server.utils.MapHelper.java
/** * Replace the values of the orignal map entries with the replace ones, add missing ones and remove the ones which are not defined in the replace map. * * @param original/*from www. j a va2s. c o m*/ * @param replace * @return */ public static Map<String, String> replaceMap(final Map<String, String> original, final Map<String, String> replace) { if (replace == null || replace.size() == 0) { return Maps.newHashMap(); } // first, remove entries which are not defined in the replace map Map<String, String> filter = Maps.filterEntries(original, new Predicate<Map.Entry<String, String>>() { @Override public boolean apply(java.util.Map.Entry<String, String> input) { return replace.get(input.getKey()) != null; } }); // then update the values of the filtered map Map<String, String> updated = Maps.transformEntries(filter, new Maps.EntryTransformer<String, String, String>() { @Override public String transformEntry(String key, String value) { if (replace.get(key) != null) { return replace.get(key); } else { return value; } } }); // then add the entries from the replace map which are not in the updated map Map<String, String> result = Maps.newHashMap(updated); result.putAll(Maps.difference(updated, replace).entriesOnlyOnRight()); return result; }
From source file:org.jclouds.ohai.functions.NestSlashKeys.java
@Override public Map<String, JsonBall> apply(Multimap<String, Supplier<JsonBall>> from) { Map<String, JsonBall> autoAttrs = mergeSameKeys(from); Map<String, JsonBall> modifiableFlatMap = Maps .newLinkedHashMap(Maps.filterKeys(autoAttrs, new Predicate<String>() { @Override//from ww w. j a v a2 s .co m public boolean apply(String input) { return input.indexOf('/') == -1; } })); Map<String, JsonBall> withSlashesMap = Maps.difference(autoAttrs, modifiableFlatMap).entriesOnlyOnLeft(); for (Entry<String, JsonBall> entry : withSlashesMap.entrySet()) { List<String> keyParts = Lists.newArrayList(Splitter.on('/').split(entry.getKey())); JsonBall toInsert = entry.getValue(); try { putUnderContext(keyParts, toInsert, modifiableFlatMap); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("error inserting value in entry: " + entry.getKey(), e); } } return modifiableFlatMap; }
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()); }//from ww w . jav a2s . c om 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.wso2.carbon.governance.comparator.wsdl.WSDLPortComparator.java
protected void comparePorts(Definition base, Definition changed, DefaultComparison comparison) { DefaultComparison.DefaultSection section = null; Set<QName> commonKeys = Sets.intersection(base.getAllServices().keySet(), changed.getAllServices().keySet()); if (commonKeys.size() > 0) { for (QName service : commonKeys) { Map<QName, Port> basePorts = base.getService(service).getPorts(); Map<QName, Port> changedPorts = changed.getService(service).getPorts(); MapDifference<QName, Port> mapDiff = Maps.difference(basePorts, changedPorts); if (!mapDiff.areEqual()) { Map<QName, Port> additions = mapDiff.entriesOnlyOnRight(); if (section == null && additions.size() > 0) { section = comparison.newSection(); }// w ww . j a v a 2 s .c om processAdditions(section, additions, changed); Map<QName, Port> removals = mapDiff.entriesOnlyOnLeft(); if (section == null && removals.size() > 0) { section = comparison.newSection(); } processRemovals(section, removals, base); Map<QName, MapDifference.ValueDifference<Port>> changes = mapDiff.entriesDiffering(); section = processChanges(section, comparison, changes, base, changed); } } } if (section != null) { comparison.addSection(ComparatorConstants.WSDL_PORTS, section); } }