Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Dec 17, 2019
2 parents fb7f572 + 696d1da commit 542dc57
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 144 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ To flatten one iterable:
new Joined<>(
new Mapped<>(
iter -> new IterableOf<>(
new CollectionOf<>(iter).toArray(new Integer[]{})
new ListOf<>(iter).toArray(new Integer[]{})
),
new IterableOf<>(new IterableOf<>(1, 2, 3, 4, 5, 6))
new IterableOf<>(1, 2, 3, 4, 5, 6))
)
); // Iterable<Integer>
```
Expand All @@ -151,7 +151,7 @@ To flatten and join several iterables:
new Joined<>(
new Mapped<>(
iter -> new IterableOf<>(
new CollectionOf<>(iter).toArray(new Integer[]{})
new ListOf<>(iter).toArray(new Integer[]{})
),
new Joined<>(
new IterableOf<>(new IterableOf<>(1, 2, 3)),
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/cactoos/collection/CollectionOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@
* the encapsulated iterable, use {@link Sticky}.</p>
*
* <p>There is no thread-safety guarantee.
*
* @param <T> List type
* @see Sticky
* @since 0.1
* @deprecated This test class is to be removed after Cactoos-Matchers project
* remooves the usage of it.
* @todo #1116:30min Remove this deprecated class after the issue
* https://github.com/llorllale/cactoos-matchers/issues/148 has been resolved.
* The Cactoos-Matchers project(https://github.com/llorllale/cactoos-matchers)
* utilizes this class and by removing the class right now causes issues with
* class not found in the Cactoos-Matchers project.
*/
@Deprecated
public final class CollectionOf<T> implements Collection<T> {
/**
* Collection.
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/org/cactoos/collection/Immutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.util.Collection;
import java.util.Iterator;
import org.cactoos.iterable.IterableOf;

/**
* Collection that doesn't allow any modifications.
Expand Down Expand Up @@ -56,23 +55,6 @@ public final class Immutable<X> implements Collection<X> {
*/
private final Collection<X> col;

/**
* Ctor.
* @param src Source elements
*/
@SafeVarargs
public Immutable(final X... src) {
this(new IterableOf<>(src));
}

/**
* Ctor.
* @param src Source iterable
*/
public Immutable(final Iterable<X> src) {
this(new CollectionOf<>(src));
}

/**
* Ctor.
* @param src Source collection
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/cactoos/collection/Reversed.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.LinkedList;
import java.util.List;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.Unchecked;

/**
* Reversed collection.
Expand Down Expand Up @@ -54,16 +55,16 @@ public Reversed(final X... src) {
*/
public Reversed(final Iterable<X> src) {
super(
new Sticky<>(
new CollectionOf<>(
new Unchecked<>(
new org.cactoos.scalar.Sticky<>(
() -> {
final List<X> items = new LinkedList<>();
src.forEach(items::add);
Collections.reverse(items);
return items;
}
)
)
).value()
);
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/cactoos/collection/Shuffled.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.Unchecked;

/**
* Shuffled collection.
Expand All @@ -43,7 +45,7 @@ public final class Shuffled<T> extends CollectionEnvelope<T> {
*/
@SafeVarargs
public Shuffled(final T... src) {
this(new CollectionOf<>(src));
this(new IterableOf<T>(src));
}

/**
Expand All @@ -52,16 +54,16 @@ public Shuffled(final T... src) {
*/
public Shuffled(final Iterable<T> src) {
super(
new Sticky<>(
new CollectionOf<>(
new Unchecked<>(
new org.cactoos.scalar.Sticky<>(
() -> {
final List<T> items = new LinkedList<>();
src.forEach(items::add);
Collections.shuffle(items);
return items;
}
)
)
).value()
);
}

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/org/cactoos/collection/Solid.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
package org.cactoos.collection;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.Unchecked;

/**
* A {@link Collection} that is both synchronized and sticky.
Expand Down Expand Up @@ -52,11 +56,18 @@ public Solid(final T... array) {
*/
public Solid(final Iterable<T> src) {
super(
new CollectionOf<>(
new Unchecked<>(
new org.cactoos.scalar.Solid<>(
() -> new Synced<>(new Sticky<>(src))
new org.cactoos.scalar.Sticky<>(
() -> {
final List<T> items = new LinkedList<>();
src.forEach(items::add);
Collections.shuffle(items);
return items;
}
)
)
)
).value()
);
}

Expand Down
15 changes: 7 additions & 8 deletions src/main/java/org/cactoos/collection/Sorted.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import org.cactoos.iterable.IterableOf;
import org.cactoos.list.ListOf;
import org.cactoos.scalar.Unchecked;

/**
* Sorted collection.
Expand Down Expand Up @@ -58,10 +60,7 @@ public Sorted(final T... src) {
*/
@SuppressWarnings("unchecked")
public Sorted(final Iterable<T> src) {
this(
(Comparator<T>) Comparator.naturalOrder(),
new CollectionOf<>(src)
);
this((Comparator<T>) Comparator.naturalOrder(), src);
}

/**
Expand All @@ -71,7 +70,7 @@ public Sorted(final Iterable<T> src) {
*/
@SafeVarargs
public Sorted(final Comparator<T> cmp, final T... src) {
this(cmp, new CollectionOf<>(src));
this(cmp, new IterableOf<T>(src));
}

/**
Expand All @@ -81,16 +80,16 @@ public Sorted(final Comparator<T> cmp, final T... src) {
*/
public Sorted(final Comparator<T> cmp, final Iterable<T> src) {
super(
new Sticky<>(
new CollectionOf<>(
new Unchecked<>(
new org.cactoos.scalar.Sticky<>(
() -> {
final List<T> items = new LinkedList<>();
src.forEach(items::add);
items.sort(cmp);
return items;
}
)
)
).value()
);
}
}
5 changes: 3 additions & 2 deletions src/main/java/org/cactoos/collection/Sticky.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collection;
import java.util.LinkedList;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.Unchecked;

/**
* Collection decorator that goes through the list only once.
Expand All @@ -52,15 +53,15 @@ public Sticky(final E... src) {
*/
public Sticky(final Iterable<E> src) {
super(
new CollectionOf<>(
new Unchecked<>(
new org.cactoos.scalar.Sticky<>(
() -> {
final Collection<E> temp = new LinkedList<>();
src.forEach(temp::add);
return temp;
}
)
)
).value()
);
}
}
13 changes: 3 additions & 10 deletions src/main/java/org/cactoos/collection/Synced.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.LinkedList;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.Unchecked;

/**
* Iterable as {@link Collection}.
Expand Down Expand Up @@ -60,24 +61,16 @@ public Synced(final T... array) {
* @param src An {@link Iterable}
*/
public Synced(final Iterable<T> src) {
this(new CollectionOf<>(src));
}

/**
* Ctor.
* @param src An {@link Iterable}
*/
public Synced(final Collection<T> src) {
super(
new CollectionOf<>(
new Unchecked<>(
new org.cactoos.scalar.Synced<>(
() -> {
final Collection<T> temp = new LinkedList<>();
src.forEach(temp::add);
return Collections.synchronizedCollection(temp);
}
)
)
).value()
);
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/cactoos/iterator/TailOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@

import java.util.Iterator;
import java.util.LinkedList;
import org.cactoos.collection.CollectionOf;
import org.cactoos.iterable.IterableOf;
import org.cactoos.list.ListOf;

/**
* Tail portion of the iterator.
*
* <p>There is no thread-safety guarantee.</p>
* @param <T> Element type
* @since 0.31
* @todo #947:30min Reimplement the implementation using
* {@link org.cactoos.iterable.Reversed} decorator. Do not use concrete classes
* as {@link LinkedList} here, as it is already used in
* {@link org.cactoos.iterable.Reversed} decorator.
*/
public final class TailOf<T> implements Iterator<T> {

Expand All @@ -49,12 +53,12 @@ public final class TailOf<T> implements Iterator<T> {
*/
public TailOf(final int num, final Iterator<T> iterator) {
this.origin = new LinkedList<>(
new CollectionOf<>(
new ListOf<>(
new IterableOf<>(
new HeadOf<>(
num,
new LinkedList<>(
new CollectionOf<>(new IterableOf<>(iterator))
new ListOf<>(new IterableOf<>(iterator))
).descendingIterator()
)
)
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/org/cactoos/list/Immutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
package org.cactoos.list;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.cactoos.Scalar;
import org.cactoos.collection.CollectionOf;
import org.cactoos.iterable.IterableOf;
import org.cactoos.scalar.And;
import org.cactoos.scalar.Folded;
import org.cactoos.scalar.Or;
Expand Down Expand Up @@ -71,35 +70,31 @@ public final class Immutable<T> implements List<T> {
*/
@SafeVarargs
public Immutable(final T... items) {
this(new CollectionOf<T>(items));
this(new IterableOf<T>(items));
}

/**
* Ctor.
* @param src Source list
*/
public Immutable(final List<T> src) {
this(new CollectionOf<>(src));
this(() -> new ListOf<>(src));
}

/**
* Ctor.
* @param src Source iterable
*/
public Immutable(final Iterable<T> src) {
this(new CollectionOf<T>(src));
this(() -> new ListOf<>(src));
}

/**
* Ctor.
* @param src Source collection
*/
public Immutable(final Collection<T> src) {
this(() -> {
final List<T> copy = new ArrayList<>(src.size());
copy.addAll(src);
return copy;
});
this(() -> new ListOf<>(src));
}

/**
Expand Down
Loading

2 comments on commit 542dc57

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 542dc57 Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1116-ec0ce41a discovered in src/main/java/org/cactoos/collection/CollectionOf.java and submitted as #1261. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 542dc57 Dec 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 947-c9c78905 discovered in src/main/java/org/cactoos/iterator/TailOf.java and submitted as #1262. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.