From a2652152d32cb55ce3465b61204b55955620b544 Mon Sep 17 00:00:00 2001 From: andreoss Date: Tue, 6 Apr 2021 23:29:32 -0400 Subject: [PATCH 1/6] (#1579) Accept CharSequence instead of String --- src/main/java/org/cactoos/text/TextOf.java | 2 +- src/main/java/org/cactoos/text/TextOfScalar.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/cactoos/text/TextOf.java b/src/main/java/org/cactoos/text/TextOf.java index 42ed8209c1..aca4a5378e 100644 --- a/src/main/java/org/cactoos/text/TextOf.java +++ b/src/main/java/org/cactoos/text/TextOf.java @@ -368,7 +368,7 @@ public TextOf(final InputStream input) { * * @param scalar The Scalar of String */ - public TextOf(final Scalar scalar) { + public TextOf(final Scalar scalar) { this(new TextOfScalar(scalar)); } diff --git a/src/main/java/org/cactoos/text/TextOfScalar.java b/src/main/java/org/cactoos/text/TextOfScalar.java index 42d9ed31c0..dfb99d8e1a 100644 --- a/src/main/java/org/cactoos/text/TextOfScalar.java +++ b/src/main/java/org/cactoos/text/TextOfScalar.java @@ -41,20 +41,20 @@ public final class TextOfScalar implements Text { /** * String value of the envelope. */ - private final Scalar origin; + private final Scalar origin; /** * Ctor. * * @param scalar The Scalar of String */ - public TextOfScalar(final Scalar scalar) { + public TextOfScalar(final Scalar scalar) { this.origin = scalar; } @Override public String asString() throws Exception { - return this.origin.value(); + return this.origin.value().toString(); } @Override From 8b67ca5eb826b5b3da05f7f29a447a95d787be9e Mon Sep 17 00:00:00 2001 From: andreoss Date: Tue, 6 Apr 2021 23:42:40 -0400 Subject: [PATCH 2/6] (#1579) Change type in ctors --- src/main/java/org/cactoos/text/Abbreviated.java | 2 +- src/main/java/org/cactoos/text/Base64Decoded.java | 2 +- src/main/java/org/cactoos/text/Base64Encoded.java | 2 +- src/main/java/org/cactoos/text/Capitalized.java | 2 +- src/main/java/org/cactoos/text/Concatenated.java | 2 +- src/main/java/org/cactoos/text/Contains.java | 4 ++-- src/main/java/org/cactoos/text/EndsWith.java | 2 +- src/main/java/org/cactoos/text/FormattedText.java | 4 ++-- src/main/java/org/cactoos/text/Joined.java | 4 ++-- src/main/java/org/cactoos/text/Lowered.java | 2 +- src/main/java/org/cactoos/text/Mapped.java | 2 +- src/main/java/org/cactoos/text/Normalized.java | 3 +-- src/main/java/org/cactoos/text/PrefixOf.java | 2 +- src/main/java/org/cactoos/text/Repeated.java | 2 +- src/main/java/org/cactoos/text/Split.java | 8 ++++---- src/main/java/org/cactoos/text/StartsWith.java | 2 +- src/main/java/org/cactoos/text/Sub.java | 4 ++-- src/main/java/org/cactoos/text/Upper.java | 2 +- 18 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/cactoos/text/Abbreviated.java b/src/main/java/org/cactoos/text/Abbreviated.java index 536b4a3f0e..1afa64ef39 100644 --- a/src/main/java/org/cactoos/text/Abbreviated.java +++ b/src/main/java/org/cactoos/text/Abbreviated.java @@ -55,7 +55,7 @@ public final class Abbreviated extends TextEnvelope { * * @param text The Text */ - public Abbreviated(final String text) { + public Abbreviated(final CharSequence text) { this(new TextOf(text)); } diff --git a/src/main/java/org/cactoos/text/Base64Decoded.java b/src/main/java/org/cactoos/text/Base64Decoded.java index 5f1f61f465..dccb90aadd 100644 --- a/src/main/java/org/cactoos/text/Base64Decoded.java +++ b/src/main/java/org/cactoos/text/Base64Decoded.java @@ -39,7 +39,7 @@ public final class Base64Decoded extends TextEnvelope { * * @param input The String */ - public Base64Decoded(final String input) { + public Base64Decoded(final CharSequence input) { this(new TextOf(input)); } diff --git a/src/main/java/org/cactoos/text/Base64Encoded.java b/src/main/java/org/cactoos/text/Base64Encoded.java index 05852b6d36..0b558fa009 100644 --- a/src/main/java/org/cactoos/text/Base64Encoded.java +++ b/src/main/java/org/cactoos/text/Base64Encoded.java @@ -40,7 +40,7 @@ public final class Base64Encoded extends TextEnvelope { * * @param input The String */ - public Base64Encoded(final String input) { + public Base64Encoded(final CharSequence input) { this(new TextOf(input)); } diff --git a/src/main/java/org/cactoos/text/Capitalized.java b/src/main/java/org/cactoos/text/Capitalized.java index 00042e8326..dcadd6cf63 100644 --- a/src/main/java/org/cactoos/text/Capitalized.java +++ b/src/main/java/org/cactoos/text/Capitalized.java @@ -42,7 +42,7 @@ public final class Capitalized extends TextEnvelope { * * @param text The text */ - public Capitalized(final String text) { + public Capitalized(final CharSequence text) { this(new TextOf(text)); } diff --git a/src/main/java/org/cactoos/text/Concatenated.java b/src/main/java/org/cactoos/text/Concatenated.java index 562547d537..de3f70ff59 100644 --- a/src/main/java/org/cactoos/text/Concatenated.java +++ b/src/main/java/org/cactoos/text/Concatenated.java @@ -48,7 +48,7 @@ public Concatenated(final Text... txts) { * Ctor. * @param strs Strings to be concatenated */ - public Concatenated(final String... strs) { + public Concatenated(final CharSequence... strs) { this( new Mapped<>( TextOf::new, diff --git a/src/main/java/org/cactoos/text/Contains.java b/src/main/java/org/cactoos/text/Contains.java index 92a36a5bb3..a096a1f76b 100644 --- a/src/main/java/org/cactoos/text/Contains.java +++ b/src/main/java/org/cactoos/text/Contains.java @@ -48,7 +48,7 @@ public final class Contains implements Scalar { * @param origin The origin * @param other The other */ - public Contains(final String origin, final String other) { + public Contains(final CharSequence origin, final CharSequence other) { this(new TextOf(origin), new TextOf(other)); } @@ -57,7 +57,7 @@ public Contains(final String origin, final String other) { * @param origin The origin * @param other The other */ - public Contains(final String origin, final Text other) { + public Contains(final CharSequence origin, final Text other) { this(new TextOf(origin), other); } diff --git a/src/main/java/org/cactoos/text/EndsWith.java b/src/main/java/org/cactoos/text/EndsWith.java index a9da4705a9..1b3376c5be 100644 --- a/src/main/java/org/cactoos/text/EndsWith.java +++ b/src/main/java/org/cactoos/text/EndsWith.java @@ -48,7 +48,7 @@ public final class EndsWith implements Scalar { * @param origin The origin * @param suffix The suffix */ - public EndsWith(final Text origin, final String suffix) { + public EndsWith(final Text origin, final CharSequence suffix) { this(origin, new TextOf(suffix)); } diff --git a/src/main/java/org/cactoos/text/FormattedText.java b/src/main/java/org/cactoos/text/FormattedText.java index 293aa62448..64be149d5a 100644 --- a/src/main/java/org/cactoos/text/FormattedText.java +++ b/src/main/java/org/cactoos/text/FormattedText.java @@ -94,7 +94,7 @@ public FormattedText( * @param ptn Pattern * @param arguments Arguments */ - public FormattedText(final String ptn, final Collection arguments) { + public FormattedText(final CharSequence ptn, final Collection arguments) { this(ptn, Locale.getDefault(Locale.Category.FORMAT), arguments); } @@ -116,7 +116,7 @@ public FormattedText(final Text ptn, final Collection arguments) { * @param arguments Arguments */ public FormattedText( - final String ptn, + final CharSequence ptn, final Locale locale, final Collection arguments ) { diff --git a/src/main/java/org/cactoos/text/Joined.java b/src/main/java/org/cactoos/text/Joined.java index db97449818..0cebaca5ea 100644 --- a/src/main/java/org/cactoos/text/Joined.java +++ b/src/main/java/org/cactoos/text/Joined.java @@ -42,7 +42,7 @@ public final class Joined extends TextEnvelope { * @param delimit Delimit among strings * @param strs Strings to be joined */ - public Joined(final String delimit, final String... strs) { + public Joined(final CharSequence delimit, final CharSequence... strs) { this(delimit, new IterableOf<>(strs)); } @@ -51,7 +51,7 @@ public Joined(final String delimit, final String... strs) { * @param delimit Delimit among strings * @param strs Strings to be joined */ - public Joined(final String delimit, final Iterable strs) { + public Joined(final CharSequence delimit, final Iterable strs) { this( new TextOf(delimit), new Mapped<>(TextOf::new, strs) diff --git a/src/main/java/org/cactoos/text/Lowered.java b/src/main/java/org/cactoos/text/Lowered.java index 3042faa07b..47562a0fb8 100644 --- a/src/main/java/org/cactoos/text/Lowered.java +++ b/src/main/java/org/cactoos/text/Lowered.java @@ -39,7 +39,7 @@ public final class Lowered extends TextEnvelope { * Ctor. * @param text The text */ - public Lowered(final String text) { + public Lowered(final CharSequence text) { this(new TextOf(text)); } diff --git a/src/main/java/org/cactoos/text/Mapped.java b/src/main/java/org/cactoos/text/Mapped.java index 9dbfc71a21..f4064c167a 100644 --- a/src/main/java/org/cactoos/text/Mapped.java +++ b/src/main/java/org/cactoos/text/Mapped.java @@ -39,7 +39,7 @@ public final class Mapped extends TextEnvelope { * @param fnc Function to apply * @param txt Original text */ - public Mapped(final Func fnc, final Text txt) { + public Mapped(final Func fnc, final Text txt) { super(new TextOf(() -> fnc.apply(txt.asString()))); } diff --git a/src/main/java/org/cactoos/text/Normalized.java b/src/main/java/org/cactoos/text/Normalized.java index f86754ce8e..06c7fd484b 100644 --- a/src/main/java/org/cactoos/text/Normalized.java +++ b/src/main/java/org/cactoos/text/Normalized.java @@ -37,7 +37,7 @@ public final class Normalized extends TextEnvelope { * Ctor. * @param text A Text */ - public Normalized(final String text) { + public Normalized(final CharSequence text) { this(new TextOf(text)); } @@ -55,4 +55,3 @@ public Normalized(final Text text) { ); } } - diff --git a/src/main/java/org/cactoos/text/PrefixOf.java b/src/main/java/org/cactoos/text/PrefixOf.java index 33ed6e6c2b..dcff27b57a 100644 --- a/src/main/java/org/cactoos/text/PrefixOf.java +++ b/src/main/java/org/cactoos/text/PrefixOf.java @@ -43,7 +43,7 @@ public final class PrefixOf extends TextEnvelope { * @param text Text representing the text value * @param boundary String to which text will be split */ - public PrefixOf(final String text, final String boundary) { + public PrefixOf(final CharSequence text, final String boundary) { this(new TextOf(text), boundary); } diff --git a/src/main/java/org/cactoos/text/Repeated.java b/src/main/java/org/cactoos/text/Repeated.java index 515738c42c..2dec6e3ea1 100644 --- a/src/main/java/org/cactoos/text/Repeated.java +++ b/src/main/java/org/cactoos/text/Repeated.java @@ -39,7 +39,7 @@ public final class Repeated extends TextEnvelope { * @param text A String * @param count How many times repeat the Text */ - public Repeated(final String text, final int count) { + public Repeated(final CharSequence text, final int count) { this(new TextOf(text), count); } diff --git a/src/main/java/org/cactoos/text/Split.java b/src/main/java/org/cactoos/text/Split.java index 2ed80241ba..6a5637f075 100644 --- a/src/main/java/org/cactoos/text/Split.java +++ b/src/main/java/org/cactoos/text/Split.java @@ -44,7 +44,7 @@ public final class Split extends IterableEnvelope { * @param rgx The regex * @see String#split(String) */ - public Split(final String text, final String rgx) { + public Split(final CharSequence text, final CharSequence rgx) { this(new TextOf(text), new TextOf(rgx)); } @@ -56,7 +56,7 @@ public Split(final String text, final String rgx) { * @param lmt The limit * @see String#split(String, int) */ - public Split(final String text, final String rgx, final int lmt) { + public Split(final CharSequence text, final CharSequence rgx, final int lmt) { this(new TextOf(text), new TextOf(rgx), lmt); } @@ -66,7 +66,7 @@ public Split(final String text, final String rgx, final int lmt) { * @param rgx The regex * @see String#split(String) */ - public Split(final String text, final Text rgx) { + public Split(final CharSequence text, final Text rgx) { this(new TextOf(text), rgx); } @@ -87,7 +87,7 @@ public Split(final String text, final Text rgx, final int lmt) { * @param rgx The regex * @see String#split(String) */ - public Split(final Text text, final String rgx) { + public Split(final Text text, final CharSequence rgx) { this(text, new TextOf(rgx)); } diff --git a/src/main/java/org/cactoos/text/StartsWith.java b/src/main/java/org/cactoos/text/StartsWith.java index 4ed2022a80..822aaab884 100644 --- a/src/main/java/org/cactoos/text/StartsWith.java +++ b/src/main/java/org/cactoos/text/StartsWith.java @@ -62,7 +62,7 @@ public StartsWith(final Text text, final Text prefix) { * @param text The text * @param prefix The prefix */ - public StartsWith(final String text, final String prefix) { + public StartsWith(final CharSequence text, final CharSequence prefix) { this(new TextOf(text), new TextOf(prefix)); } diff --git a/src/main/java/org/cactoos/text/Sub.java b/src/main/java/org/cactoos/text/Sub.java index ae708aa25a..5683547e42 100644 --- a/src/main/java/org/cactoos/text/Sub.java +++ b/src/main/java/org/cactoos/text/Sub.java @@ -42,7 +42,7 @@ public final class Sub extends TextEnvelope { * @param text The String * @param strt Start position in the text */ - public Sub(final String text, final int strt) { + public Sub(final CharSequence text, final int strt) { this(new TextOf(text), strt); } @@ -52,7 +52,7 @@ public Sub(final String text, final int strt) { * @param strt Start position in the text * @param finish End position in the text */ - public Sub(final String text, final int strt, final int finish) { + public Sub(final CharSequence text, final int strt, final int finish) { this(new TextOf(text), strt, finish); } diff --git a/src/main/java/org/cactoos/text/Upper.java b/src/main/java/org/cactoos/text/Upper.java index 4615ae2740..5443d73c7b 100644 --- a/src/main/java/org/cactoos/text/Upper.java +++ b/src/main/java/org/cactoos/text/Upper.java @@ -40,7 +40,7 @@ public final class Upper extends TextEnvelope { * Ctor. * @param text The text */ - public Upper(final String text) { + public Upper(final CharSequence text) { this(new TextOf(text)); } From ec63222411bee7d02cc99635c9dab5a7c460682f Mon Sep 17 00:00:00 2001 From: andreoss Date: Tue, 6 Apr 2021 23:43:04 -0400 Subject: [PATCH 3/6] (#1579) Add ctors --- src/main/java/org/cactoos/text/PrefixOf.java | 17 +++++++++++++---- src/main/java/org/cactoos/text/SuffixOf.java | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/cactoos/text/PrefixOf.java b/src/main/java/org/cactoos/text/PrefixOf.java index dcff27b57a..8e3199cd8c 100644 --- a/src/main/java/org/cactoos/text/PrefixOf.java +++ b/src/main/java/org/cactoos/text/PrefixOf.java @@ -43,7 +43,7 @@ public final class PrefixOf extends TextEnvelope { * @param text Text representing the text value * @param boundary String to which text will be split */ - public PrefixOf(final CharSequence text, final String boundary) { + public PrefixOf(final CharSequence text, final CharSequence boundary) { this(new TextOf(text), boundary); } @@ -52,13 +52,22 @@ public PrefixOf(final CharSequence text, final String boundary) { * @param text Text representing the text value * @param boundary String to which text will be split */ - public PrefixOf(final Text text, final String boundary) { + public PrefixOf(final Text text, final CharSequence boundary) { + this(text, new TextOf(boundary)); + } + + /** + * Ctor. + * @param text Text representing the text value + * @param boundary String to which text will be split + */ + public PrefixOf(final Text text, final Text boundary) { super( new Flattened( new Ternary<>( new ScalarOf<>(() -> new Sticky(text)), - (Text t) -> t.asString().indexOf(boundary) >= 0, - t -> new Sub(t, 0, s -> s.indexOf(boundary)), + (Text t) -> t.asString().indexOf(boundary.asString()) >= 0, + t -> new Sub(t, 0, s -> s.indexOf(boundary.asString())), t -> t ) ) diff --git a/src/main/java/org/cactoos/text/SuffixOf.java b/src/main/java/org/cactoos/text/SuffixOf.java index 42acaec477..6ee56bde92 100644 --- a/src/main/java/org/cactoos/text/SuffixOf.java +++ b/src/main/java/org/cactoos/text/SuffixOf.java @@ -24,6 +24,7 @@ package org.cactoos.text; import org.cactoos.Text; +import org.cactoos.scalar.LengthOf; import org.cactoos.scalar.ScalarOf; import org.cactoos.scalar.Ternary; @@ -41,7 +42,7 @@ public final class SuffixOf extends TextEnvelope { * @param text Text representing the text value * @param boundary String after which text will be split */ - public SuffixOf(final String text, final String boundary) { + public SuffixOf(final CharSequence text, final CharSequence boundary) { this(new TextOf(text), boundary); } @@ -50,15 +51,23 @@ public SuffixOf(final String text, final String boundary) { * @param text Text representing the text value * @param boundary String after which text will be split */ - public SuffixOf(final Text text, final String boundary) { + public SuffixOf(final Text text, final CharSequence boundary) { + this(text, new TextOf(boundary)); + } + /** + * Ctor. + * @param text Text representing the text value + * @param boundary String after which text will be split + */ + public SuffixOf(final Text text, final Text boundary) { super( new Flattened( new Ternary<>( new ScalarOf<>(() -> new Sticky(text)), - (Text t) -> t.asString().indexOf(boundary) >= 0, + (Text t) -> t.asString().indexOf(boundary.asString()) >= 0, t -> new Sub( t, - s -> s.indexOf(boundary) + boundary.length() + s -> s.indexOf(boundary.asString()) + new LengthOf(boundary).value().intValue() ), t -> new TextOf("") ) From 725932604928ce545b614b4ab6509c1a5d4f3826 Mon Sep 17 00:00:00 2001 From: andreoss Date: Tue, 6 Apr 2021 23:59:15 -0400 Subject: [PATCH 4/6] (#1579) Qulice compliance --- src/main/java/org/cactoos/text/SuffixOf.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cactoos/text/SuffixOf.java b/src/main/java/org/cactoos/text/SuffixOf.java index 6ee56bde92..ce775838df 100644 --- a/src/main/java/org/cactoos/text/SuffixOf.java +++ b/src/main/java/org/cactoos/text/SuffixOf.java @@ -54,6 +54,7 @@ public SuffixOf(final CharSequence text, final CharSequence boundary) { public SuffixOf(final Text text, final CharSequence boundary) { this(text, new TextOf(boundary)); } + /** * Ctor. * @param text Text representing the text value @@ -67,7 +68,8 @@ public SuffixOf(final Text text, final Text boundary) { (Text t) -> t.asString().indexOf(boundary.asString()) >= 0, t -> new Sub( t, - s -> s.indexOf(boundary.asString()) + new LengthOf(boundary).value().intValue() + s -> s.indexOf(boundary.asString()) + + new LengthOf(boundary).value().intValue() ), t -> new TextOf("") ) From a19ec5072f2b3db9c6c15325101d9694aa0c49be Mon Sep 17 00:00:00 2001 From: andreoss Date: Thu, 15 Apr 2021 16:35:54 -0400 Subject: [PATCH 5/6] (#1579) Improve javadoc --- src/main/java/org/cactoos/text/Abbreviated.java | 2 +- src/main/java/org/cactoos/text/Base64Decoded.java | 2 +- src/main/java/org/cactoos/text/Base64Encoded.java | 2 +- src/main/java/org/cactoos/text/Concatenated.java | 2 +- src/main/java/org/cactoos/text/PrefixOf.java | 6 +++--- src/main/java/org/cactoos/text/TextOf.java | 12 ++++++------ src/main/java/org/cactoos/text/TextOfScalar.java | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/cactoos/text/Abbreviated.java b/src/main/java/org/cactoos/text/Abbreviated.java index 1afa64ef39..02f6997e18 100644 --- a/src/main/java/org/cactoos/text/Abbreviated.java +++ b/src/main/java/org/cactoos/text/Abbreviated.java @@ -53,7 +53,7 @@ public final class Abbreviated extends TextEnvelope { * *

By default, the max line width is 80 characters. * - * @param text The Text + * @param text The CharSequence */ public Abbreviated(final CharSequence text) { this(new TextOf(text)); diff --git a/src/main/java/org/cactoos/text/Base64Decoded.java b/src/main/java/org/cactoos/text/Base64Decoded.java index dccb90aadd..e34ed6c2a5 100644 --- a/src/main/java/org/cactoos/text/Base64Decoded.java +++ b/src/main/java/org/cactoos/text/Base64Decoded.java @@ -37,7 +37,7 @@ public final class Base64Decoded extends TextEnvelope { /** * Ctor. * - * @param input The String + * @param input The CharSequence */ public Base64Decoded(final CharSequence input) { this(new TextOf(input)); diff --git a/src/main/java/org/cactoos/text/Base64Encoded.java b/src/main/java/org/cactoos/text/Base64Encoded.java index 0b558fa009..84ac8741a3 100644 --- a/src/main/java/org/cactoos/text/Base64Encoded.java +++ b/src/main/java/org/cactoos/text/Base64Encoded.java @@ -38,7 +38,7 @@ public final class Base64Encoded extends TextEnvelope { /** * Ctor. * - * @param input The String + * @param input The CharSequence */ public Base64Encoded(final CharSequence input) { this(new TextOf(input)); diff --git a/src/main/java/org/cactoos/text/Concatenated.java b/src/main/java/org/cactoos/text/Concatenated.java index de3f70ff59..f0ceab96bd 100644 --- a/src/main/java/org/cactoos/text/Concatenated.java +++ b/src/main/java/org/cactoos/text/Concatenated.java @@ -46,7 +46,7 @@ public Concatenated(final Text... txts) { /** * Ctor. - * @param strs Strings to be concatenated + * @param strs CharSequences to be concatenated */ public Concatenated(final CharSequence... strs) { this( diff --git a/src/main/java/org/cactoos/text/PrefixOf.java b/src/main/java/org/cactoos/text/PrefixOf.java index 8e3199cd8c..99374d4cac 100644 --- a/src/main/java/org/cactoos/text/PrefixOf.java +++ b/src/main/java/org/cactoos/text/PrefixOf.java @@ -40,8 +40,8 @@ public final class PrefixOf extends TextEnvelope { /** * Ctor. - * @param text Text representing the text value - * @param boundary String to which text will be split + * @param text CharSequence representing the text value + * @param boundary CharSequence to which text will be split */ public PrefixOf(final CharSequence text, final CharSequence boundary) { this(new TextOf(text), boundary); @@ -50,7 +50,7 @@ public PrefixOf(final CharSequence text, final CharSequence boundary) { /** * Ctor. * @param text Text representing the text value - * @param boundary String to which text will be split + * @param boundary CharSequence to which text will be split */ public PrefixOf(final Text text, final CharSequence boundary) { this(text, new TextOf(boundary)); diff --git a/src/main/java/org/cactoos/text/TextOf.java b/src/main/java/org/cactoos/text/TextOf.java index aca4a5378e..4e1a528650 100644 --- a/src/main/java/org/cactoos/text/TextOf.java +++ b/src/main/java/org/cactoos/text/TextOf.java @@ -169,20 +169,20 @@ public TextOf(final Reader rdr, final int max, final Charset cset) { /** * Ctor. * - * @param builder The String builder + * @param str The CharSequence */ - public TextOf(final CharSequence builder) { - this(new BytesOf(builder)); + public TextOf(final CharSequence str) { + this(new BytesOf(str)); } /** * Ctor. * - * @param builder The String builder + * @param str The CharSequence * @param cset The Charset */ - public TextOf(final CharSequence builder, final Charset cset) { - this(new BytesOf(builder, cset), cset); + public TextOf(final CharSequence str, final Charset cset) { + this(new BytesOf(str, cset), cset); } /** diff --git a/src/main/java/org/cactoos/text/TextOfScalar.java b/src/main/java/org/cactoos/text/TextOfScalar.java index dfb99d8e1a..12a4a6e223 100644 --- a/src/main/java/org/cactoos/text/TextOfScalar.java +++ b/src/main/java/org/cactoos/text/TextOfScalar.java @@ -39,14 +39,14 @@ public final class TextOfScalar implements Text { /** - * String value of the envelope. + * Value of the envelope. */ private final Scalar origin; /** * Ctor. * - * @param scalar The Scalar of String + * @param scalar The scalar of CharSequence */ public TextOfScalar(final Scalar scalar) { this.origin = scalar; From ed23927c7525691b15bec16344ce6aec698b3bea Mon Sep 17 00:00:00 2001 From: andreoss Date: Mon, 19 Apr 2021 12:20:32 -0400 Subject: [PATCH 6/6] (#1579) Remove ctor --- src/main/java/org/cactoos/text/PrefixOf.java | 17 +++-------------- src/main/java/org/cactoos/text/SuffixOf.java | 15 +++------------ 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/cactoos/text/PrefixOf.java b/src/main/java/org/cactoos/text/PrefixOf.java index 99374d4cac..643dd2235f 100644 --- a/src/main/java/org/cactoos/text/PrefixOf.java +++ b/src/main/java/org/cactoos/text/PrefixOf.java @@ -24,8 +24,6 @@ package org.cactoos.text; import org.cactoos.Text; -import org.cactoos.func.FuncOf; -import org.cactoos.scalar.Constant; import org.cactoos.scalar.ScalarOf; import org.cactoos.scalar.Ternary; @@ -47,27 +45,18 @@ public PrefixOf(final CharSequence text, final CharSequence boundary) { this(new TextOf(text), boundary); } - /** - * Ctor. - * @param text Text representing the text value - * @param boundary CharSequence to which text will be split - */ - public PrefixOf(final Text text, final CharSequence boundary) { - this(text, new TextOf(boundary)); - } - /** * Ctor. * @param text Text representing the text value * @param boundary String to which text will be split */ - public PrefixOf(final Text text, final Text boundary) { + public PrefixOf(final Text text, final CharSequence boundary) { super( new Flattened( new Ternary<>( new ScalarOf<>(() -> new Sticky(text)), - (Text t) -> t.asString().indexOf(boundary.asString()) >= 0, - t -> new Sub(t, 0, s -> s.indexOf(boundary.asString())), + (Text t) -> t.asString().contains(boundary.toString()), + t -> new Sub(t, 0, s -> s.indexOf(boundary.toString())), t -> t ) ) diff --git a/src/main/java/org/cactoos/text/SuffixOf.java b/src/main/java/org/cactoos/text/SuffixOf.java index ce775838df..dae8954a30 100644 --- a/src/main/java/org/cactoos/text/SuffixOf.java +++ b/src/main/java/org/cactoos/text/SuffixOf.java @@ -52,24 +52,15 @@ public SuffixOf(final CharSequence text, final CharSequence boundary) { * @param boundary String after which text will be split */ public SuffixOf(final Text text, final CharSequence boundary) { - this(text, new TextOf(boundary)); - } - - /** - * Ctor. - * @param text Text representing the text value - * @param boundary String after which text will be split - */ - public SuffixOf(final Text text, final Text boundary) { super( new Flattened( new Ternary<>( new ScalarOf<>(() -> new Sticky(text)), - (Text t) -> t.asString().indexOf(boundary.asString()) >= 0, + (Text t) -> t.asString().contains(boundary.toString()), t -> new Sub( t, - s -> s.indexOf(boundary.asString()) - + new LengthOf(boundary).value().intValue() + s -> s.indexOf(boundary.toString()) + + boundary.length() ), t -> new TextOf("") )