1 4 package com.tc.util.diff; 5 6 import org.apache.commons.lang.ClassUtils; 7 import org.apache.commons.lang.builder.EqualsBuilder; 8 9 import com.tc.util.Assert; 10 11 14 public class PrimitiveDifference extends Difference { 15 16 private final Object a; 17 private final Object b; 18 19 public PrimitiveDifference(DifferenceContext where, boolean a, boolean b) { 20 super(where); 21 Assert.eval(a != b); 22 23 this.a = a ? Boolean.TRUE : Boolean.FALSE; 24 this.b = b ? Boolean.TRUE : Boolean.FALSE; 25 } 26 27 public PrimitiveDifference(DifferenceContext where, byte a, byte b) { 28 super(where); 29 Assert.eval(a != b); 30 31 this.a = new Byte (a); 32 this.b = new Byte (b); 33 } 34 35 public PrimitiveDifference(DifferenceContext where, char a, char b) { 36 super(where); 37 Assert.eval(a != b); 38 39 this.a = new Character (a); 40 this.b = new Character (b); 41 } 42 43 public PrimitiveDifference(DifferenceContext where, short a, short b) { 44 super(where); 45 Assert.eval(a != b); 46 47 this.a = new Short (a); 48 this.b = new Short (b); 49 } 50 51 public PrimitiveDifference(DifferenceContext where, int a, int b) { 52 super(where); 53 Assert.eval(a != b); 54 55 this.a = new Integer (a); 56 this.b = new Integer (b); 57 } 58 59 public PrimitiveDifference(DifferenceContext where, long a, long b) { 60 super(where); 61 Assert.eval(a != b); 62 63 this.a = new Long (a); 64 this.b = new Long (b); 65 } 66 67 public PrimitiveDifference(DifferenceContext where, float a, float b) { 68 super(where); 69 Assert.eval(a != b); 70 71 this.a = new Float (a); 72 this.b = new Float (b); 73 } 74 75 public PrimitiveDifference(DifferenceContext where, double a, double b) { 76 super(where); 77 Assert.eval(a != b); 78 79 this.a = new Double (a); 80 this.b = new Double (b); 81 } 82 83 public Object a() { 84 return this.a; 85 } 86 87 public Object b() { 88 return this.b; 89 } 90 91 public String toString() { 92 return where() + ": primitive fields of type " + ClassUtils.getShortClassName(this.a.getClass()) + " differ: " 93 + this.a + " vs. " + this.b; 94 } 95 96 public boolean equals(Object that) { 97 if (!(that instanceof PrimitiveDifference)) return false; 98 99 PrimitiveDifference primThat = (PrimitiveDifference) that; 100 101 return new EqualsBuilder().appendSuper(super.equals(that)).append(this.a, primThat.a).append(this.b, primThat.b) 102 .isEquals(); 103 } 104 105 } | Popular Tags |