EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.core.job.flow]

COVERAGE SUMMARY FOR SOURCE FILE [FlowExecutionStatus.java]

nameclass, %method, %block, %line, %
FlowExecutionStatus.java100% (2/2)88%  (14/16)88%  (169/192)85%  (27.9/33)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FlowExecutionStatus100% (1/1)91%  (10/11)84%  (95/113)81%  (21/26)
hashCode (): int 0%   (0/1)0%   (0/4)0%   (0/1)
equals (Object): boolean 100% (1/1)26%  (5/19)33%  (2/6)
<static initializer> 100% (1/1)100% (25/25)100% (4/4)
FlowExecutionStatus (String): void 100% (1/1)100% (6/6)100% (3/3)
compareTo (FlowExecutionStatus): int 100% (1/1)100% (22/22)100% (6/6)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
isComplete (): boolean 100% (1/1)100% (6/6)100% (1/1)
isEnd (): boolean 100% (1/1)100% (13/13)100% (1/1)
isFail (): boolean 100% (1/1)100% (6/6)100% (1/1)
isStop (): boolean 100% (1/1)100% (6/6)100% (1/1)
toString (): String 100% (1/1)100% (3/3)100% (1/1)
     
class FlowExecutionStatus$Status100% (1/1)80%  (4/5)94%  (74/79)99%  (6.9/7)
valueOf (String): FlowExecutionStatus$Status 0%   (0/1)0%   (0/5)0%   (0/1)
<static initializer> 100% (1/1)100% (44/44)100% (2/2)
FlowExecutionStatus$Status (String, int): void 100% (1/1)100% (5/5)100% (1/1)
match (String): FlowExecutionStatus$Status 100% (1/1)100% (21/21)100% (5/5)
values (): FlowExecutionStatus$Status [] 100% (1/1)100% (4/4)100% (1/1)

1/*
2 * Copyright 2006-2013 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.springframework.batch.core.job.flow;
17 
18/**
19 * Represents the status of {@link FlowExecution}.
20 *
21 * @author Dan Garrette
22 * @author Dave Syer
23 * @since 2.0
24 */
25public class FlowExecutionStatus implements Comparable<FlowExecutionStatus> {
26 
27        /**
28         * Special well-known status value.
29         */
30        public static final FlowExecutionStatus COMPLETED = new FlowExecutionStatus(Status.COMPLETED.toString());
31 
32        /**
33         * Special well-known status value.
34         */
35        public static final FlowExecutionStatus STOPPED = new FlowExecutionStatus(Status.STOPPED.toString());
36 
37        /**
38         * Special well-known status value.
39         */
40        public static final FlowExecutionStatus FAILED = new FlowExecutionStatus(Status.FAILED.toString());
41 
42        /**
43         * Special well-known status value.
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                        // Default match should be the lowest priority
61                        return COMPLETED;
62                }
63 
64        };
65 
66        /**
67         * @param status
68         */
69        public FlowExecutionStatus(String status) {
70                this.name = status;
71        }
72 
73        /**
74         * @return true if the status starts with "STOPPED"
75         */
76        public boolean isStop() {
77                return name.startsWith(STOPPED.getName());
78        }
79 
80        /**
81         * @return true if the status starts with "FAILED"
82         */
83        public boolean isFail() {
84                return name.startsWith(FAILED.getName());
85        }
86 
87 
88        /**
89         * @return true if this status represents the end of a flow
90         */
91        public boolean isEnd() {
92                return isStop() || isFail() || isComplete();
93        }
94 
95        /**
96         * @return true if the status starts with "COMPLETED"
97         */
98        private boolean isComplete() {
99                return name.startsWith(COMPLETED.getName());
100        }
101        /**
102         * Create an ordering on {@link FlowExecutionStatus} instances by comparing
103         * their statuses.
104         *
105         * @see Comparable#compareTo(Object)
106         *
107         * @param other
108         * @return negative, zero or positive as per the contract
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         * Check the equality of the statuses.
123         *
124         * @see java.lang.Object#equals(java.lang.Object)
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         * @see Object#toString()
145         */
146        @Override
147        public String toString() {
148                return name;
149        }
150 
151        /**
152         * @return the name of this status
153         */
154        public String getName() {
155                return name;
156        }
157 
158}

[all classes][org.springframework.batch.core.job.flow]
EMMA 2.0.5312 (C) Vladimir Roubtsov