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.support.state;
17
18 import java.util.Collection;
19 import java.util.Collections;
20
21 import org.springframework.batch.core.job.flow.FlowExecution;
22 import org.springframework.batch.core.job.flow.FlowExecutionStatus;
23
24 /**
25 * Implementation of the {@link FlowExecutionAggregator} interface that aggregates
26 * {@link FlowExecutionStatus}', using the status with the high precedence as the
27 * aggregate status. See {@link FlowExecutionStatus} for details on status
28 * precedence.
29 *
30 * @author Dave Syer
31 * @since 2.0
32 */
33 public class MaxValueFlowExecutionAggregator implements FlowExecutionAggregator {
34
35 /**
36 * Aggregate all of the {@link FlowExecutionStatus}es of the
37 * {@link FlowExecution}s into one status. The aggregate status will be the
38 * status with the highest precedence.
39 *
40 * @see FlowExecutionAggregator#aggregate(Collection)
41 */
42 @Override
43 public FlowExecutionStatus aggregate(Collection<FlowExecution> executions) {
44 if (executions == null || executions.size() == 0) {
45 return FlowExecutionStatus.UNKNOWN;
46 }
47 return Collections.max(executions).getStatus();
48 }
49
50 }