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

net.sf.jabb.dstream.StreamDataSupplierWithIdAndPositionRange Maven / Gradle / Ivy

/**
 * 
 */
package net.sf.jabb.dstream;

import java.util.function.Function;

import net.sf.jabb.dstream.ex.DataStreamInfrastructureException;

/**
 * Data structure for a StreamDataSupplier, an ID, a from position, and a to position.
 * The the from and to positions can be inclusive or exclusive, depending on the upper level application.
 * @author James Hu
 * 
 * @param  type of the message object
 *
 */
public class StreamDataSupplierWithIdAndPositionRange extends SimpleStreamDataSupplierWithId implements StreamDataSupplierWithIdAndRange{
	protected String fromPosition;
	protected String toPosition;
	
	public StreamDataSupplierWithIdAndPositionRange(){
		super();
	}
	
	public StreamDataSupplierWithIdAndPositionRange(String id, StreamDataSupplier supplier){
		super(id, supplier);
	}
	
	public StreamDataSupplierWithIdAndPositionRange(String id, StreamDataSupplier supplier, String fromPosition, String toPosition){
		super(id, supplier);
		this.fromPosition = fromPosition;
		this.toPosition = toPosition;
	}
	
	@Override
	public ReceiveStatus receiveInRange(Function receiver, String startPosition, String endPosition) throws DataStreamInfrastructureException {
		if (startPosition == null || startPosition.length() == 0 || supplier.isInRange(startPosition, fromPosition)){
			startPosition = fromPosition;
		}
		if (endPosition == null || endPosition.length() == 0 || supplier.isInRange(toPosition, endPosition)){
			endPosition = toPosition;
		}
		return supplier.receive(receiver, startPosition, endPosition);
	}

	@Override
	public String getFrom(){
		return fromPosition;
	}

	@Override
	public String getTo(){
		return toPosition;
	}


	/**
	 * Get the from position
	 * @return	the from position, can be null
	 */
	public String getFromPosition() {
		return fromPosition;
	}
	
	/**
	 * Set the from position
	 * @param fromPosition		the from position, can be null
	 */
	public void setFromPosition(String fromPosition) {
		this.fromPosition = fromPosition;
	}
	
	/**
	 * Get the to position
	 * @return	the to position, can be null
	 */
	public String getToPosition() {
		return toPosition;
	}
	
	/**
	 * Set the to position
	 * @param toPosition	the to position, can be null
	 */
	public void setToPosition(String toPosition) {
		this.toPosition = toPosition;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy