Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2006-2007 the original author or authors.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.springframework.batch.repeat.context;
Helper class for policies that need to count the number of occurrences of some event (e.g. an exception type in the context) in the scope of a batch. The value of the counter can be stored between batches in a nested context, so that the termination decision is based on the aggregate of a number of sibling batches.

Dave Syer
 public class RepeatContextCounter {
 	final private String countKey;

Flag to indicate whether the count is stored at the level of the parent context, or just local to the current context. Default value is false.
 	final private boolean useParent;
 	final private RepeatContext context;

Increment the counter.

delta the amount by which to increment the counter.
 	final public void increment(int delta) {
 		AtomicInteger count = getCounter();

Increment by 1.
 	final public void increment() {

Convenience constructor with useParent=false.

context the current context.
countKey the key to use to store the counter in the context.
 	public RepeatContextCounter(RepeatContext contextString countKey) {

Construct a new RepeatContextCounter.

context the current context.
countKey the key to use to store the counter in the context.
useParent true if the counter is to be shared between siblings. The state will be stored in the parent of the context (if it exists) instead of the context itself.
 	public RepeatContextCounter(RepeatContext contextString countKeyboolean useParent) {
 		Assert.notNull(context"The context must be provided to initialize a counter");
 		this. = countKey;
 		this. = useParent;
 		RepeatContext parent = context.getParent();
 		if (this. && parent != null) {
 			this. = parent;
 		else {
 			this. = context;
 		if (!this..hasAttribute(countKey)) {
 			this..setAttribute(countKeynew AtomicInteger());

the current value of the counter
	public int getCount() {
		return getCounter().intValue();
New to GrepCode? Check out our FAQ X