本文整理汇总了Java中com.google.common.collect.Maps.difference方法的典型用法代码示例。如果您正苦于以下问题:Java Maps.difference方法的具体用法?Java Maps.difference怎么用?Java Maps.difference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Maps
的用法示例。
在下文中一共展示了Maps.difference方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findDifference
import com.google.common.collect.Maps; //导入方法依赖的package包/类
public AreasMapComparationResult findDifference(Map<Area, ColorModel> previous, Map<Area, ColorModel> current) {
MapDifference<Area, ColorModel> differences = Maps.difference(previous, current);
checkDifferencesCount(differences);
if (isAdded(differences)) {
return getAdded(differences);
}
if (isRemoved(differences)) {
return getRemoved(differences);
}
if (isChanged(differences)) {
return getChanged(differences);
}
return AreasMapComparationResult.ofSame();
}
示例2: TestDiff
import com.google.common.collect.Maps; //导入方法依赖的package包/类
@Test
public void TestDiff() {
HashMap<String, Object> map1 = new HashMap<>();
HashMap<String, Object> map2 = new HashMap<>();
map1.put("bbbb", "cccc");
map1.put("xxx", "aaa");
map2.put("xxx", "aa");
map2.put("cccc", "bbbb");
map1.put("dict", ImmutableMap.builder().put("a", 1).put("b", 2)
.put("em", ImmutableMap.builder().put("c", 3).build()).build());
map2.put("dict", ImmutableMap.builder().put("a", 1).put("b", 3)
.put("em", ImmutableMap.builder().put("c", 4).put("d", 5).build()).build());
MapDifference diff = Maps.difference(map1, map2);
Map diffMap = new HashMap();
JsonCompareUtil.getDetailsDiff(map1, map2, diffMap, "");
Assert.assertTrue(diffMap.containsKey("bbbb"));
Assert.assertTrue(diffMap.containsKey("xxx"));
Assert.assertTrue(diffMap.containsKey("cccc"));
Assert.assertTrue(diffMap.containsKey("dict.b"));
Assert.assertTrue(diffMap.containsKey("dict.em.c"));
Assert.assertTrue(diffMap.containsKey("dict.em.d"));
Assert.assertEquals(6, diffMap.size());
}
示例3: findMatchedRows
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private List<WebElement> findMatchedRows(List<RowWebElement> matchedRows,
Map<String, String> rowToFind) {
List<WebElement> resultedRows = new ArrayList<WebElement>();
for (RowWebElement rowCandidate : matchedRows) {
Map<String, String> cellsCandidates = cellsFromRow(rowCandidate);
MapDifference<String, String> diff = Maps.difference
(cellsCandidates, rowToFind);
if (diff.areEqual()) {
resultedRows.add(rowCandidate.getRow());
} else if (diff.entriesOnlyOnRight().isEmpty() && diff
.entriesDiffering().isEmpty()) {
resultedRows.add(rowCandidate.getRow());
} else if (rowCandidate.hasSubRows()) {
for (String commonKey : diff.entriesInCommon().keySet()) {
rowToFind.remove(commonKey);
}
return findMatchedRows(getSubRowsFor(rowCandidate), diff
.entriesOnlyOnRight().isEmpty() ? rowToFind : diff
.entriesOnlyOnRight());
}
}
return resultedRows;
}
示例4: roughlyEqual
import com.google.common.collect.Maps; //导入方法依赖的package包/类
private static boolean roughlyEqual(String expectedRaw, String requestedPathRaw) {
logger.debug("Comparing expected [{}] vs requested [{}]", expectedRaw, requestedPathRaw);
if(StringUtils.isEmpty(expectedRaw)) {
logger.debug("False: empty expected");
return false;
}
try {
UriComponents expected = UriComponentsBuilder.fromUriString(expectedRaw).build();
UriComponents requested = UriComponentsBuilder.fromUriString(requestedPathRaw).build();
if(!Objects.equals(expected.getPath(), requested.getPath())) {
logger.debug("False: expected path [{}] does not match requested path [{}]",
expected.getPath(), requested.getPath());
return false;
}
MapDifference<String, List<String>> difference = Maps.difference(expected.getQueryParams(),
requested.getQueryParams());
if(difference.entriesDiffering().size() != 0 ||
difference.entriesOnlyOnLeft().size() != 0 ||
difference.entriesOnlyOnRight().size() != 1 ||
difference.entriesOnlyOnRight().get(JWTSecurityService.JWT_PARAM_NAME) == null) {
logger.debug("False: expected query params [{}] do not match requested query params [{}]", expected.getQueryParams(), requested.getQueryParams());
return false;
}
} catch(Exception e) {
logger.warn("Exception encountered while comparing paths", e);
return false;
}
return true;
}
示例5: isModified
import com.google.common.collect.Maps; //导入方法依赖的package包/类
boolean isModified(Namespace namespace) {
Release release = releaseService.findLatestActiveRelease(namespace);
List<Item> items = itemService.findItemsWithoutOrdered(namespace.getId());
if (release == null) {
return hasNormalItems(items);
}
Map<String, String> releasedConfiguration = gson.fromJson(release.getConfigurations(), GsonType.CONFIG);
Map<String, String> configurationFromItems = generateConfigurationFromItems(namespace, items);
MapDifference<String, String> difference = Maps.difference(releasedConfiguration, configurationFromItems);
return !difference.areEqual();
}
示例6: getPreferenceChanges
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* @param originalSettings
* the settings before applying the values of the form page
* @param currentSettings
* the settings after collecting the values of the form page
* @return a map keyed by the preference store key (e.g. outlet.es5.autobuilding for compiler (resp. output
* configuration) with name 'es5' and property 'autobuilding') containing old and new value. Only keys whose
* values has been changed are included.
*/
private Map<String, ValueDifference<String>> getPreferenceChanges(Map<String, String> originalSettings,
Map<String, String> currentSettings) {
MapDifference<String, String> mapDifference = Maps.difference(currentSettings, originalSettings);
Map<String, ValueDifference<String>> entriesDiffering = mapDifference.entriesDiffering();
return entriesDiffering;
}
示例7: getPreferenceChanges
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* @param originalSettings
* the settings before applying the values of the form page
* @param currentSettings
* the settings after collecting the values of the form page
* @return a map keyed by the preference store key (e.g. outlet.es5.autobuilding for compiler (resp. output
* configuration) with name 'es5' and property 'autobuilding') containing old and new value. Only keys whose
* values has been changed are included.
*/
private Map<String, ValueDifference<String>> getPreferenceChanges(Map<String, String> originalSettings,
Map<String, String> currentSettings) {
MapDifference<String, String> mapDifference = Maps.difference(currentSettings, originalSettings);
return mapDifference.entriesDiffering();
}
示例8: difference
import com.google.common.collect.Maps; //导入方法依赖的package包/类
/**
* 对两个Map进行比较,返回MapDifference,然后各种妙用.
*
* 包括key的差集,key的交集,以及key相同但value不同的元素。
*/
public static <K, V> MapDifference<K, V> difference(Map<? extends K, ? extends V> left,
Map<? extends K, ? extends V> right) {
return Maps.difference(left, right);
}