| 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 | */ |
| 16 | package org.springframework.batch.core.job.flow; |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * @author Dave Syer |
| 21 | * @since 2.0 |
| 22 | */ |
| 23 | public class FlowExecution implements Comparable<FlowExecution> { |
| 24 | |
| 25 | private final String name; |
| 26 | private final FlowExecutionStatus status; |
| 27 | |
| 28 | /** |
| 29 | * @param name |
| 30 | * @param status |
| 31 | */ |
| 32 | public FlowExecution(String name, FlowExecutionStatus status) { |
| 33 | this.name = name; |
| 34 | this.status = status; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @return the name of the end state reached |
| 39 | */ |
| 40 | public String getName() { |
| 41 | return name; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return the FlowExecutionStatus |
| 46 | */ |
| 47 | public FlowExecutionStatus getStatus() { |
| 48 | return status; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Create an ordering on {@link FlowExecution} instances by comparing their |
| 53 | * statuses. |
| 54 | * |
| 55 | * @see Comparable#compareTo(Object) |
| 56 | * |
| 57 | * @param other |
| 58 | * @return negative, zero or positive as per the contract |
| 59 | */ |
| 60 | @Override |
| 61 | public int compareTo(FlowExecution other) { |
| 62 | return this.status.compareTo(other.getStatus()); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public String toString() { |
| 67 | return String.format("FlowExecution: name=%s, status=%s", name, status); |
| 68 | } |
| 69 | |
| 70 | } |