Skip to content

Commit

Permalink
(yegor256#1591) MinOf/MaxOf rejects empty Iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
victornoel committed May 13, 2021
1 parent c9f64e1 commit ae13b5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
22 changes: 9 additions & 13 deletions src/main/java/org/cactoos/number/MaxOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.scalar.Folded;
import org.cactoos.scalar.Reduced;

/**
* Find the greater among items.
Expand Down Expand Up @@ -66,25 +66,21 @@ public MaxOf(final Number... src) {
public MaxOf(final Iterable<? extends Number> src) {
super(
new NumberOfScalars(
new Folded<>(
Long.MIN_VALUE,
new Reduced<Long>(
Math::max,
new Mapped<>(Number::longValue, src)
new Mapped<>((Number n) -> n::longValue, src)
),
new Folded<>(
Integer.MIN_VALUE,
new Reduced<Integer>(
Math::max,
new Mapped<>(Number::intValue, src)
new Mapped<>((Number n) -> n::intValue, src)
),
new Folded<>(
-Float.MAX_VALUE,
new Reduced<Float>(
Math::max,
new Mapped<>(Number::floatValue, src)
new Mapped<>((Number n) -> n::floatValue, src)
),
new Folded<>(
-Double.MAX_VALUE,
new Reduced<Double>(
Math::max,
new Mapped<>(Number::doubleValue, src)
new Mapped<>((Number n) -> n::doubleValue, src)
)
)
);
Expand Down
22 changes: 9 additions & 13 deletions src/main/java/org/cactoos/number/MinOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.scalar.Folded;
import org.cactoos.scalar.Reduced;

/**
* Find the smaller among items.
Expand Down Expand Up @@ -66,25 +66,21 @@ public MinOf(final Number... src) {
public MinOf(final Iterable<? extends Number> src) {
super(
new NumberOfScalars(
new Folded<>(
Long.MAX_VALUE,
new Reduced<Long>(
Math::min,
new Mapped<>(Number::longValue, src)
new Mapped<>((Number n) -> n::longValue, src)
),
new Folded<>(
Integer.MAX_VALUE,
new Reduced<Integer>(
Math::min,
new Mapped<>(Number::intValue, src)
new Mapped<>((Number n) -> n::intValue, src)
),
new Folded<>(
Float.MAX_VALUE,
new Reduced<Float>(
Math::min,
new Mapped<>(Number::floatValue, src)
new Mapped<>((Number n) -> n::floatValue, src)
),
new Folded<>(
Double.MAX_VALUE,
new Reduced<Double>(
Math::min,
new Mapped<>(Number::doubleValue, src)
new Mapped<>((Number n) -> n::doubleValue, src)
)
)
);
Expand Down

0 comments on commit ae13b5f

Please sign in to comment.