这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ public void groupedOnEmpty() throws Exception {
assertThat( empty.grouped(10).count(),equalTo(0l));
}

@Test(expected=IllegalArgumentException.class)
@Test
public void groupedEmpty0() throws Exception {
empty.grouped(0).toList();

}
@Test(expected=IllegalArgumentException.class)
@Test
public void grouped0() throws Exception {
nonEmpty.grouped(0).toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void testReverseListLimit() {
public void testReverseRange() {

assertThat( ReactiveSeq.range(0,10)
.reverse().toList(), equalTo(asList(10,9,8,7,6,5,4,3,2,1)));
.reverse().toList(), equalTo(asList(9,8,7,6,5,4,3,2,1,0)));
}
@Test
public void testCycleLong() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void testReverseListLimit() {
public void testReverseRange() {

assertThat( ReactiveSeq.range(0,10)
.reverse().toList(), equalTo(asList(10,9,8,7,6,5,4,3,2,1)));
.reverse().toList(), equalTo(asList(9,8,7,6,5,4,3,2,1,0)));
}
@Test
public void testCycleLong() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void testReverseListLimit() {
public void testReverseRange() {

assertThat( ReactiveSeq.range(0,10)
.reverse().toList(), equalTo(asList(10,9,8,7,6,5,4,3,2,1)));
.reverse().toList(), equalTo(asList(9,8,7,6,5,4,3,2,1,0)));
}
@Test
public void testCycleLong() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void testReverseListLimit() {
public void testReverseRange() {

assertThat( ReactiveSeq.range(0,10)
.reverse().toList(), equalTo(asList(10,9,8,7,6,5,4,3,2,1)));
.reverse().toList(), equalTo(asList(9,8,7,6,5,4,3,2,1,0)));
}
@Test
public void testCycleLong() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void testReverseListLimit() {
public void testReverseRange() {

assertThat( ReactiveSeq.range(0,10)
.reverse().toList(), equalTo(asList(10,9,8,7,6,5,4,3,2,1)));
.reverse().toList(), equalTo(asList(9,8,7,6,5,4,3,2,1,0)));
}
@Test
public void testCycleLong() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,24 +296,24 @@ public ReactiveSeq<Vector<T>> grouped(final int groupSize) {

@Override
public ReactiveSeq<Vector<T>> groupedWhile(final BiPredicate<Vector<? super T>, ? super T> predicate) {
return createSeq(new GroupedStatefullyOperator<>(source, () -> Vector.empty(), Function.identity(), predicate));
return createSeq(new GroupedStatefullyOperator<>(source, () -> Vector.empty(), Function.identity(), predicate.negate()));
}

@Override
public <C extends PersistentCollection<T>, R> ReactiveSeq<R> groupedWhile(final BiPredicate<C, ? super T> predicate, final Supplier<C> factory,
Function<? super C, ? extends R> finalizer) {
return this.<R>createSeq(new GroupedStatefullyOperator<>(source, factory, finalizer, predicate));
return this.<R>createSeq(new GroupedStatefullyOperator<>(source, factory, finalizer, predicate.negate()));
}

@Override
public ReactiveSeq<Vector<T>> groupedUntil(final BiPredicate<Vector<? super T>, ? super T> predicate) {
return createSeq(new GroupedStatefullyOperator<>(source, () -> Vector.empty(), Function.identity(), predicate.negate()));
return createSeq(new GroupedStatefullyOperator<>(source, () -> Vector.empty(), Function.identity(), predicate));
}

@Override
public <C extends PersistentCollection<T>, R> ReactiveSeq<R> groupedUntil(final BiPredicate<C, ? super T> predicate, final Supplier<C> factory,
Function<? super C, ? extends R> finalizer) {
return this.<R>createSeq(new GroupedStatefullyOperator<>(source, factory, finalizer, predicate.negate()));
return this.<R>createSeq(new GroupedStatefullyOperator<>(source, factory, finalizer, predicate));
}

@Override
Expand Down Expand Up @@ -722,11 +722,11 @@ public ReactiveSeq<T> appendAll(final T... other) {

@Override
public ReactiveSeq<T> prependStream(final Stream<? extends T> other) {
return Spouts.concat((Stream<T>) (other), this);
return Spouts.concat(other, this);
}

public ReactiveSeq<T> prependAll(final Iterable<? extends T> other) {
return Spouts.concat((Stream<T>) (other), this);
return Spouts.concat((Spouts.fromIterable( other)), this);
}

@Override
Expand Down Expand Up @@ -832,14 +832,17 @@ public <C extends PersistentCollection<? super T>> ReactiveSeq<C> grouped(final

@Override
public ReactiveSeq<T> dropRight(final int num) {

if(num<=0)
return this;
if(num==1)
return createSeq(new SkipLastOneOperator<>(source));
return createSeq(new SkipLastOperator<>(source, num < 0 ? 0 : num));
}

@Override
public ReactiveSeq<T> takeRight(final int num) {
if(num<=0)
return Spouts.empty();
if (num == 1)
return createSeq(new LimitLastOneOperator<>(source));
return createSeq(new LimitLastOperator<>(source, num < 0 ? 0 : num));
Expand Down Expand Up @@ -1481,5 +1484,19 @@ public void onComplete() {
return maybe;
}

@Override
public int hashCode() {
return vector().hashCode();
}

@Override
public boolean equals(Object obj) {
if(obj instanceof ReactiveSeq){
ReactiveSeq it = (ReactiveSeq) obj;
return this.equalToIteration(it);

}
return super.equals(obj);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ public final <U> ReactiveSeq<U> scanLeft(final U seed, final BiFunction<? super

@Override
public ReactiveSeq<T> skip(final long num) {
if(this.stream instanceof Indexable){
Indexable<T> indexable = (Indexable)stream;
return createSeq(indexable.skip(num),reversible);
}
return createSeq(new SkipSpliterator<>(get(),num), reversible);
}

Expand All @@ -246,13 +242,6 @@ public final ReactiveSeq<T> dropUntil(final Predicate<? super T> p) {
@Override
public ReactiveSeq<T> limit(final long num) {


if(this.stream instanceof Indexable){
Indexable<T> indexable = (Indexable)stream;
Spliterator<T> limit = indexable.take(num);

return createSeq(limit,Optional.empty());
}
return createSeq(new LimitSpliterator<T>(get(),num), reversible);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,18 @@ public <R> R fold(Function<? super ReactiveSeq<T>,? extends R> sync, Function<?
return sync.apply(this);
}

@Override
public int hashCode() {
return vector().hashCode();
}

@Override
public boolean equals(Object obj) {
if(obj instanceof ReactiveSeq){
ReactiveSeq it = (ReactiveSeq) obj;
return this.equalToIteration(it);

}
return super.equals(obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public class GroupingSpliterator<T, C extends PersistentCollection<? super T>,R>
private final int groupSize;
public GroupingSpliterator(final Spliterator<T> source, Supplier<? extends C> factory, Function<? super C, ? extends R> finalizer,int groupSize) {
super(source.estimateSize(),source.characteristics() & Spliterator.ORDERED);
if(groupSize<=0)
throw new IllegalArgumentException("Group size must be greater than ");

this.source = source;
this.factory = factory;
this.groupSize = groupSize;
this.groupSize = groupSize >0 ? groupSize : 1;
this.finalizer=finalizer;
collection =factory.get();

Expand Down Expand Up @@ -66,7 +65,7 @@ public void forEachRemaining(Consumer<? super R> action) {
public boolean tryAdvance(Consumer<? super R> action) {
if(closed)
return false;
for(int i=collection.size();i<groupSize;i++) {
for(int i=collection.size();collection.size()<groupSize;i++) {
boolean canAdvance = source.tryAdvance(t -> {
collection = (C)collection.plus(t);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.oath.cyclops.internal.stream.spliterators;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.Spliterators.AbstractSpliterator;
Expand All @@ -22,14 +24,14 @@ public static <T> Spliterator<T> takeRight(Spliterator<T> source, int limit){
}


private final ArrayDeque<T> buffer;
private final Deque<T> buffer;
private final int limit;
private final Spliterator<T> source;

public LimitLastSpliterator(final Spliterator<T> source, final int limit) {
super(source.estimateSize(),source.characteristics() & Spliterator.ORDERED);
buffer = new ArrayDeque<>(
limit);
buffer = limit < 1_000 ? new ArrayDeque<>(
limit) : new LinkedList<>();
this.source = source;;
this.limit = limit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import lombok.Getter;
import lombok.Setter;

//@AllArgsConstructor
public class ReversingArraySpliterator<T> implements Spliterator<T>, ReversableSpliterator<T>, Indexable<T> {

public class ReversingArraySpliterator<T> implements Spliterator<T>, ReversableSpliterator<T> {

private final Object[] array;
private int max;
Expand Down Expand Up @@ -106,21 +106,5 @@ public ReversableSpliterator<T> copy() {
array, start,max,reverse);
}

@Override
public Spliterator<T> skip(long offset) {
this.start = index= this.start+(int)offset;
return new ReversingArraySpliterator<T>(
array, start, max,reverse);


}

@Override
public Spliterator<T> take(long num) {
this.max = start+(int)num;
return new ReversingArraySpliterator<T>(
array, start, max,reverse);
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.oath.cyclops.internal.stream.spliterators;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.Spliterators.AbstractSpliterator;
Expand All @@ -21,14 +23,14 @@ public static <T> Spliterator<T> dropRight(Spliterator<T> source, int skip){
}


private final ArrayDeque<T> buffer;
private final Deque<T> buffer;
private final int skip;
private final Spliterator<T> source;

public SkipLastSpliterator(final Spliterator<T> source, final int skip) {
super(source.estimateSize(),source.characteristics() & Spliterator.ORDERED);
buffer = new ArrayDeque<>(
skip);
buffer = skip <1_000 ? new ArrayDeque<>(
skip) : new LinkedList<>();
this.source = source;;
this.skip = skip;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.oath.cyclops.internal.stream.spliterators.doubles;

import com.oath.cyclops.internal.stream.spliterators.Indexable;

import com.oath.cyclops.internal.stream.spliterators.ReversableSpliterator;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -11,7 +11,7 @@
import java.util.function.DoubleConsumer;

//@AllArgsConstructor
public class ReversingDoubleArraySpliterator<Double> implements Spliterator.OfDouble,ReversableSpliterator<java.lang.Double>, Indexable<java.lang.Double> {
public class ReversingDoubleArraySpliterator<Double> implements Spliterator.OfDouble,ReversableSpliterator<java.lang.Double> {

private final double[] array;
private int max;
Expand Down Expand Up @@ -152,16 +152,5 @@ public ReversableSpliterator<java.lang.Double> copy() {
array, start,max,reverse);
}

@Override
public Spliterator<java.lang.Double> skip(long offset) {
this.start = index= this.start+(int)offset;
return this;
}

@Override
public Spliterator<java.lang.Double> take(long num) {
this.max = start+(int)num;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.oath.cyclops.internal.stream.spliterators.ints;

import com.oath.cyclops.internal.stream.spliterators.Indexable;

import com.oath.cyclops.internal.stream.spliterators.ReversableSpliterator;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -11,7 +11,7 @@
import java.util.function.IntConsumer;

//@AllArgsConstructor
public class ReversingIntArraySpliterator<Integer> implements Spliterator.OfInt,ReversableSpliterator<java.lang.Integer>, Indexable<java.lang.Integer> {
public class ReversingIntArraySpliterator<Integer> implements Spliterator.OfInt,ReversableSpliterator<java.lang.Integer> {

private final int[] array;
private int max;
Expand Down Expand Up @@ -152,16 +152,6 @@ public ReversableSpliterator<java.lang.Integer> copy() {
array, start,max,reverse);
}

@Override
public Spliterator<java.lang.Integer> skip(long offset) {
this.start = index= this.start+(int)offset;
return this;
}

@Override
public Spliterator<java.lang.Integer> take(long num) {
this.max = start+(int)num;
return this;
}

}
Loading