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

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

The newest version!
/**
 * 
 */
package net.sf.jabb.dstream;

import java.time.Instant;

import org.apache.commons.lang3.Validate;


/**
 * Simple data structure for a StreamDataSupplier and an ID.
 * @author James Hu
 *
 * @param  type of the message object
 */
public class SimpleStreamDataSupplierWithId implements StreamDataSupplierWithId {
	protected String id;
	protected StreamDataSupplier supplier;
	
	public SimpleStreamDataSupplierWithId(){
		
	}
	
	public SimpleStreamDataSupplierWithId(String id, StreamDataSupplier supplier){
		this.id = id;
		this.supplier = supplier;
	}
	
	@Override
	public StreamDataSupplierWithIdAndPositionRange withRange(String fromPosition, String toPosition){
		if (fromPosition != null && toPosition != null){
			Validate.isTrue(supplier.isInRange(fromPosition, toPosition), "fromPosition cannot be after toPosition");
		}
		return new StreamDataSupplierWithIdAndPositionRange<>(id, supplier, fromPosition, toPosition);
	}
	
	@Override
	public StreamDataSupplierWithIdAndEnqueuedTimeRange withRange(Instant fromTime, Instant toTime){
		if (fromTime != null && toTime != null){
			Validate.isTrue(supplier.isInRange(fromTime, toTime), "fromTime cannot be after toTime");
		}
		return new StreamDataSupplierWithIdAndEnqueuedTimeRange<>(id, supplier, fromTime, toTime);
	}
	
	@Override
	public String toString(){
		return (id == null ? "" : id) + ": " + supplier;
	}
	
	@Override
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@Override
	public StreamDataSupplier getSupplier() {
		return supplier;
	}

	public void setSupplier(StreamDataSupplier supplier) {
		this.supplier = supplier;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy