【问题标题】:EMF Compare: DifferenceKind is ADD and DELETE instead of CHANGE. Why?EMF 比较:DifferenceKind 是 ADD 和 DELETE 而不是 CHANGE。为什么?
【发布时间】:2013-03-30 18:15:46
【问题描述】:

以下是我的 emf 实例文档的 2 个版本。如您所见,唯一改变的是 'productCode' 值从 KAFChanged。但是比较将其视为两个更改ADDDELETE。不知道为什么?

版本 1

<billableSystemEvent eventType="1" description="Application Processed">
        <billableProductCode productCode="KAF"/>
</billableSystemEvent>

第 2 版

<billableSystemEvent eventType="1" description="Application Processed">
        <billableProductCode productCode="Changed"/>
</billableSystemEvent>

public Comparison compare()
{
    // Load the two input models
    ResourceSet resourceSet1 = new ResourceSetImpl();
    ResourceSet resourceSet2 = new ResourceSetImpl();
    String xmi1 = "src/test/java/com/equifax/ic/provisioning/service/v1.xmi";
    String xmi2 = "src/test/java/com/equifax/ic/provisioning/service/v2.xmi";
    load(xmi1, resourceSet1);
    load(xmi2, resourceSet2);

    // Configure EMF Compare
    EMFCompare comparator = EMFCompare.builder().build();

    // Compare the two models
    IComparisonScope scope = EMFCompare.createDefaultScope(resourceSet1, resourceSet2);
    return comparator.compare(scope);
}

@Test
public void testCompare()
{
    Comparison comparison = compare();
    List<Diff> differences = comparison.getDifferences();

    for(Diff d: differences)
    {
        System.err.println("d.getKind(): "+d.getKind());
        System.err.println("d.getMatch(): " + d.getMatch());
        System.err.println("State: " + d.getState());
    }

    assertSame(Integer.valueOf(12), Integer.valueOf(differences.size()));
}

输出

d.getKind(): ADD
d.getMatch(): MatchSpec{left=BillableSystemEvent@1b5340c Application Processed, right=BillableSystemEvent@16c163f Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED

d.getKind(): DELETE
d.getMatch(): MatchSpec{left=BillableSystemEvent@1b5340c Application Processed, right=BillableSystemEvent@16c163f Application Processed, origin=<null>, #differences=2, #submatches=2}
State: UNRESOLVED

【问题讨论】:

    标签: java eclipse eclipse-emf emf emf-compare


    【解决方案1】:

    我们的 wiki 远未完成,但 description of the Diff elements 应该足够完整以描述“添加”、“删除”或“更改”对 EMF 比较的含义。

    除此之外,您在此处打印的内容不足以说明实际发生的情况。如果您自己打印“d.toString()”,您的 System.out 会更有用......或者至少打印 d.getValue()(如果是 instanceof ReferenceChange 或 ReferenceChange)。

    在这里,我将在不了解您的模型的情况下回答,我希望我不会对它做出错误的假设(特别是什么是“billableProductCode”及其“productCode”)。

    我很确定 billableSystemEvent.billableProductCode 是一个多值属性。在这种情况下,彼此不“相等”的元素将被视为不匹配。 “KAF”不等于“Changed”,因此我们认为这两个值不匹配,这导致了两个不同之处:“KAF”已被删除,“Changed”已被添加。

    请注意,这是一种简化:我们在这里不使用 Object#equals(Object),而是使用IEqualityHelper#matchingValues(Object, Object)

    如果“billableProductCode”是单值属性,我们会检测到“KAF”已更改为“已更改”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      • 2012-06-27
      • 2015-08-05
      • 2010-10-28
      • 2015-01-11
      • 1970-01-01
      相关资源
      最近更新 更多