Skip to content

Commit

Permalink
Merge 32e71a0 into 04eda63
Browse files Browse the repository at this point in the history
  • Loading branch information
born-to-be-mad committed Jun 5, 2020
2 parents 04eda63 + 32e71a0 commit 8e8449c
Show file tree
Hide file tree
Showing 47 changed files with 912 additions and 921 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -14,9 +14,9 @@ class as well as primitive collectors concept.

Full API documentation is available [here](http://amaembo.github.io/streamex/javadoc/).

Take a look at the [Cheatsheet](CHEATSHEET.md) for brief introduction to the StreamEx!
Take a look at the [Cheatsheet](wiki/CHEATSHEET.md) for brief introduction to the StreamEx!

Before updating StreamEx check the [migration notes](MIGRATION.md) and full list of [changes](CHANGES.md).
Before updating StreamEx check the [migration notes](wiki/MIGRATION.md) and full list of [changes](wiki/CHANGES.md).

StreamEx library main points are following:

Expand Down Expand Up @@ -123,7 +123,7 @@ This project is licensed under [Apache License, version 2.0](https://www.apache.

Releases are available in [Maven Central](https://repo1.maven.org/maven2/one/util/streamex/)

Before updating StreamEx check the [migration notes](MIGRATION.md) and full list of [changes](CHANGES.md).
Before updating StreamEx check the [migration notes](wiki/MIGRATION.md) and full list of [changes](wiki/CHANGES.md).

#### Maven

Expand Down
3 changes: 0 additions & 3 deletions src/main/java-mr/9/one/util/streamex/Java9Specific.java
Expand Up @@ -15,9 +15,6 @@
*/
package one.util.streamex;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.function.DoublePredicate;
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java-mr/9/one/util/streamex/VerSpec.java
Expand Up @@ -17,5 +17,5 @@
package one.util.streamex;

/* package */ interface VerSpec {
VersionSpecific VER_SPEC = new Java9Specific();
VersionSpecific VER_SPEC = new Java9Specific();
}
11 changes: 5 additions & 6 deletions src/main/java/one/util/streamex/AbstractStreamEx.java
Expand Up @@ -35,12 +35,12 @@ public abstract class AbstractStreamEx<T, S extends AbstractStreamEx<T, S>> exte
BaseStreamEx<T, Stream<T>, Spliterator<T>, S> implements Stream<T>, Iterable<T> {
@SuppressWarnings("unchecked")
AbstractStreamEx(Stream<? extends T> stream, StreamContext context) {
super((Stream<T>)stream, context);
super((Stream<T>) stream, context);
}

@SuppressWarnings("unchecked")
AbstractStreamEx(Spliterator<? extends T> spliterator, StreamContext context) {
super((Spliterator<T>)spliterator, context);
super((Spliterator<T>) spliterator, context);
}

@Override
Expand Down Expand Up @@ -1178,8 +1178,7 @@ public S prepend(Stream<? extends T> other) {
* operation</a>.
*
* @param other other stream to replace the contents of this stream if this stream is empty.
* @return the stream which contents is replaced by other stream contents only if
* this stream is empty.
* @return the stream which contents is replaced by other stream contents only if this stream is empty.
* @since 0.6.6
*/
public S ifEmpty(Stream<? extends T> other) {
Expand Down Expand Up @@ -1221,7 +1220,7 @@ public List<T> toList() {
@SuppressWarnings("unchecked")
public List<T> toImmutableList() {
Object[] array = toArray(Object[]::new);
switch(array.length) {
switch (array.length) {
case 0:
return Collections.emptyList();
case 1:
Expand Down Expand Up @@ -1821,6 +1820,6 @@ public S prefix(BinaryOperator<T> op) {
@SuppressWarnings("unchecked")
@Override
public <U> U chain(Function<? super S, U> mapper) {
return mapper.apply((S)this);
return mapper.apply((S) this);
}
}
2 changes: 1 addition & 1 deletion src/main/java/one/util/streamex/BaseStreamEx.java
Expand Up @@ -167,5 +167,5 @@ public void close() {
* @return the result of the function invocation.
* @since 0.5.4
*/
abstract public <U> U chain(Function<? super B, U> mapper);
public abstract <U> U chain(Function<? super B, U> mapper);
}
2 changes: 1 addition & 1 deletion src/main/java/one/util/streamex/CancellableCollector.java
Expand Up @@ -20,5 +20,5 @@
import java.util.stream.Collector;

/* package */ abstract class CancellableCollector<T, A, R> implements Collector<T, A, R> {
abstract Predicate<A> finished();
abstract Predicate<A> finished();
}
2 changes: 1 addition & 1 deletion src/main/java/one/util/streamex/CollapseSpliterator.java
Expand Up @@ -97,7 +97,7 @@ public boolean tryAdvance(Consumer<? super R> action) {
return true;
}
}
if (a == NONE) {// start
if (a == NONE) { // start
if (!source.tryAdvance(this)) {
return accept(pushRight(none(), none()), action);
}
Expand Down
Expand Up @@ -31,6 +31,7 @@ public CombinationSpliterator(int n, long pos, long fence, int[] value) {
this.fence = fence;
this.value = value;
}

@Override
public void forEachRemaining(Consumer<? super int[]> action) {
long rest = pos - fence;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/one/util/streamex/EntryStream.java
Expand Up @@ -253,7 +253,7 @@ public <VV> EntryStream<K, VV> flatMapToValue(
* @since 0.3.0
*/
public <R> StreamEx<R> flatMapKeyValue(BiFunction<? super K, ? super V, ? extends Stream<? extends R>> mapper) {
return this.<R> flatMap(toFunction(mapper));
return this.<R>flatMap(toFunction(mapper));
}

/**
Expand Down Expand Up @@ -516,7 +516,7 @@ public <VV> EntryStream<K, VV> mapValues(Function<? super V, ? extends VV> value
* @return the new stream
*/
public <R> StreamEx<R> mapKeyValue(BiFunction<? super K, ? super V, ? extends R> mapper) {
return this.<R> map(toFunction(mapper));
return this.<R>map(toFunction(mapper));
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/one/util/streamex/HeadTailSpliterator.java
Expand Up @@ -45,10 +45,10 @@

@Override
public boolean tryAdvance(Consumer<? super U> action) {
if(!init())
if (!init())
return false;
target = TailSpliterator.tryAdvanceWithTail(target, action);
if(target == null) {
if (target == null) {
context = null;
return false;
}
Expand All @@ -57,7 +57,7 @@ public boolean tryAdvance(Consumer<? super U> action) {

@Override
public Spliterator<U> tryAdvanceOrTail(Consumer<? super U> action) {
if(!init())
if (!init())
return null;
Spliterator<U> tail = target;
target = null;
Expand All @@ -67,7 +67,7 @@ public Spliterator<U> tryAdvanceOrTail(Consumer<? super U> action) {

@Override
public void forEachRemaining(Consumer<? super U> action) {
if(!init())
if (!init())
return;
TailSpliterator.forEachWithTail(target, action);
target = null;
Expand All @@ -80,20 +80,20 @@ public Spliterator<U> forEachOrTail(Consumer<? super U> action) {
}

private boolean init() {
if(context == null)
if (context == null)
return false;
if(target == null) {
if (target == null) {
Box<T> first = new Box<>();
source = TailSpliterator.tryAdvanceWithTail(source, first);
Stream<U> stream = source == null ? emptyMapper.get() : mapper.apply(first.a, StreamEx.of(source));
source = null;
mapper = null;
emptyMapper = null;
if(stream == null) {
if (stream == null) {
target = Spliterators.emptySpliterator();
} else {
StreamContext ctx = StreamContext.of(stream);
if(ctx.closeHandler != null)
if (ctx.closeHandler != null)
context.onClose(ctx.closeHandler);
target = stream.spliterator();
}
Expand All @@ -103,7 +103,7 @@ private boolean init() {

@Override
public long estimateSize() {
if(context == null)
if (context == null)
return 0;
return (target == null ? source : target).estimateSize();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/one/util/streamex/IfEmptySpliterator.java
Expand Up @@ -106,7 +106,7 @@ public long estimateSize() {

@Override
public int characteristics() {
if(alt == null) {
if (alt == null) {
return spltr.characteristics() & (~SORTED);
}
return (spltr.characteristics() & alt.characteristics() & (~SORTED)) |
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/one/util/streamex/Internals.java
Expand Up @@ -332,7 +332,7 @@ public Set<Map.Entry<Boolean, T>> entrySet() {
return new AbstractSet<Map.Entry<Boolean, T>>() {
@Override
public Iterator<Map.Entry<Boolean, T>> iterator() {
return Arrays.<Map.Entry<Boolean, T>> asList(new SimpleEntry<>(Boolean.TRUE, trueValue),
return Arrays.<Map.Entry<Boolean, T>>asList(new SimpleEntry<>(Boolean.TRUE, trueValue),
new SimpleEntry<>(Boolean.FALSE, falseValue)).iterator();
}

Expand Down Expand Up @@ -488,8 +488,8 @@ static PartialCollector<StringBuilder, String> joining(CharSequence delimiter, C
};
Supplier<StringBuilder> supplier = StringBuilder::new;
if (hasPS)
return new PartialCollector<>(supplier, merger, sb -> String.valueOf(prefix) + sb +
suffix, NO_CHARACTERISTICS);
return new PartialCollector<>(supplier, merger, sb -> String.valueOf(prefix) + sb + suffix,
NO_CHARACTERISTICS);
return new PartialCollector<>(supplier, merger, StringBuilder::toString, NO_CHARACTERISTICS);
}
}
Expand Down Expand Up @@ -867,7 +867,7 @@ public Object[] toArray() {
/**
* A spliterator which may perform tail-stream optimization
*
* @param <T>
* @param <T> the type of elements returned by this spliterator
*/
interface TailSpliterator<T> extends Spliterator<T> {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/one/util/streamex/Joining.java
Expand Up @@ -396,13 +396,13 @@ public Joining maxGraphemes(int limit) {
* ellipsis sequence. The cutting strategy is mostly irrelevant for this
* mode except {@link #cutBeforeDelimiter()}.
* <p>
* The collector returned by this method is <a href="package-summary.html#ShortCircuitReduction">short-circuiting</a>:
* The collector returned by this method is
* <a href="package-summary.html#ShortCircuitReduction">short-circuiting</a>:
* it may not process all the input elements if the limit is reached.
*
* @param limit the maximal number of input elements in the resulting
* String.
* @param limit the maximal number of input elements in the resulting String.
* @return a new {@code Collector} which will produce String no longer than
* given limit.
* given limit.
* @since 0.6.7
*/
public Joining maxElements(int limit) {
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/one/util/streamex/MoreCollectors.java
Expand Up @@ -188,7 +188,7 @@ private MoreCollectors() {
* @since 0.3.8
*/
public static <T> Collector<T, ?, List<T>> distinctBy(Function<? super T, ?> mapper) {
return Collector.<T, Map<Object, T>, List<T>> of(LinkedHashMap::new, (map, t) -> map.putIfAbsent(mapper.apply(
return Collector.<T, Map<Object, T>, List<T>>of(LinkedHashMap::new, (map, t) -> map.putIfAbsent(mapper.apply(
t), t), (m1, m2) -> {
for (Entry<Object, T> e : m2.entrySet()) {
m1.putIfAbsent(e.getKey(), e.getValue());
Expand Down Expand Up @@ -399,7 +399,7 @@ private MoreCollectors() {
* @see #maxAll()
*/
public static <T extends Comparable<? super T>, A, D> Collector<T, ?, D> maxAll(Collector<T, A, D> downstream) {
return maxAll(Comparator.<T> naturalOrder(), downstream);
return maxAll(Comparator.<T>naturalOrder(), downstream);
}

/**
Expand All @@ -414,7 +414,7 @@ private MoreCollectors() {
* @see #maxAll(Collector)
*/
public static <T extends Comparable<? super T>> Collector<T, ?, List<T>> maxAll() {
return maxAll(Comparator.<T> naturalOrder(), Collectors.toList());
return maxAll(Comparator.<T>naturalOrder(), Collectors.toList());
}

/**
Expand Down Expand Up @@ -472,7 +472,7 @@ private MoreCollectors() {
* @see #minAll()
*/
public static <T extends Comparable<? super T>, A, D> Collector<T, ?, D> minAll(Collector<T, A, D> downstream) {
return maxAll(Comparator.<T> reverseOrder(), downstream);
return maxAll(Comparator.<T>reverseOrder(), downstream);
}

/**
Expand All @@ -487,7 +487,7 @@ private MoreCollectors() {
* @see #minAll(Collector)
*/
public static <T extends Comparable<? super T>> Collector<T, ?, List<T>> minAll() {
return maxAll(Comparator.<T> reverseOrder(), Collectors.toList());
return maxAll(Comparator.<T>reverseOrder(), Collectors.toList());
}

/**
Expand Down Expand Up @@ -628,7 +628,7 @@ private MoreCollectors() {
public static <T> Collector<T, ?, List<T>> tail(int n) {
if (n <= 0)
return empty();
return Collector.<T, Deque<T>, List<T>> of(ArrayDeque::new, (acc, t) -> {
return Collector.<T, Deque<T>, List<T>>of(ArrayDeque::new, (acc, t) -> {
if (acc.size() == n)
acc.pollFirst();
acc.addLast(t);
Expand Down Expand Up @@ -700,7 +700,7 @@ private MoreCollectors() {
* n stream elements or less if the stream was shorter.
*/
public static <T extends Comparable<? super T>> Collector<T, ?, List<T>> greatest(int n) {
return least(Comparator.<T> reverseOrder(), n);
return least(Comparator.<T>reverseOrder(), n);
}

/**
Expand Down Expand Up @@ -748,7 +748,7 @@ private MoreCollectors() {
return list;
return new ArrayList<>(list.subList(0, n));
});
return Collector.<T, Limiter<T>, List<T>> of(() -> new Limiter<>(n, comparator), Limiter::put, Limiter::putAll,
return Collector.<T, Limiter<T>, List<T>>of(() -> new Limiter<>(n, comparator), Limiter::put, Limiter::putAll,
pq -> {
pq.sort();
return new ArrayList<>(pq);
Expand Down Expand Up @@ -783,7 +783,7 @@ private MoreCollectors() {
* stream elements or less if the stream was shorter.
*/
public static <T extends Comparable<? super T>> Collector<T, ?, List<T>> least(int n) {
return least(Comparator.<T> naturalOrder(), n);
return least(Comparator.<T>naturalOrder(), n);
}

/**
Expand All @@ -803,6 +803,7 @@ class Container {
long count = 0;
long index = -1;
}

return Collector.of(Container::new, (c, t) -> {
if (c.index == -1 || comparator.compare(c.value, t) > 0) {
c.value = t;
Expand Down

0 comments on commit 8e8449c

Please sign in to comment.