0

我遇到了这个奇怪的问题。我正在处理属于不同类的不同对象。我想要做的是使用递归算法查看一个对象是否与另一个可能在另一个对象内部的对象相等:

private static void foundObject(EObject obj, EObject set) {

        if(EcoreUtil.equals(obj, set)){
                System.out.println("The objects are the same: \n\t"+obj+"\n\t"+set);
                return;
        } else {
                System.out.println("The objects are not the same: \n\t"+obj+"\n\t"+set+" "+set.eContents());        
                if(set.eContents().size()>0){
                    for(EObject child: set.eContents()){
                        foundObject(obj, child);
                     }
                 }
        }           
}

我想看看分配类的对象是否在组内:

  • 任务
  • [分配,关键字]

如您所见,在 Group 对象内有一个包含我要查找的对象的列表。在这种情况下,我有下一个输出:

> The objects are not the same: 
    Assignment
    Group [Assignment, Keyword]
The objects are the same: 
    Assignment
    Assignment
The objects are not the same: 
    Assignment
    Keyword

哪个是对的。问题是,当初始组获得另一个分配元素时

组 [作业, 关键字 ,作业]

该算法看不到相应的匹配,并提供如下输出:

The objects are not the same: 
    Assignment
    Group [Assignment, Keyword, Assignment]
The objects are not the same: 
    Assignment
    Assignment
The objects are not the same: 
    Assignment
    RuleCall
The objects are not the same: 
    Assignment
    Keyword
The objects are not the same: 
    Assignment
    Assignment
The objects are not the same: 
    Assignment
    RuleCall

但在我的情况下,第二对元素是相同的(这就是我使用 ECoreUtil.equals 的原因)。关于为什么会发生这种情况的任何想法?

4

0 回答 0