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