From 18556b4ffd1f6e3666b21fab595016148ae4f532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20No=C3=ABl?= Date: Sun, 27 Dec 2020 17:31:24 +0100 Subject: [PATCH] (#1462) Use Mapped when relevant --- src/main/java/org/cactoos/text/FormattedText.java | 14 ++++++-------- src/main/java/org/cactoos/text/Rotated.java | 8 ++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/cactoos/text/FormattedText.java b/src/main/java/org/cactoos/text/FormattedText.java index c866581f9a..293aa62448 100644 --- a/src/main/java/org/cactoos/text/FormattedText.java +++ b/src/main/java/org/cactoos/text/FormattedText.java @@ -136,17 +136,15 @@ public FormattedText( final Collection 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 ) ); } diff --git a/src/main/java/org/cactoos/text/Rotated.java b/src/main/java/org/cactoos/text/Rotated.java index 31448c0b1c..0cc853c4d3 100644 --- a/src/main/java/org/cactoos/text/Rotated.java +++ b/src/main/java/org/cactoos/text/Rotated.java @@ -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); @@ -55,7 +54,8 @@ public Rotated(final Text text, final int shift) { ).toString(); } return origin; - } + }, + text ) ); }