Skip to content

Commit

Permalink
Complete ReferenceStreamBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
minborg committed Apr 18, 2015
1 parent ab60dbc commit 773f883
Show file tree
Hide file tree
Showing 49 changed files with 1,562 additions and 1,149 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/speedment/util/OptionalMeta.java
@@ -1,3 +1,19 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.util;

import java.util.NoSuchElementException;
Expand Down
@@ -0,0 +1,70 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.util.stream.builder;

import com.speedment.util.stream.builder.pipeline.BasePipeline;
import com.speedment.util.stream.builder.streamterminator.StreamTerminator;
import com.speedment.util.stream.builder.action.Action;

/**
*
* @author pemi
* @param <T> The type of the super class
*/
public class BaseStreamBuilder<T extends BaseStreamBuilder<T>> {

protected final BasePipeline<?> pipeline;
protected final StreamTerminator streamTerminator;

public BaseStreamBuilder(BasePipeline<?> pipeline, StreamTerminator streamTerminator) {
this.pipeline = pipeline;
this.streamTerminator = streamTerminator;
}

protected T append(Action newAction) {
pipeline.add(newAction);
return (T) this;
}


public T sequential() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public T parallel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}


public boolean isParallel() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public T unordered() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public T onClose(Runnable closeHandler) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public void close() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}


}
@@ -1,12 +1,32 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.util.stream.builder;

import com.speedment.util.stream.builder.pipeline.BasePipeline;
import com.speedment.util.stream.builder.pipeline.IntPipeline;
import com.speedment.util.stream.builder.pipeline.ReferencePipeline;
import com.speedment.util.stream.builder.streamterminator.StreamTerminator;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.BaseStream;
import java.util.stream.Stream;

/**
*
* @author pemi
* @param <E> E type of the Collection
*/
public class CollectionsStreamTerminator<E> implements StreamTerminator {

Expand All @@ -16,27 +36,32 @@ public CollectionsStreamTerminator(Collection<E> Collection) {
this.collection = Collection;
}


@Override
public <T, S extends BaseStream<T, S>> BaseStream<T, S> baseStream(Pipeline<T> pipeline) {
return pipeline.stream(collection.stream());
public <T> long count(ReferencePipeline<T> pipeline) {
if (pipeline.stream().allMatch(a -> !a.isCountModifying())) {
return collection.size();
}
return StreamTerminator.super.count(pipeline);
}

//
// @Override
// public <T> BaseStream<T, ?> stream(Pipeline<T> pipeline) {
// return pipeline.baseStream(collection.stream());
// }

@Override
public <T> long count(Pipeline<T> pipeline) {
public <T> long count(IntPipeline pipeline) {
// Todo: Check pipeline first
if (pipeline.stream().allMatch(a -> !a.isCountModifying())) {
return collection.size();
}
return pipeline.stream(collection.stream()).count();
return StreamTerminator.super.count(pipeline);
}

@Override
public <T> Optional<T> findAny(Pipeline<T> pipeline) {

public Stream<E> stream() {
return new ReferenceStreamBuilder<>(new BasePipeline(collection::stream), this);
}

public static <E> Stream<E> streamOf(Collection<E> Collection) {
return new CollectionsStreamTerminator<>(Collection).stream();
}

}
@@ -0,0 +1,205 @@
/**
*
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.util.stream.builder;

import com.speedment.util.stream.builder.pipeline.BasePipeline;
import com.speedment.util.stream.builder.streamterminator.StreamTerminator;
import java.util.DoubleSummaryStatistics;
import java.util.OptionalDouble;
import java.util.PrimitiveIterator;
import java.util.Spliterator;
import java.util.function.BiConsumer;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleConsumer;
import java.util.function.DoubleFunction;
import java.util.function.DoublePredicate;
import java.util.function.DoubleToIntFunction;
import java.util.function.DoubleToLongFunction;
import java.util.function.DoubleUnaryOperator;
import java.util.function.ObjDoubleConsumer;
import java.util.function.Supplier;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

/**
*
* @author pemi
*/
public class DoubleStreamBuilder extends BaseStreamBuilder<DoubleStreamBuilder> implements DoubleStream {

public DoubleStreamBuilder(final BasePipeline<?> pipeline, final StreamTerminator streamTerminator) {
super(pipeline, streamTerminator);
}

@Override
public DoubleStream filter(DoublePredicate predicate) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public DoubleStream map(DoubleUnaryOperator mapper) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public IntStream mapToInt(DoubleToIntFunction mapper) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public LongStream mapToLong(DoubleToLongFunction mapper) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public DoubleStream distinct() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public DoubleStream sorted() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public DoubleStream peek(DoubleConsumer action) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public DoubleStream limit(long maxSize) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public DoubleStream skip(long n) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void forEach(DoubleConsumer action) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void forEachOrdered(DoubleConsumer action) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public double[] toArray() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public double reduce(double identity, DoubleBinaryOperator op) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public OptionalDouble reduce(DoubleBinaryOperator op) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public <R> R collect(Supplier<R> supplier, ObjDoubleConsumer<R> accumulator, BiConsumer<R, R> combiner) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public double sum() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public OptionalDouble min() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public OptionalDouble max() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public long count() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public OptionalDouble average() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public DoubleSummaryStatistics summaryStatistics() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public boolean anyMatch(DoublePredicate predicate) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public boolean allMatch(DoublePredicate predicate) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public boolean noneMatch(DoublePredicate predicate) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public OptionalDouble findFirst() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public OptionalDouble findAny() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public Stream<Double> boxed() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public PrimitiveIterator.OfDouble iterator() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public Spliterator.OfDouble spliterator() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}

0 comments on commit 773f883

Please sign in to comment.