1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.batch.core.job.flow;
17
18
19
20
21
22
23
24
25 public class FlowExecutionStatus implements Comparable<FlowExecutionStatus> {
26
27
28
29
30 public static final FlowExecutionStatus COMPLETED = new FlowExecutionStatus(Status.COMPLETED.toString());
31
32
33
34
35 public static final FlowExecutionStatus STOPPED = new FlowExecutionStatus(Status.STOPPED.toString());
36
37
38
39
40 public static final FlowExecutionStatus FAILED = new FlowExecutionStatus(Status.FAILED.toString());
41
42
43
44
45 public static final FlowExecutionStatus UNKNOWN = new FlowExecutionStatus(Status.UNKNOWN.toString());
46
47 private final String name;
48
49 private enum Status {
50
51 COMPLETED, STOPPED, FAILED, UNKNOWN;
52
53 static Status match(String value) {
54 for (int i = 0; i < values().length; i++) {
55 Status status = values()[i];
56 if (value.startsWith(status.toString())) {
57 return status;
58 }
59 }
60
61 return COMPLETED;
62 }
63
64 };
65
66
67
68
69 public FlowExecutionStatus(String status) {
70 this.name = status;
71 }
72
73
74
75
76 public boolean isStop() {
77 return name.startsWith(STOPPED.getName());
78 }
79
80
81
82
83 public boolean isFail() {
84 return name.startsWith(FAILED.getName());
85 }
86
87
88
89
90
91 public boolean isEnd() {
92 return isStop() || isFail() || isComplete();
93 }
94
95
96
97
98 private boolean isComplete() {
99 return name.startsWith(COMPLETED.getName());
100 }
101
102
103
104
105
106
107
108
109
110 @Override
111 public int compareTo(FlowExecutionStatus other) {
112 Status one = Status.match(this.name);
113 Status two = Status.match(other.name);
114 int comparison = one.compareTo(two);
115 if (comparison == 0) {
116 return this.name.compareTo(other.name);
117 }
118 return comparison;
119 }
120
121
122
123
124
125
126 @Override
127 public boolean equals(Object object) {
128 if (object == this) {
129 return true;
130 }
131 if (!(object instanceof FlowExecutionStatus)) {
132 return false;
133 }
134 FlowExecutionStatus other = (FlowExecutionStatus) object;
135 return name.equals(other.name);
136 }
137
138 @Override
139 public int hashCode() {
140 return name.hashCode();
141 }
142
143
144
145
146 @Override
147 public String toString() {
148 return name;
149 }
150
151
152
153
154 public String getName() {
155 return name;
156 }
157
158 }