KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > model > Result


1 package hudson.model;
2
3 import com.thoughtworks.xstream.converters.Converter;
4 import com.thoughtworks.xstream.converters.basic.AbstractBasicConverter;
5
6 import java.io.Serializable JavaDoc;
7
8 /**
9  * The build outcome.
10  *
11  * @author Kohsuke Kawaguchi
12  */

13 public final class Result implements Serializable JavaDoc {
14     /**
15      * The build didn't have any fatal errors not errors.
16      */

17     public static final Result SUCCESS = new Result("SUCCESS",0);
18     /**
19      * The build didn't have any fatal errors but some errors.
20      */

21     public static final Result UNSTABLE = new Result("UNSTABLE",1);
22     /**
23      * The build had a fatal error.
24      */

25     public static final Result FAILURE = new Result("FAILURE",2);
26     /**
27      * The build was manually aborted.
28      */

29     public static final Result ABORTED = new Result("ABORTED",3);
30
31     private final String JavaDoc name;
32
33     /**
34      * Bigger numbers are worse.
35      */

36     private final int ordinal;
37
38     private Result(String JavaDoc name, int ordinal) {
39         this.name = name;
40         this.ordinal = ordinal;
41     }
42
43     /**
44      * Combines two {@link Result}s and returns the worse one.
45      */

46     public Result combine(Result that) {
47         if(this.ordinal < that.ordinal)
48             return that;
49         else
50             return this;
51     }
52
53     public boolean isWorseThan(Result that) {
54         return this.ordinal > that.ordinal;
55     }
56
57     public String JavaDoc toString() {
58         return name;
59     }
60     
61     private Object JavaDoc readResolve() {
62         for (Result r : all)
63             if (ordinal==r.ordinal)
64                 return r;
65         return FAILURE;
66     }
67
68     private static final long serialVersionUID = 1L;
69
70     private static final Result[] all = new Result[] {SUCCESS,UNSTABLE,FAILURE,ABORTED};
71
72     public static final Converter conv = new AbstractBasicConverter () {
73         public boolean canConvert(Class JavaDoc clazz) {
74             return clazz==Result.class;
75         }
76
77         protected Object JavaDoc fromString(String JavaDoc s) {
78             for (Result r : all)
79                 if (s.equals(r.name))
80                     return r;
81             return FAILURE;
82         }
83     };
84 }
85
Popular Tags