Skip to content

Commit

Permalink
(yegor256#1569) Generified first 9 by alphabetical order files in pac…
Browse files Browse the repository at this point in the history
…kage.
  • Loading branch information
rocket-3 committed Sep 25, 2021
1 parent 445cf16 commit 5bb4502
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 50 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/cactoos/scalar/And.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class And implements Scalar<Boolean> {
/**
* The iterator.
*/
private final Iterable<Scalar<Boolean>> origin;
private final Iterable<? extends Scalar<Boolean>> origin;

/**
* Ctor.
Expand All @@ -77,7 +77,7 @@ public final class And implements Scalar<Boolean> {
* @param <X> Type of items in the iterable
*/
@SafeVarargs
public <X> And(final Func<X, Boolean> func, final X... src) {
public <X> And(final Func<? super X, Boolean> func, final X... src) {
this(func, new IterableOf<>(src));
}

Expand All @@ -88,7 +88,10 @@ public <X> And(final Func<X, Boolean> func, final X... src) {
* @param <X> Type of items in the iterable
* @since 0.24
*/
public <X> And(final Func<X, Boolean> func, final Iterable<X> src) {
public <X> And(
final Func<? super X, Boolean> func,
final Iterable<? extends X> src
) {
this(
new Mapped<>(
item -> new ScalarOf<>(() -> func.apply(item)),
Expand All @@ -105,7 +108,7 @@ public <X> And(final Func<X, Boolean> func, final Iterable<X> src) {
* @since 0.34
*/
@SafeVarargs
public <X> And(final X subject, final Func<X, Boolean>... conditions) {
public <X> And(final X subject, final Func<? super X, Boolean>... conditions) {
this(subject, new IterableOf<>(conditions));
}

Expand All @@ -116,7 +119,7 @@ public <X> And(final X subject, final Func<X, Boolean>... conditions) {
* @param <X> Type of items in the iterable
* @since 0.49
*/
public <X> And(final X subject, final Iterable<Func<X, Boolean>> conditions) {
public <X> And(final X subject, final Iterable<? extends Func<? super X, Boolean>> conditions) {
this(
new Mapped<>(
item -> new ScalarOf<>(() -> item.apply(subject)),
Expand All @@ -138,7 +141,7 @@ public And(final Scalar<Boolean>... scalar) {
* Ctor.
* @param iterable The iterable.
*/
public And(final Iterable<Scalar<Boolean>> iterable) {
public And(final Iterable<? extends Scalar<Boolean>> iterable) {
this.origin = iterable;
}

Expand Down
42 changes: 27 additions & 15 deletions src/main/java/org/cactoos/scalar/AndInThreads.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public final class AndInThreads implements Scalar<Boolean> {
/**
* The iterator.
*/
private final Iterable<Scalar<Boolean>> iterable;
private final Iterable<? extends Scalar<Boolean>> iterable;

/**
* Shut down the service when it's done.
Expand All @@ -78,7 +78,7 @@ public final class AndInThreads implements Scalar<Boolean> {
* @param <X> Type of items in the iterable
*/
@SafeVarargs
public <X> AndInThreads(final Func<X, Boolean> func, final X... src) {
public <X> AndInThreads(final Func<? super X, Boolean> func, final X... src) {
this(func, new IterableOf<>(src));
}

Expand All @@ -88,8 +88,8 @@ public <X> AndInThreads(final Func<X, Boolean> func, final X... src) {
* @param src The iterable
* @param <X> Type of items in the iterable
*/
public <X> AndInThreads(final Func<X, Boolean> func,
final Iterable<X> src) {
public <X> AndInThreads(final Func<? super X, Boolean> func,
final Iterable<? extends X> src) {
this(
new Mapped<>(
item -> new ScalarOf<>(() -> func.apply(item)),
Expand All @@ -111,7 +111,7 @@ public AndInThreads(final Scalar<Boolean>... src) {
* Ctor.
* @param src The iterable
*/
public AndInThreads(final Iterable<Scalar<Boolean>> src) {
public AndInThreads(final Iterable<? extends Scalar<Boolean>> src) {
this(Executors.newCachedThreadPool(), src, true);
}

Expand All @@ -123,8 +123,11 @@ public AndInThreads(final Iterable<Scalar<Boolean>> src) {
* @param <X> Type of items in the iterable
*/
@SafeVarargs
public <X> AndInThreads(final ExecutorService svc,
final Proc<X> proc, final X... src) {
public <X> AndInThreads(
final ExecutorService svc,
final Proc<? super X> proc,
final X... src
) {
this(svc, new FuncOf<>(proc, true), src);
}

Expand All @@ -136,8 +139,11 @@ public <X> AndInThreads(final ExecutorService svc,
* @param <X> Type of items in the iterable
*/
@SafeVarargs
public <X> AndInThreads(final ExecutorService svc,
final Func<X, Boolean> func, final X... src) {
public <X> AndInThreads(
final ExecutorService svc,
final Func<? super X, Boolean> func,
final X... src
) {
this(svc, func, new IterableOf<>(src));
}

Expand All @@ -148,8 +154,11 @@ public <X> AndInThreads(final ExecutorService svc,
* @param src The iterable
* @param <X> Type of items in the iterable
*/
public <X> AndInThreads(final ExecutorService svc,
final Proc<X> proc, final Iterable<X> src) {
public <X> AndInThreads(
final ExecutorService svc,
final Proc<? super X> proc,
final Iterable<? extends X> src
) {
this(svc, new FuncOf<>(proc, true), src);
}

Expand All @@ -160,8 +169,11 @@ public <X> AndInThreads(final ExecutorService svc,
* @param src The iterable
* @param <X> Type of items in the iterable
*/
public <X> AndInThreads(final ExecutorService svc,
final Func<X, Boolean> func, final Iterable<X> src) {
public <X> AndInThreads(
final ExecutorService svc,
final Func<? super X, Boolean> func,
final Iterable<? extends X> src
) {
this(
svc,
new Mapped<>(
Expand All @@ -188,7 +200,7 @@ public AndInThreads(final ExecutorService svc,
* @param src The iterable
*/
public AndInThreads(final ExecutorService svc,
final Iterable<Scalar<Boolean>> src) {
final Iterable<? extends Scalar<Boolean>> src) {
this(svc, src, false);
}

Expand All @@ -199,7 +211,7 @@ public AndInThreads(final ExecutorService svc,
* @param sht Shut it down
*/
private AndInThreads(final ExecutorService svc,
final Iterable<Scalar<Boolean>> src, final boolean sht) {
final Iterable<? extends Scalar<Boolean>> src, final boolean sht) {
this.service = svc;
this.iterable = src;
this.shut = sht;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/cactoos/scalar/AndWithIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class AndWithIndex implements Scalar<Boolean> {
/**
* The iterator.
*/
private final Iterable<Func<Integer, Boolean>> iterable;
private final Iterable<? extends Func<Integer, Boolean>> iterable;

/**
* Ctor.
Expand All @@ -77,7 +77,7 @@ public final class AndWithIndex implements Scalar<Boolean> {
* @param <X> Type of items in the iterable
*/
@SafeVarargs
public <X> AndWithIndex(final Proc<X> proc, final X... src) {
public <X> AndWithIndex(final Proc<? super X> proc, final X... src) {
this(new BiFuncOf<>(proc, true), src);
}

Expand All @@ -88,7 +88,7 @@ public <X> AndWithIndex(final Proc<X> proc, final X... src) {
* @param <X> Type of items in the iterable
*/
@SafeVarargs
public <X> AndWithIndex(final BiFunc<X, Integer, Boolean> func,
public <X> AndWithIndex(final BiFunc<? super X, Integer, Boolean> func,
final X... src) {
this(func, new IterableOf<>(src));
}
Expand All @@ -100,8 +100,8 @@ public <X> AndWithIndex(final BiFunc<X, Integer, Boolean> func,
* @param <X> Type of items in the iterable
* @since 0.24
*/
public <X> AndWithIndex(final BiProc<X, Integer> proc,
final Iterable<X> src) {
public <X> AndWithIndex(final BiProc<? super X, Integer> proc,
final Iterable<? extends X> src) {
this(new BiFuncOf<>(proc, true), src);
}

Expand All @@ -112,8 +112,8 @@ public <X> AndWithIndex(final BiProc<X, Integer> proc,
* @param <X> Type of items in the iterable
* @since 0.24
*/
public <X> AndWithIndex(final BiFunc<X, Integer, Boolean> func,
final Iterable<X> src) {
public <X> AndWithIndex(final BiFunc<? super X, Integer, Boolean> func,
final Iterable<? extends X> src) {
this(
new Mapped<>(
item -> new FuncOf<>(input -> func.apply(item, input)),
Expand All @@ -135,7 +135,7 @@ public AndWithIndex(final Func<Integer, Boolean>... src) {
* Ctor.
* @param src The iterable
*/
public AndWithIndex(final Iterable<Func<Integer, Boolean>> src) {
public AndWithIndex(final Iterable<? extends Func<Integer, Boolean>> src) {
this.iterable = src;
}

Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/cactoos/scalar/FirstOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ public final class FirstOf<T> implements Scalar<T> {
/**
* Condition for getting the element.
*/
private final Func<T, Boolean> condition;
private final Func<? super T, Boolean> condition;

/**
* Source iterable.
*/
private final Iterable<T> source;
private final Iterable<? extends T> source;

/**
* Fallback used if no value matches.
*/
private final Scalar<T> fallback;
private final Scalar<? extends T> fallback;

/**
* Constructor with default condition (always `true`) and plain fallback.
* @param src Source iterable
* @param fbck Fallback used if no value matches
*/
public FirstOf(final Iterable<T> src, final T fbck) {
public FirstOf(final Iterable<? extends T> src, final T fbck) {
this(
new FuncOf<>(new True()),
src,
Expand All @@ -71,7 +71,7 @@ public FirstOf(final Iterable<T> src, final T fbck) {
* @param src Source iterable
* @param fbck Fallback used if no value matches
*/
public FirstOf(final Iterable<T> src, final Scalar<T> fbck) {
public FirstOf(final Iterable<? extends T> src, final Scalar<? extends T> fbck) {
this(
new FuncOf<>(new True()),
src,
Expand All @@ -85,8 +85,11 @@ public FirstOf(final Iterable<T> src, final Scalar<T> fbck) {
* @param src Source iterable
* @param fbck Fallback used if no value matches
*/
public FirstOf(final Func<T, Boolean> cond, final Iterable<T> src,
final Scalar<T> fbck) {
public FirstOf(
final Func<? super T, Boolean> cond,
final Iterable<? extends T> src,
final Scalar<? extends T> fbck
) {
this.condition = cond;
this.source = src;
this.fallback = fbck;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/scalar/IoChecked.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public final class IoChecked<T> implements Scalar<T> {
/**
* Original scalar.
*/
private final Scalar<T> origin;
private final Scalar<? extends T> origin;

/**
* Ctor.
* @param scalar Encapsulated scalar
*/
public IoChecked(final Scalar<T> scalar) {
public IoChecked(final Scalar<? extends T> scalar) {
this.origin = scalar;
}

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/cactoos/scalar/ItemAt.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.cactoos.Func;
import org.cactoos.Scalar;
import org.cactoos.func.FuncOf;
import org.cactoos.iterable.IterableOf;
import org.cactoos.text.FormattedText;

/**
Expand All @@ -53,7 +54,7 @@ public final class ItemAt<T> implements Scalar<T> {
* @param position Position
* @param iterable Iterable
*/
public ItemAt(final int position, final Iterable<T> iterable) {
public ItemAt(final int position, final Iterable<? extends T> iterable) {
this(
position,
itr -> {
Expand All @@ -78,7 +79,7 @@ public ItemAt(final int position, final Iterable<T> iterable) {
public ItemAt(
final int position,
final T fallback,
final Iterable<T> iterable
final Iterable<? extends T> iterable
) {
this(position, new FuncOf<>(new Constant<>(fallback)), iterable);
}
Expand All @@ -92,8 +93,8 @@ public ItemAt(
*/
public ItemAt(
final int position,
final Func<Iterable<T>, T> fallback,
final Iterable<T> iterable
final Func<? super Iterable<? super T>, ? extends T> fallback,
final Iterable<? extends T> iterable
) {
this.saved = new Sticky<T>(
() -> {
Expand All @@ -106,15 +107,15 @@ public ItemAt(
).asString()
);
}
final Iterator<T> src = iterable.iterator();
final Iterator<? extends T> src = iterable.iterator();
int cur;
for (cur = 0; cur < position && src.hasNext(); ++cur) {
src.next();
}
if (cur == position && src.hasNext()) {
ret = src.next();
} else {
ret = fallback.apply(() -> src);
ret = fallback.apply(new IterableOf<>(src));
}
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/scalar/NoNulls.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public final class NoNulls<T> implements Scalar<T> {
/**
* The scalar.
*/
private final Scalar<T> origin;
private final Scalar<? extends T> origin;

/**
* Ctor.
* @param sclr The scalar
*/
public NoNulls(final Scalar<T> sclr) {
public NoNulls(final Scalar<? extends T> sclr) {
this.origin = sclr;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/scalar/PropertiesOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public PropertiesOf(final Map.Entry<?, ?>... entries) {
* @param entries The map with properties
* @since 0.23
*/
public PropertiesOf(final Iterable<Map.Entry<?, ?>> entries) {
public PropertiesOf(final Iterable<? extends Map.Entry<?, ?>> entries) {
this(
new MapOf<>(
input -> new MapEntry<>(
Expand Down Expand Up @@ -131,7 +131,7 @@ public PropertiesOf(final Map<?, ?> map) {
* Ctor.
* @param sclr The underlying properties
*/
private PropertiesOf(final Scalar<Properties> sclr) {
private PropertiesOf(final Scalar<? extends Properties> sclr) {
this.scalar = new IoChecked<>(sclr);
}

Expand Down
Loading

0 comments on commit 5bb4502

Please sign in to comment.