001/*
002 * Copyright 2006-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.springframework.batch.core.job.flow;
017
018
019/**
020 * @author Dave Syer
021 * @since 2.0
022 */
023public class FlowExecution implements Comparable<FlowExecution> {
024
025        private final String name;
026        private final FlowExecutionStatus status;
027
028        /**
029         * @param name the flow name to be associated with the FlowExecution.
030         * @param status the {@link FlowExecutionStatus} to be associated with the FlowExecution.
031         */
032        public FlowExecution(String name, FlowExecutionStatus status) {
033                this.name = name;
034                this.status = status;
035        }
036
037        /**
038         * @return the name of the end state reached
039         */
040        public String getName() {
041                return name;
042        }
043
044        /**
045         * @return the FlowExecutionStatus
046         */
047        public FlowExecutionStatus getStatus() {
048                return status;
049        }
050
051        /**
052         * Create an ordering on {@link FlowExecution} instances by comparing their
053         * statuses.
054         *
055         * @see Comparable#compareTo(Object)
056         *
057         * @param other the {@link FlowExecution} instance to compare with this instance.
058         * @return negative, zero or positive as per the contract
059         */
060        @Override
061        public int compareTo(FlowExecution other) {
062                return this.status.compareTo(other.getStatus());
063        }
064
065        @Override
066        public String toString() {
067                return String.format("FlowExecution: name=%s, status=%s", name, status);
068        }
069
070}