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 29, 2020
2 parents 019f965 + 807ab3f commit 8adeb28
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 80 deletions.
12 changes: 1 addition & 11 deletions src/main/java/org/cactoos/iterable/Repeated.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.cactoos.iterable;

import org.cactoos.Scalar;
import org.cactoos.scalar.Unchecked;

/**
* Repeat an element.
Expand All @@ -51,18 +50,9 @@ public Repeated(final int total, final T elm) {
* @param elm The element to repeat
*/
public Repeated(final int total, final Scalar<T> elm) {
this(total, new Unchecked<T>(elm));
}

/**
* Ctor.
* @param total The total number of repetitions
* @param item The element to repeat
*/
public Repeated(final int total, final Unchecked<T> item) {
super(
new IterableOf<>(
() -> new org.cactoos.iterator.Repeated<>(total, item)
() -> new org.cactoos.iterator.Repeated<>(total, elm)
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/iterator/Repeated.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Repeated(final int max, final Scalar<T> scalar) {
* @param max How many times to repeat
* @param scalar Scalar to repeat
*/
public Repeated(final int max, final Unchecked<T> scalar) {
private Repeated(final int max, final Unchecked<T> scalar) {
this.elm = scalar;
this.repeat = max;
}
Expand Down
28 changes: 8 additions & 20 deletions src/main/java/org/cactoos/scalar/AvgOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@

import java.math.BigDecimal;
import java.math.MathContext;
import java.util.List;
import org.cactoos.Scalar;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.list.ListOf;

/**
* Average of numbers.
Expand All @@ -50,16 +52,7 @@
* <p>There is no thread-safety guarantee.
*
* @since 0.24
* @checkstyle ExecutableStatementCountCheck (500 lines)
* @checkstyle NPathComplexityCheck (500 lines)
*/
@SuppressWarnings(
{
"PMD.CallSuperInConstructor",
"PMD.OnlyOneConstructorShouldDoInitialization",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"
}
)
public final class AvgOf extends NumberEnvelope {

/**
Expand Down Expand Up @@ -136,22 +129,17 @@ public AvgOf(final Scalar<Number>... src) {
public AvgOf(final Iterable<Scalar<Number>> src) {
super(
new Ternary<>(
new LengthOf(src),
(Double len) -> len > 0,
len -> new Folded<BigDecimal, BigDecimal>(
new ScalarOf<>(() -> new ListOf<>(new Mapped<Number>(Scalar::value, src))),
(List<Number> list) -> !list.isEmpty(),
list -> new Folded<BigDecimal, BigDecimal>(
BigDecimal.ZERO,
(sum, value) -> sum.add(value, MathContext.DECIMAL128),
new Mapped<>(
number -> BigDecimal.valueOf(
number.value().doubleValue()
),
src
)
new Mapped<>(s -> new BigDecimal(s.doubleValue()), list)
).value().divide(
BigDecimal.valueOf(len),
BigDecimal.valueOf(list.size()),
MathContext.DECIMAL128
).doubleValue(),
len -> 0.0
list -> 0.0
)
);
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/cactoos/text/FormattedText.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,15 @@ public FormattedText(
final Collection<Object> args
) {
super(
new TextOf(
() -> {
final StringBuilder out = new StringBuilder(0);
new Mapped(
pattern -> {
final StringBuilder out = new StringBuilder(pattern.length());
try (Formatter fmt = new Formatter(out, locale)) {
fmt.format(
ptn.asString(),
args.toArray()
);
fmt.format(pattern, args.toArray());
}
return out.toString();
}
},
ptn
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/cactoos/text/Rotated.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ public final class Rotated extends TextEnvelope {
*/
public Rotated(final Text text, final int shift) {
super(
new TextOf(
() -> {
String origin = text.asString();
new Mapped(
origin -> {
final int length = origin.length();
if (length != 0 && shift != 0 && shift % length != 0) {
final StringBuilder builder = new StringBuilder(length);
Expand All @@ -55,7 +54,8 @@ public Rotated(final Text text, final int shift) {
).toString();
}
return origin;
}
},
text
)
);
}
Expand Down
45 changes: 9 additions & 36 deletions src/main/java/org/cactoos/text/Split.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.cactoos.iterable.IterableEnvelope;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.iterator.IteratorOf;

/**
* Split the Text.
Expand All @@ -44,10 +45,7 @@ public final class Split extends IterableEnvelope<Text> {
* @see String#split(String)
*/
public Split(final String text, final String rgx) {
this(
new UncheckedText(new TextOf(text)),
new UncheckedText(new TextOf(rgx))
);
this(new TextOf(text), new TextOf(rgx));
}

/**
Expand All @@ -59,11 +57,7 @@ public Split(final String text, final String rgx) {
* @see String#split(String, int)
*/
public Split(final String text, final String rgx, final int lmt) {
this(
new UncheckedText(new TextOf(text)),
new UncheckedText(new TextOf(rgx)),
lmt
);
this(new TextOf(text), new TextOf(rgx), lmt);
}

/**
Expand All @@ -73,7 +67,7 @@ public Split(final String text, final String rgx, final int lmt) {
* @see String#split(String)
*/
public Split(final String text, final Text rgx) {
this(new UncheckedText(text), new UncheckedText(rgx));
this(new TextOf(text), rgx);
}

/**
Expand All @@ -84,7 +78,7 @@ public Split(final String text, final Text rgx) {
* @see String#split(String, int)
*/
public Split(final String text, final Text rgx, final int lmt) {
this(new UncheckedText(text), new UncheckedText(rgx), lmt);
this(new TextOf(text), rgx, lmt);
}

/**
Expand All @@ -94,7 +88,7 @@ public Split(final String text, final Text rgx, final int lmt) {
* @see String#split(String)
*/
public Split(final Text text, final String rgx) {
this(new UncheckedText(text), new UncheckedText(rgx));
this(text, new TextOf(rgx));
}

/**
Expand All @@ -105,7 +99,7 @@ public Split(final Text text, final String rgx) {
* @see String#split(String, int)
*/
public Split(final Text text, final String rgx, final int lmt) {
this(new UncheckedText(text), new UncheckedText(rgx), lmt);
this(text, new TextOf(rgx), lmt);
}

/**
Expand All @@ -115,27 +109,6 @@ public Split(final Text text, final String rgx, final int lmt) {
* @see String#split(String)
*/
public Split(final Text text, final Text rgx) {
this(new UncheckedText(text), new UncheckedText(rgx));
}

/**
* Ctor.
* @param text The text
* @param rgx The regex
* @param lmt The limit
* @see String#split(String, int)
*/
public Split(final Text text, final Text rgx, final int lmt) {
this(new UncheckedText(text), new UncheckedText(rgx), lmt);
}

/**
* Ctor.
* @param text The text
* @param rgx The regex
* @see String#split(String)
*/
public Split(final UncheckedText text, final UncheckedText rgx) {
this(text, rgx, 0);
}

Expand All @@ -146,12 +119,12 @@ public Split(final UncheckedText text, final UncheckedText rgx) {
* @param lmt The limit
* @see String#split(String, int)
*/
public Split(final UncheckedText text, final UncheckedText rgx, final int lmt) {
public Split(final Text text, final Text rgx, final int lmt) {
super(
new Mapped<>(
TextOf::new,
new IterableOf<>(
text.asString().split(rgx.asString(), lmt)
() -> new IteratorOf<>(text.asString().split(rgx.asString(), lmt))
)
)
);
Expand Down

0 comments on commit 8adeb28

Please sign in to comment.