Skip to content

Commit

Permalink
main methods models writed
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Komarov (k0m@) committed Jun 16, 2021
1 parent b44442d commit 21761e5
Showing 1 changed file with 182 additions and 21 deletions.
203 changes: 182 additions & 21 deletions src/main/java/pw/komarov/streamer/Streamer.java
Expand Up @@ -140,62 +140,95 @@ private void throwIfNotWaiting() {
throw new IllegalStateException("stream has already been operated upon or closed");
}

@Override
public Stream<T> onClose(Runnable closeHandler) {
throwIfNotWaiting();

onCloseSequences.add(closeHandler);

return this;
}

/*
Intermediate methods (conveyor/pipeline)
*/

@Override
public Stream<T> limit(long maxSize) {
throw new UnsupportedOperationException("will be soon");
throwIfNotWaiting();

//todo: add operations here

return this;
}

@Override
public Stream<T> skip(long n) {
throw new UnsupportedOperationException("will be soon");
throwIfNotWaiting();

//todo: add operations here

return this;
}

@Override
public Stream<T> distinct() {
throw new UnsupportedOperationException("will be soon");
throwIfNotWaiting();

//todo: add operations here

return this;
}

@Override
public Stream<T> filter(Predicate<? super T> predicate) {
throw new UnsupportedOperationException("will be soon");
throwIfNotWaiting();

//todo: add operations here

return this;
}

@Override
public <R> Stream<R> map(Function<? super T, ? extends R> mapper) {
throw new UnsupportedOperationException("will be soon");
public Stream<T> sorted() {
throwIfNotWaiting();

//todo: add operations here

return this;
}

@Override
public <R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper) {
throw new UnsupportedOperationException("will be soon");
public Stream<T> sorted(Comparator<? super T> comparator) {
throwIfNotWaiting();

//todo: add operations here

return this;
}

@Override
public Stream<T> sorted() {
throw new UnsupportedOperationException("will be soon");
@SuppressWarnings("unchecked")
public <R> Stream<R> map(Function<? super T, ? extends R> mapper) {
throwIfNotWaiting();

//todo: add operations here

return (Streamer<R>) this;
}

@Override
public Stream<T> sorted(Comparator<? super T> comparator) {
public <R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper) {
throw new UnsupportedOperationException("will be soon");
}

@Override
public Stream<T> peek(Consumer<? super T> action) {
throw new UnsupportedOperationException("will be soon");
throwIfNotWaiting();

//todo: add operations here

return this;
}

@Override
public Stream<T> onClose(Runnable closeHandler) {
throwIfNotWaiting();

onCloseSequences.add(closeHandler);

return this;
}

/*
Expand All @@ -204,21 +237,53 @@ public Stream<T> peek(Consumer<? super T> action) {

@Override
public Iterator<T> iterator() {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public boolean anyMatch(Predicate<? super T> predicate) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public boolean allMatch(Predicate<? super T> predicate) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public boolean noneMatch(Predicate<? super T> predicate) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

Expand All @@ -229,61 +294,157 @@ public Optional<T> findFirst() {

@Override
public Optional<T> findAny() {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public void forEach(Consumer<? super T> action) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public Optional<T> min(Comparator<? super T> comparator) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public Optional<T> max(Comparator<? super T> comparator) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public T reduce(T identity, BinaryOperator<T> accumulator) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public Optional<T> reduce(BinaryOperator<T> accumulator) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public <U> U reduce(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public long count() {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public <R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public <R, A> R collect(Collector<? super T, A, R> collector) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public Object[] toArray() {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

@Override
public <A> A[] toArray(IntFunction<A[]> generator) {
throwIfNotWaiting();

state = State.OPERATED;

//todo: терминальные операции...

internalClose();

throw new UnsupportedOperationException("will be soon");
}

Expand Down

0 comments on commit 21761e5

Please sign in to comment.