module RGen::Ext::Comparison::DeepComparator
Public Class Methods
eql?(left,right)
click to toggle source
It checks all the containment references recursively while it compare the non-containment references using ShallowComparator
, to avoid infinite recursion
# File lib/rgen/ext/comparison.rb, line 62 def self.eql?(left,right) return false unless ShallowComparator.eql?(left,right) left.class.ecore.eAllReferences.each do |ref| left_value = left.send(ref.name) right_value = right.send(ref.name) # it should ignore relations which has as opposite a containment unless (ref.getEOpposite and ref.getEOpposite.containment) comparison_method = ref.containment ? DeepComparator : ShallowComparator if left_value==nil || right_value==nil # if one value is nil, both should be nil return false unless left_value==right_value elsif ref.many # compare each children return false unless left_value.count==right_value.count if ref.ordered for i in 0...left_value.count return false unless comparison_method.send(:eql?,left_value[i],right_value[i]) end else return false unless UnorderedComparison.eql?(left_value,right_value,DeepComparator) end else # compare the only child return false unless comparison_method.send(:eql?,left_value,right_value) end end end true end