2013-04-08 57 views
0

以下是我的emf实例文档的2个版本。正如您所看到的,唯一改变的是'productCode'的值从KAF更改。但是比较是把这个当成两个变化ADD and DELETE。不知道为什么?EMF比较:DifferenceKind是ADD和DELETE而不是CHANGE。为什么?

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{[email protected] Application Processed, [email protected] Application Processed, origin=<null>, #differences=2, #submatches=2} 
State: UNRESOLVED 

d.getKind(): DELETE 
d.getMatch(): MatchSpec{[email protected] Application Processed, [email protected] Application Processed, origin=<null>, #differences=2, #submatches=2} 
State: UNRESOLVED 

回答

0

我们的wiki还远远没有完成,但description of the Diff elements应该足够完整,以描述EMF Compare的“添加”,“删除”或“更改”的含义。

除此之外,您在此处打印的内容不足以说明真正发生的情况。如果您打印“d.toString()”本身或至少d.getValue()(如果instanceof ReferenceChange或ReferenceChange),则System.out会更加有用。我希望我不会对它做出错误的假设(特别是什么是“billableProductCode”和它的“productCode”),我不会回答你的模型。

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

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

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