EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core]

COVERAGE SUMMARY FOR SOURCE FILE [BatchStatus.java]

nameclass, %method, %block, %line, %
BatchStatus.java100% (1/1)83%  (10/12)83%  (177/212)71%  (12.8/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BatchStatus100% (1/1)83%  (10/12)83%  (177/212)71%  (12.8/18)
isLessThanOrEqualTo (BatchStatus): boolean 0%   (0/1)0%   (0/8)0%   (0/1)
match (String): BatchStatus 0%   (0/1)0%   (0/25)0%   (0/4)
isLessThan (BatchStatus): boolean 100% (1/1)75%  (6/8)75%  (0.8/1)
<static initializer> 100% (1/1)100% (84/84)100% (2/2)
BatchStatus (String, int): void 100% (1/1)100% (5/5)100% (1/1)
isGreaterThan (BatchStatus): boolean 100% (1/1)100% (8/8)100% (1/1)
isRunning (): boolean 100% (1/1)100% (10/10)100% (1/1)
isUnsuccessful (): boolean 100% (1/1)100% (11/11)100% (1/1)
max (BatchStatus, BatchStatus): BatchStatus 100% (1/1)100% (8/8)100% (1/1)
upgradeTo (BatchStatus): BatchStatus 100% (1/1)100% (24/24)100% (5/5)
valueOf (String): BatchStatus 100% (1/1)100% (5/5)100% (1/1)
values (): BatchStatus [] 100% (1/1)100% (16/16)100% (1/1)

1/*
2 * Copyright 2006-2007 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 */
16 
17package org.springframework.batch.core;
18 
19/**
20 * Enumeration representing the status of a an Execution.
21 * 
22 * @author Lucas Ward
23 * @author Dave Syer
24 */
25public enum BatchStatus {
26 
27        /**
28         * The order of the status values is significant because it can be used to
29         * aggregate a set of status values - the result should be the maximum
30         * value. Since COMPLETED is first in the order, only if all elements of an
31         * execution are COMPLETED will the aggregate status be COMPLETED. A running
32         * execution is expected to move from STARTING to STARTED to COMPLETED
33         * (through the order defined by {@link #upgradeTo(BatchStatus)}). Higher
34         * values than STARTED signify more serious failure. INCOMPLETE is used for
35         * steps that have finished processing, but were not successful, and where
36         * they should be skipped on a restart (so FAILED is the wrong status).
37         */
38        COMPLETED, STARTING, STARTED, STOPPING, STOPPED, FAILED, ABANDONED, UNKNOWN;
39 
40        public static BatchStatus max(BatchStatus status1, BatchStatus status2) {
41                return status1.isGreaterThan(status2) ? status1 : status2;
42        }
43 
44        /**
45         * Convenience method to decide if a status indicates work is in progress.
46         * 
47         * @return true if the status is STARTING, STARTED
48         */
49        public boolean isRunning() {
50                return this == STARTING || this == STARTED;
51        }
52 
53        /**
54         * Convenience method to decide if a status indicates execution was
55         * unsuccessful.
56         * 
57         * @return true if the status is FAILED or greater
58         */
59        public boolean isUnsuccessful() {
60                return this == FAILED || this.isGreaterThan(FAILED);
61        }
62 
63        /**
64         * Method used to move status values through their logical progression, and
65         * override less severe failures with more severe ones. This value is
66         * compared with the parameter and the one that has higher priority is
67         * returned. If both are STARTED or less than the value returned is the
68         * largest in the sequence STARTING, STARTED, COMPLETED. Otherwise the value
69         * returned is the maximum of the two.
70         * 
71         * @param other another status to compare to
72         * @return either this or the other status depending on their priority
73         */
74        public BatchStatus upgradeTo(BatchStatus other) {
75                if (isGreaterThan(STARTED) || other.isGreaterThan(STARTED)) {
76                        return max(this, other);
77                }
78                // Both less than or equal to STARTED
79                if (this == COMPLETED || other == COMPLETED)
80                        return COMPLETED;
81                return max(this, other);
82        }
83 
84        /**
85         * @param other a status value to compare
86         * @return true if this is greater than other
87         */
88        public boolean isGreaterThan(BatchStatus other) {
89                return this.compareTo(other) > 0;
90        }
91 
92        /**
93         * @param other a status value to compare
94         * @return true if this is less than other
95         */
96        public boolean isLessThan(BatchStatus other) {
97                return this.compareTo(other) < 0;
98        }
99 
100        /**
101         * @param other a status value to compare
102         * @return true if this is less than other
103         */
104        public boolean isLessThanOrEqualTo(BatchStatus other) {
105                return this.compareTo(other) <= 0;
106        }
107 
108        /**
109         * Find a BatchStatus that matches the beginning of the given value. If no
110         * match is found, return COMPLETED as the default because has is low
111         * precedence.
112         * 
113         * @param value a string representing a status
114         * @return a BatchStatus
115         */
116        public static BatchStatus match(String value) {
117                for (BatchStatus status : values()) {
118                        if (value.startsWith(status.toString())) {
119                                return status;
120                        }
121                }
122                // Default match should be the lowest priority
123                return COMPLETED;
124        }
125}

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