本文整理汇总了Java中com.google.common.collect.MapDifference类的典型用法代码示例。如果您正苦于以下问题:Java MapDifference类的具体用法?Java MapDifference怎么用?Java MapDifference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MapDifference类属于com.google.common.collect包,在下文中一共展示了MapDifference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findDifference
import com.google.common.collect.MapDifference; //导入依赖的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: doEquivalent
import com.google.common.collect.MapDifference; //导入依赖的package包/类
@Override
protected boolean doEquivalent(SolrInputField o1, SolrInputField o2) {
if (o1.getValue() instanceof SolrInputDocument) {
if (!(o2.getValue() instanceof SolrInputDocument)) {
return false;
}
final MapDifference<String, SolrInputField> difference = Maps.difference(
(SolrInputDocument) o1.getValue(),
(SolrInputDocument) o2.getValue(),
this
);
if (!difference.areEqual()) {
return false;
}
} else {
if (o1.getValue() != o2.getValue()) {
return false;
}
}
return true;
}
示例3: TestDiff
import com.google.common.collect.MapDifference; //导入依赖的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());
}
示例4: findMatchedRows
import com.google.common.collect.MapDifference; //导入依赖的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;
}
示例5: computeUnscoped
import com.google.common.collect.MapDifference; //导入依赖的package包/类
private static JobDiff computeUnscoped(
Map<Integer, ITaskConfig> currentState,
IJobKey job,
Map<Integer, ITaskConfig> proposedState) {
requireNonNull(job);
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()));
}
示例6: get
import com.google.common.collect.MapDifference; //导入依赖的package包/类
@Override
public String get() {
StringBuilder builder = new StringBuilder();
if (!difference.entriesDiffering().isEmpty()) {
builder.append("Differing:\n");
for (Map.Entry<String, MapDifference.ValueDifference<SolrInputField>> diff : difference.entriesDiffering().entrySet()) {
builder.append(" ");
builder.append(diff.getKey());
builder.append('\n');
builder.append(" left : ");
builder.append(diff.getValue().leftValue());
builder.append('\n');
builder.append(" right : ");
builder.append(diff.getValue().rightValue());
builder.append('\n');
}
}
return builder.toString();
}
示例7: calculateChanges
import com.google.common.collect.MapDifference; //导入依赖的package包/类
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(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;
}
示例8: describeMismatchSafely
import com.google.common.collect.MapDifference; //导入依赖的package包/类
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());
}
}
}
示例9: getDiff
import com.google.common.collect.MapDifference; //导入依赖的package包/类
private boolean getDiff(String captureInstanceName, Map<String, Integer> sourceTableColumnInfo, Map<String, Integer> cdcTableColumnInfo) {
MapDifference<String, Integer> diff = Maps.difference(sourceTableColumnInfo, cdcTableColumnInfo);
if (!diff.areEqual()) {
if (LOG.isTraceEnabled()) {
LOG.trace(
"Detected drift for table {} - new columns: {}, drop columns: {}",
captureInstanceName,
StringUtils.join(diff.entriesOnlyOnLeft().keySet(), ","),
StringUtils.join(diff.entriesOnlyOnRight().keySet(), ",")
);
}
return true;
}
return false;
}
示例10: compare
import com.google.common.collect.MapDifference; //导入依赖的package包/类
public boolean compare(JSONObject expected, JSONObject actual) {
MapDifference mapDifferences = Maps.difference(expected, actual);
if (mapDifferences.entriesOnlyOnLeft().size() > 0) Assert.fail("Expected JSON has extra parameters: " + mapDifferences.entriesOnlyOnLeft());
if (mapDifferences.entriesOnlyOnRight().size() > 0) Assert.fail("Actual JSON has extra parameters: " + mapDifferences.entriesOnlyOnRight());
Map actualDifferences = new HashMap();
if (mapDifferences.entriesDiffering().size() > 0) {
Map differences = Collections.unmodifiableMap(mapDifferences.entriesDiffering());
for (Object key : differences.keySet()) {
Object expectedValueObject = expected.get(key);
Object actualValueObject = actual.get(key);
if (expectedValueObject instanceof Long || expectedValueObject instanceof Integer) {
Long expectedValue = Long.parseLong(expectedValueObject.toString());
Long actualValue = Long.parseLong(actualValueObject.toString());
if (!expectedValue.equals(actualValue)) {
actualDifferences.put(key, differences.get(key));
}
} else {
actualDifferences.put(key, differences.get(key));
}
}
}
if (actualDifferences.size() > 0) Assert.fail("Expected and Actual JSON values don't match: " + actualDifferences);
return true;
}
示例11: processChanges
import com.google.common.collect.MapDifference; //导入依赖的package包/类
private void processChanges(DefaultComparison comparison, DefaultComparison.DefaultSection section,
Map<String, MapDifference.ValueDifference<Vector<Import>>> changes) {
if (changes.size() > 0) {
section.addSectionSummary(Comparison.SectionType.CONTENT_CHANGE, ComparatorConstants.CHANGED_IMPORTS);
DefaultComparison.DefaultSection.DefaultTextChangeContent content = section.newTextChangeContent();
DefaultComparison.DefaultSection.DefaultTextChange change = section.newTextChange();
Vector<Import> left = new Vector<>();
Vector<Import> right = new Vector<>();
for (MapDifference.ValueDifference<Vector<Import>> diff : changes.values()) {
left.add(diff.leftValue().firstElement());
right.add(diff.rightValue().firstElement());
}
change.setOriginal(getImportsOnly(left));
change.setChanged(getImportsOnly(right));
content.setContent(change);
section.addContent(Comparison.SectionType.CONTENT_CHANGE, content);
}
}
示例12: isDifferent
import com.google.common.collect.MapDifference; //导入依赖的package包/类
private boolean isDifferent(Map<String, Fault> left, Map<String, Fault> right) {
if (left != null && right != null && left.size() != right.size()) {
return true;
} else {
MapDifference<String, Fault> mapDiff = Maps.difference(left, right);
if (!mapDiff.areEqual()) {
return true;
} else {
for (String name : mapDiff.entriesInCommon().keySet()) {
if (isDifferent(left.get(name), right.get(name))) {
return true;
}
}
}
}
return false;
}
示例13: execute
import com.google.common.collect.MapDifference; //导入依赖的package包/类
@Override
public void execute(INetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName)
{
byte[] allData = Bytes.concat(partials);
GameData.initializeServerGate(1);
try
{
NBTTagCompound serverList = CompressedStreamTools.func_74792_a(allData);
NBTTagList list = serverList.func_74761_m("List");
Set<ItemData> itemData = GameData.buildWorldItemData(list);
GameData.validateWorldSave(itemData);
MapDifference<Integer, ItemData> serverDifference = GameData.gateWorldLoadingForValidation();
if (serverDifference!=null)
{
FMLCommonHandler.instance().disconnectIDMismatch(serverDifference, netHandler, network);
}
}
catch (IOException e)
{
}
}
示例14: gateWorldLoadingForValidation
import com.google.common.collect.MapDifference; //导入依赖的package包/类
public static MapDifference<Integer, ItemData> gateWorldLoadingForValidation()
{
try
{
serverValidationLatch.await();
if (!isSaveValid)
{
return difference;
}
}
catch (InterruptedException e)
{
}
difference = null;
return null;
}
示例15: execute
import com.google.common.collect.MapDifference; //导入依赖的package包/类
@Override
public void execute(INetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName)
{
byte[] allData = Bytes.concat(partials);
GameData.initializeServerGate(1);
try
{
NBTTagCompound serverList = CompressedStreamTools.decompress(allData);
NBTTagList list = serverList.getTagList("List");
Set<ItemData> itemData = GameData.buildWorldItemData(list);
GameData.validateWorldSave(itemData);
MapDifference<Integer, ItemData> serverDifference = GameData.gateWorldLoadingForValidation();
if (serverDifference!=null)
{
FMLCommonHandler.instance().disconnectIDMismatch(serverDifference, netHandler, network);
}
}
catch (IOException e)
{
}
}