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 ; 7 8 13 public final class Result implements Serializable { 14 17 public static final Result SUCCESS = new Result("SUCCESS",0); 18 21 public static final Result UNSTABLE = new Result("UNSTABLE",1); 22 25 public static final Result FAILURE = new Result("FAILURE",2); 26 29 public static final Result ABORTED = new Result("ABORTED",3); 30 31 private final String name; 32 33 36 private final int ordinal; 37 38 private Result(String name, int ordinal) { 39 this.name = name; 40 this.ordinal = ordinal; 41 } 42 43 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 toString() { 58 return name; 59 } 60 61 private Object 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 clazz) { 74 return clazz==Result.class; 75 } 76 77 protected Object fromString(String s) { 78 for (Result r : all) 79 if (s.equals(r.name)) 80 return r; 81 return FAILURE; 82 } 83 }; 84 } 85 | Popular Tags |