Skip to content

Commit

Permalink
(yegor256#1252) After review refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
fanifieiev committed Dec 6, 2019
1 parent 1591022 commit d68a61f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 72 deletions.
18 changes: 8 additions & 10 deletions src/main/java/org/cactoos/collection/Reversed.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.cactoos.func.FuncOf;
import org.cactoos.func.StickyFunc;
import org.cactoos.func.UncheckedFunc;
import org.cactoos.iterable.IterableOf;

Expand Down Expand Up @@ -58,15 +58,13 @@ public Reversed(final X... src) {
public Reversed(final Iterable<X> src) {
super(
new UncheckedFunc<>(
new FuncOf<Iterable<X>, Collection<X>>(
new org.cactoos.scalar.Sticky<>(
() -> {
final List<X> items = new LinkedList<>();
src.forEach(items::add);
Collections.reverse(items);
return items;
}
)
new StickyFunc<Iterable<X>, Collection<X>>(
input -> {
final List<X> items = new LinkedList<>();
input.forEach(items::add);
Collections.reverse(items);
return items;
}
)
).apply(src)
);
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/org/cactoos/collection/Shuffled.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.cactoos.func.FuncOf;
import org.cactoos.func.StickyFunc;
import org.cactoos.func.UncheckedFunc;
import org.cactoos.iterable.IterableOf;

Expand Down Expand Up @@ -57,15 +57,13 @@ public Shuffled(final T... src) {
public Shuffled(final Iterable<T> src) {
super(
new UncheckedFunc<>(
new FuncOf<Iterable<T>, Collection<T>>(
new org.cactoos.scalar.Sticky<>(
() -> {
final List<T> items = new LinkedList<>();
src.forEach(items::add);
Collections.shuffle(items);
return items;
}
)
new StickyFunc<Iterable<T>, Collection<T>>(
input -> {
final List<T> items = new LinkedList<>();
input.forEach(items::add);
Collections.shuffle(items);
return items;
}
)
).apply(src)
);
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/org/cactoos/collection/Solid.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.cactoos.func.FuncOf;
import org.cactoos.func.SolidFunc;
import org.cactoos.func.UncheckedFunc;
import org.cactoos.iterable.IterableOf;

Expand Down Expand Up @@ -58,17 +58,13 @@ public Solid(final T... array) {
public Solid(final Iterable<T> src) {
super(
new UncheckedFunc<>(
new FuncOf<Iterable<T>, Collection<T>>(
new org.cactoos.scalar.Solid<>(
new org.cactoos.scalar.Sticky<>(
() -> {
final List<T> items = new LinkedList<>();
src.forEach(items::add);
Collections.shuffle(items);
return items;
}
)
)
new SolidFunc<Iterable<T>, Collection<T>>(
input -> {
final List<T> items = new LinkedList<>();
input.forEach(items::add);
Collections.shuffle(items);
return items;
}
)
).apply(src)
);
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/org/cactoos/collection/Sorted.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import org.cactoos.func.FuncOf;
import org.cactoos.func.StickyFunc;
import org.cactoos.func.UncheckedFunc;
import org.cactoos.iterable.IterableOf;
import org.cactoos.list.ListOf;
Expand Down Expand Up @@ -83,15 +83,13 @@ public Sorted(final Comparator<T> cmp, final T... src) {
public Sorted(final Comparator<T> cmp, final Iterable<T> src) {
super(
new UncheckedFunc<>(
new FuncOf<Iterable<T>, Collection<T>>(
new org.cactoos.scalar.Sticky<>(
() -> {
final List<T> items = new LinkedList<>();
src.forEach(items::add);
items.sort(cmp);
return items;
}
)
new StickyFunc<Iterable<T>, Collection<T>>(
input -> {
final List<T> items = new LinkedList<>();
input.forEach(items::add);
items.sort(cmp);
return items;
}
)
).apply(src)
);
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/cactoos/collection/Sticky.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.Collection;
import java.util.LinkedList;
import org.cactoos.func.FuncOf;
import org.cactoos.func.StickyFunc;
import org.cactoos.func.UncheckedFunc;
import org.cactoos.iterable.IterableOf;

Expand Down Expand Up @@ -55,14 +55,12 @@ public Sticky(final E... src) {
public Sticky(final Iterable<E> src) {
super(
new UncheckedFunc<>(
new FuncOf<Iterable<E>, Collection<E>>(
new org.cactoos.scalar.Sticky<>(
() -> {
final Collection<E> temp = new LinkedList<>();
src.forEach(temp::add);
return temp;
}
)
new StickyFunc<Iterable<E>, Collection<E>>(
input -> {
final Collection<E> temp = new LinkedList<>();
input.forEach(temp::add);
return temp;
}
)
).apply(src)
);
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/cactoos/collection/Synced.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import org.cactoos.func.FuncOf;
import org.cactoos.func.SyncFunc;
import org.cactoos.func.UncheckedFunc;
import org.cactoos.iterable.IterableOf;

Expand Down Expand Up @@ -64,14 +64,12 @@ public Synced(final T... array) {
public Synced(final Iterable<T> src) {
super(
new UncheckedFunc<>(
new FuncOf<Iterable<T>, Collection<T>>(
new org.cactoos.scalar.Synced<>(
() -> {
final Collection<T> temp = new LinkedList<>();
src.forEach(temp::add);
return Collections.synchronizedCollection(temp);
}
)
new SyncFunc<Iterable<T>, Collection<T>>(
input -> {
final Collection<T> temp = new LinkedList<>();
input.forEach(temp::add);
return Collections.synchronizedCollection(temp);
}
)
).apply(src)
);
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/org/cactoos/set/SetOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import java.util.HashSet;
import java.util.Set;
import org.cactoos.collection.CollectionEnvelope;
import org.cactoos.func.FuncOf;
import org.cactoos.func.UncheckedFunc;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.Unchecked;

/**
* Iterable as {@link Set}.
Expand Down Expand Up @@ -62,16 +60,12 @@ public SetOf(final T... array) {
*/
public SetOf(final Iterable<T> src) {
super(
new UncheckedFunc<>(
new FuncOf<Iterable<T>, Set<T>>(
new Unchecked<>(
() -> {
final Set<T> tmp = new HashSet<>();
src.forEach(tmp::add);
return Collections.unmodifiableSet(tmp);
}
)
)
new UncheckedFunc<Iterable<T>, Set<T>>(
input -> {
final Set<T> tmp = new HashSet<>();
input.forEach(tmp::add);
return Collections.unmodifiableSet(tmp);
}
).apply(src)
);
}
Expand Down

0 comments on commit d68a61f

Please sign in to comment.