1 package net.sf.clirr.core.internal.checks; 2 3 import net.sf.clirr.core.ApiDifference; 4 import net.sf.clirr.core.MessageTranslator; 5 import net.sf.clirr.core.Severity; 6 7 10 11 public final class ExpectedDiff 12 { 13 private static MessageTranslator translator = new MessageTranslator(); 14 15 private String report; 16 private Severity binaryCompatibilitySeverity; 17 private Severity sourceCompatibilitySeverity; 18 private String affectedClass; 19 private String affectedMethod; 20 private String affectedField; 21 22 33 public ExpectedDiff(String report, Severity severity, String clazz, String method, String field) 34 { 35 this(report, severity, severity, clazz, method, field); 36 } 37 38 50 public ExpectedDiff(String report, Severity binarySeverity, Severity sourceSeverity, 51 String clazz, String method, String field) 52 { 53 checkNonNull(report); 54 checkNonNull(binarySeverity); 55 checkNonNull(sourceSeverity); 56 checkNonNull(clazz); 57 58 this.report = report; 59 this.binaryCompatibilitySeverity = binarySeverity; 60 this.sourceCompatibilitySeverity = sourceSeverity; 61 this.affectedClass = clazz; 62 this.affectedField = field; 63 this.affectedMethod = method; 64 } 65 66 69 private void checkNonNull(Object o) 70 { 71 if (o == null) 72 { 73 throw new IllegalArgumentException (); 74 } 75 } 76 77 80 public String toString() 81 { 82 return report + " (" + binaryCompatibilitySeverity + ") - " 83 + affectedClass + '[' + affectedField + '/' + affectedMethod + ']'; 84 } 85 86 90 public boolean matches(ApiDifference diff) 91 { 92 if (!report.equals(diff.getReport(translator))) 93 { 94 return false; 95 } 96 97 if (!binaryCompatibilitySeverity.equals(diff.getBinaryCompatibilitySeverity())) 98 { 99 return false; 100 } 101 102 if (!sourceCompatibilitySeverity.equals(diff.getSourceCompatibilitySeverity())) 103 { 104 return false; 105 } 106 107 108 final String otherClass = diff.getAffectedClass(); 109 if (!affectedClass.equals(otherClass)) 110 { 111 return false; 112 } 113 114 final String otherMethod = diff.getAffectedMethod(); 115 if (affectedMethod != null ? !affectedMethod.equals(otherMethod) : otherMethod != null) 116 { 117 return false; 118 } 119 120 final String otherField = diff.getAffectedField(); 121 if (affectedField != null ? !affectedField.equals(otherField) : otherField != null) 122 { 123 return false; 124 } 125 126 return true; 127 } 128 } 129 | Popular Tags |