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

COVERAGE SUMMARY FOR SOURCE FILE [StepExecutionAggregator.java]

nameclass, %method, %block, %line, %
StepExecutionAggregator.java100% (1/1)100% (2/2)100% (92/92)100% (15/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StepExecutionAggregator100% (1/1)100% (2/2)100% (92/92)100% (15/15)
StepExecutionAggregator (): void 100% (1/1)100% (3/3)100% (1/1)
aggregate (StepExecution, Collection): void 100% (1/1)100% (89/89)100% (14/14)

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.partition.support;
18 
19import java.util.Collection;
20 
21import org.springframework.batch.core.BatchStatus;
22import org.springframework.batch.core.ExitStatus;
23import org.springframework.batch.core.StepExecution;
24import org.springframework.util.Assert;
25 
26/**
27 * Convenience class for aggregating a set of {@link StepExecution} instances
28 * into a single result.
29 * 
30 * @author Dave Syer
31 * @since 2.0
32 */
33public class StepExecutionAggregator {
34 
35        /**
36         * Take the inputs and aggregate certain fields, putting the aggregates into
37         * the result.  The aggregated fields are
38         * <ul>
39         * <li>status - choosing the highest value using {@link BatchStatus#max(BatchStatus, BatchStatus)}</li>
40         * <li>exitStatus - using {@link ExitStatus#and(ExitStatus)}</li>
41         * <li>commitCount, rollbackCount, etc. - by arithmetic sum</li>
42         * </ul>
43         * 
44         * @param result the result to overwrite
45         * @param executions the inputs
46         */
47        public void aggregate(StepExecution result, Collection<StepExecution> executions) {
48                Assert.notNull(result, "To aggregate into a result it must be non-null.");
49                if (executions == null || executions.isEmpty()) {
50                        throw new IllegalArgumentException("Cannot aggregate empty or null executions: " + executions);
51                }
52                for (StepExecution stepExecution : executions) {
53                        BatchStatus status = stepExecution.getStatus();
54                        result.setStatus(BatchStatus.max(result.getStatus(), status));
55                        result.setExitStatus(result.getExitStatus().and(stepExecution.getExitStatus()));
56                        result.setCommitCount(result.getCommitCount() + stepExecution.getCommitCount());
57                        result.setRollbackCount(result.getRollbackCount() + stepExecution.getRollbackCount());
58                        result.setReadCount(result.getReadCount() + stepExecution.getReadCount());
59                        result.setReadSkipCount(result.getReadSkipCount() + stepExecution.getReadSkipCount());
60                        result.setWriteCount(result.getWriteCount() + stepExecution.getWriteCount());
61                        result.setWriteSkipCount(result.getWriteSkipCount() + stepExecution.getWriteSkipCount());
62                }
63        }
64 
65}

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