All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sangupta.jerry.consume.GenericConsumer Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
/**
 *
 * jerry - Common Java Functionality
 * Copyright (c) 2012-2015, Sandeep Gupta
 * 
 * http://sangupta.com/projects/jerry
 * 
 * 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
 * 
 * 		http://www.apache.org/licenses/LICENSE-2.0
 * 
 * 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 com.sangupta.jerry.consume;

import java.io.IOException;

/**
 * A generic processing class that can be used to consume an entity.
 * 
 * @author sangupta
 *
 * @param 
 *            the type of instance that this consumer can consume
 */
public abstract class GenericConsumer {

	/**
	 * Called before the consumption of entity starts.
	 * 
	 * @return true if consumption should continue, or
	 *         false if processing should stop immediately.
	 * 
	 */
	public boolean before() {
		return true;
	}

	/**
	 * Called for processing of the entity.
	 * 
	 * @param data
	 *            the entity data to consume
	 * 
	 * @return true if consumption should continue, or
	 *         false if processing should stop immediately.
	 */
	public abstract boolean consume(T data);

	/**
	 * Called after completing of processing when the entity was consumed
	 * successfully, and not stopped in between either by returning a
	 * false in the {@link #consume(Object)} method, or if an
	 * exception was raised.
	 * 
	 */
	public void after() {
		// do nothing
	}

	/**
	 * Called when an exception is raised during the processing of file.
	 * 
	 * @param e
	 *            the {@link IOException} that was raised.
	 */
	public void onException(Exception e) {
		// do nothing
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy