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

java.util.StreamImpl Maven / Gradle / Ivy

There is a newer version: 0.96-beta4
Show newest version
/*
 * Copyright (c) 2011-2014 Fernando Petrola
 *
 * 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 java.util;

import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Optional;
import java.util.Spliterator;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import java.util.stream.Collector;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class StreamImpl implements Stream, Consumer
{
	protected Consumer downstream;
	protected StreamImpl topStream;
	private Collection items;

	public StreamImpl()
	{
		topStream= this;
	}
	public StreamImpl(StreamImpl upstream)
	{
		topStream= upstream.topStream;
		upstream.downstream= this;
	}
	public StreamImpl(Collection items)
	{
		this();
		this.items= items;
	}
	public Iterator iterator()
	{
		return items.iterator();
	}
	public Spliterator spliterator()
	{
		// TODO Auto-generated method stub
		return null;
	}
	public boolean isParallel()
	{
		// TODO Auto-generated method stub
		return false;
	}
	public Stream sequential()
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream parallel()
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream unordered()
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream onClose(Runnable closeHandler)
	{
		// TODO Auto-generated method stub
		return null;
	}

	public void close()
	{
		// TODO Auto-generated method stub

	}
	public Stream filter(Predicate predicate)
	{
		return new StreamImpl((StreamImpl) this)
		{
			public void accept(T t)
			{
				if (predicate.test(t))
					downstream.accept(t);
			}
		};
	}
	public  Stream map(Function mapper)
	{
		return new StreamImpl((StreamImpl) this)
		{
			public void accept(T t)
			{
				downstream.accept((T) mapper.apply(t));
			}
		};
	}
	public IntStream mapToInt(ToIntFunction mapper)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public LongStream mapToLong(ToLongFunction mapper)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public DoubleStream mapToDouble(ToDoubleFunction mapper)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public  Stream flatMap(Function> mapper)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public IntStream flatMapToInt(Function mapper)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public LongStream flatMapToLong(Function mapper)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public DoubleStream flatMapToDouble(Function mapper)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream distinct()
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream sorted()
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream sorted(Comparator comparator)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream peek(Consumer action)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream limit(long maxSize)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Stream skip(long n)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public void forEach(Consumer action)
	{
		new StreamImpl((StreamImpl) this)
		{
			public void accept(T t)
			{
				action.accept(t);
			}
		};

		for (Iterator iterator= topStream.iterator(); iterator.hasNext();)
		{
			T type= (T) iterator.next();
			topStream.accept((C) type);
		}
	}
	public void forEachOrdered(Consumer action)
	{
		// TODO Auto-generated method stub

	}
	public Object[] toArray()
	{
		// TODO Auto-generated method stub
		return null;
	}
	public  A[] toArray(IntFunction generator)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public T reduce(T identity, BinaryOperator accumulator)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Optional reduce(BinaryOperator accumulator)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public  U reduce(U identity, BiFunction accumulator, BinaryOperator combiner)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public  R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public  R collect(Collector collector)
	{
		forEach(v -> collector.accumulator().accept(null, v));
		return collector.finisher().apply(null);
	}
	public Optional min(Comparator comparator)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Optional max(Comparator comparator)
	{
		// TODO Auto-generated method stub
		return null;
	}
	public long count()
	{
		int[] counter= new int[1];
		counter[0]= 0;
		forEach(new Consumer()
		{
            public void accept(T t)
            {
				counter[0]++;
            }
		});
		
		return counter[0];
	}
	public boolean anyMatch(Predicate predicate)
	{
		// TODO Auto-generated method stub
		return false;
	}
	public boolean allMatch(Predicate predicate)
	{
		// TODO Auto-generated method stub
		return false;
	}
	public boolean noneMatch(Predicate predicate)
	{
		// TODO Auto-generated method stub
		return false;
	}
	public Optional findFirst()
	{
		// TODO Auto-generated method stub
		return null;
	}
	public Optional findAny()
	{
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void accept(C t)
	{
		downstream.accept(t);
	}
}