1 4 package com.tc.util.diff; 5 6 import org.apache.commons.lang.builder.EqualsBuilder; 7 8 import com.tc.util.Assert; 9 10 14 public class BasicObjectDifference extends Difference { 15 16 private final Object a; 17 private final Object b; 18 19 public BasicObjectDifference(DifferenceContext where, Object a, Object b) { 20 super(where); 21 22 Assert 23 .eval((a != null && b != null && ((a instanceof Differenceable) && (b instanceof Differenceable) && (!a 24 .getClass().equals(b)))) 25 || (a == null) || (b == null) || ((!(a instanceof Differenceable)) || (!(b instanceof Differenceable)))); 26 27 Assert.eval(!(a == null && b == null)); 28 Assert.eval((a == null) || (b == null) || (! a.getClass().equals(b.getClass())) || (!(a.equals(b)))); 29 30 this.a = a; 31 this.b = b; 32 } 33 34 public Object a() { 35 return this.a; 36 } 37 38 public Object b() { 39 return this.b; 40 } 41 42 public String toString() { 43 return where() + ": object fields differ: " + describe(a) + " vs. " + describe(b); 44 } 45 46 private String describe(Object o) { 47 return where().describe(o); 48 } 49 50 public boolean equals(Object that) { 51 if (!(that instanceof BasicObjectDifference)) return false; 52 53 BasicObjectDifference basicThat = (BasicObjectDifference) that; 54 55 return new EqualsBuilder().appendSuper(super.equals(that)).append(this.a, basicThat.a).append(this.b, basicThat.b) 56 .isEquals(); 57 } 58 59 } | Popular Tags |