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

prompto.intrinsic.PromptoIterable Maven / Gradle / Ivy

The newest version!
package prompto.intrinsic;

import java.util.Iterator;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public abstract class PromptoIterable implements IterableWithCounts {

	Iterable source;
	long length;
	
	public PromptoIterable(Iterable source, long length) {
		this.source = source;
		this.length = length;
	}
	
	@Override
	public Iterator iterator() {
		return new PromptoIterator();
	}
	
	@Override
	public String toString() {
		return StreamSupport.stream(spliterator(), false)
				.map(Object::toString)
				.collect(Collectors.joining(", "));
	}

	
	class PromptoIterator implements Iterator {
		
		Iterator iter = source.iterator();
		
		@Override
		public boolean hasNext() { return iter.hasNext(); }
		
		@Override
		public R next() { 
			return apply(iter.next()); 
		}
		
	}
	
	protected abstract R apply(S s);
}