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

org.codefilarete.tool.function.Serie Maven / Gradle / Ivy

package org.codefilarete.tool.function;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * Very close to {@link Sequence} but with a seed on each {@link #next(Object)} : {@link Serie}s doesn't have to keep their state.
 * 
 * @author Guillaume Mary
 */
@FunctionalInterface
public interface Serie {
	
	/** Default instance for an integer serie */
	IntegerSerie INTEGER_SERIE = new IntegerSerie();
	
	/** Default instance for an integer serie, long-typed */
	LongSerie LONG_SERIE = new LongSerie();
	
	/** Every {@link #next(Object)} returns a new {@link Date} */
	NowSerie NOW_SERIE = new NowSerie();
	
	I next(I input);
	
	/** An integer serie */
	class IntegerSerie implements Serie {
		
		@Override
		public Integer next(Integer input) {
			return ++input;
		}
	}
	
	/** An integer serie, long-typed */
	class LongSerie implements Serie {
		
		@Override
		public Long next(Long input) {
			return ++input;
		}
	}
	
	/** Every {@link #next(Object)} returns a new {@link LocalDateTime} */
	class NowSerie implements Serie {
		
		@Override
		public LocalDateTime next(LocalDateTime input) {
			return LocalDateTime.now();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy