Skip to content

Commit

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

Expand All @@ -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
)
)
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/org/cactoos/text/SuffixOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
)
Expand Down

0 comments on commit ed23927

Please sign in to comment.