Skip to content

Commit

Permalink
(yegor256#1579) Add ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Apr 7, 2021
1 parent 8b67ca5 commit ec63222
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/cactoos/text/PrefixOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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
)
)
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/org/cactoos/text/SuffixOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand All @@ -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("")
)
Expand Down

0 comments on commit ec63222

Please sign in to comment.