1 package org.unicode.cldr.unittest; 2 3 import com.ibm.icu.text.MessageFormat; 4 import java.util.concurrent.Callable; 5 6 /** 7 * Class for holding error reports 8 * 9 * @author ribnitz 10 */ 11 public class CheckResult { 12 /** 13 * The status of a CheckResult 14 * 15 * @author ribnitz 16 */ 17 public enum ResultStatus { 18 error, 19 warning; 20 } 21 22 CheckResult.ResultStatus status; 23 String message; 24 String locale; 25 String path; 26 getLocale()27 public String getLocale() { 28 return locale; 29 } 30 getPath()31 public String getPath() { 32 return path; 33 } 34 setPath(String path)35 public CheckResult setPath(String path) { 36 this.path = path; 37 return this; 38 } 39 setLocale(String locale)40 public CheckResult setLocale(String locale) { 41 this.locale = locale; 42 return this; 43 } 44 CheckResult()45 public CheckResult() {} 46 setMessage(String msg, Object[] args)47 public CheckResult setMessage(String msg, Object[] args) { 48 message = MessageFormat.format(msg, args); 49 return this; 50 } 51 getStatus()52 public CheckResult.ResultStatus getStatus() { 53 return status; 54 } 55 setStatus(CheckResult.ResultStatus status)56 public CheckResult setStatus(CheckResult.ResultStatus status) { 57 this.status = status; 58 return this; 59 } 60 getMessage()61 public String getMessage() { 62 return message; 63 } 64 65 /** 66 * Factory method, initialize with (status,locale,path); depending on the result of pred, use 67 * ether (msgSuccess,objSuccess) or (msgFail,objFail) to construct the message. 68 * 69 * @param status 70 * @param locale 71 * @param path 72 * @param pred 73 * @param msgSuccess 74 * @param msgFail 75 * @param objSuccess 76 * @param objFail 77 * @return newly constructed CheckResult or null, in the case of an error occurring on Callable 78 * invocation 79 */ create( CheckResult.ResultStatus status, String locale, String path, Callable<Boolean> pred, String msgSuccess, String msgFail, Object[] objSuccess, Object[] objFail)80 public static CheckResult create( 81 CheckResult.ResultStatus status, 82 String locale, 83 String path, 84 Callable<Boolean> pred, 85 String msgSuccess, 86 String msgFail, 87 Object[] objSuccess, 88 Object[] objFail) { 89 if (pred == null) { 90 throw new IllegalArgumentException("The callable must not be null"); 91 } 92 try { 93 CheckResult result = 94 new CheckResult().setStatus(status).setLocale(locale).setPath(path); 95 if (pred.call()) { 96 result.setMessage(msgSuccess, objSuccess); 97 } else { 98 result.setMessage(msgFail, objFail); 99 } 100 return result; 101 } catch (Exception e) { 102 // TODO Auto-generated catch block 103 e.printStackTrace(); 104 } 105 return null; 106 } 107 } 108