1 package br.com.ibnetwork.guara.rundata;
2
3 import br.com.ibnetwork.guara.modules.Module;
4
5 public class Outcome
6 {
7 public static final String ERROR_CODE = "ERROR";
8
9 public static final String UNKNOWN_CODE = "UNKNOWN";
10
11 public static final String SUCCESS_CODE = "SUCCESS";
12
13 public static Outcome UNKNOWN = new Outcome(UNKNOWN_CODE,null,null);
14
15 private String code;
16
17 private Module source;
18
19 private String method;
20
21 private Outcome(String code, Module source, String method)
22 {
23 this.code = code;
24 this.source = source;
25 this.method = method;
26 }
27
28 public String getCode()
29 {
30 return code;
31 }
32
33 public Module getSource()
34 {
35 return source;
36 }
37
38 public String getMethod()
39 {
40 return method;
41 }
42
43 public static Outcome unknown(String code, Module source) {
44 return new Outcome(code,source,null);
45 }
46
47 public static Outcome unknown(String code, Module source, String method) {
48 return new Outcome(code,source,method);
49 }
50
51 public static Outcome error(Module source) {
52 return new Outcome(ERROR_CODE,source,null);
53 }
54
55 public static Outcome error(Module source, String method) {
56 return new Outcome(ERROR_CODE,source,method);
57 }
58
59 public static Outcome success(Module source) {
60 return new Outcome(SUCCESS_CODE,source,null);
61 }
62
63 public static Outcome success(Module source, String method) {
64 return new Outcome(SUCCESS_CODE,source,method);
65 }
66
67 public boolean equals(Object other)
68 {
69 if(other == null) return false;
70 if(this == other) return true;
71 if(!(other instanceof Outcome)) return false;
72 Outcome obj = (Outcome) other;
73 return obj.getSource() == source
74 && (code == null ? obj.getCode() == null : code.equals(obj.getCode()))
75 && (method == null ? obj.getMethod() == null : method.equals(obj.getMethod()));
76 }
77
78 public String toString()
79 {
80 return "Outcome: code("+code+") source("+source+") method("+method+")";
81 }
82 }