Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Apr 23, 2019
2 parents eb13135 + 50878cc commit d70339d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
56 changes: 22 additions & 34 deletions src/main/java/org/cactoos/text/Abbreviated.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.cactoos.text;

import org.cactoos.Scalar;
import org.cactoos.Text;

/**
Expand All @@ -31,11 +32,8 @@
* <p>There is no thread-safety guarantee.
*
* @since 0.29
* @todo #897:30min All classes implementing Text need to be refactored
* to extend TextEnvelope - asString() should be removed and implementation
* from TextEnvelope should be used.
*/
public final class Abbreviated implements Text {
public final class Abbreviated extends TextEnvelope {

/**
* The default max line width.
Expand All @@ -47,16 +45,6 @@ public final class Abbreviated implements Text {
*/
private static final int ELLIPSES_WIDTH = 3;

/**
* The origin Text.
*/
private final Text origin;

/**
* The max width of the resulting string.
*/
private final int width;

/**
* Ctor.
*
Expand Down Expand Up @@ -94,26 +82,26 @@ public Abbreviated(final String text, final int max) {
* @param text The Text
* @param max Max width of the result string
*/
@SuppressWarnings({
"PMD.CallSuperInConstructor",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"
})
public Abbreviated(final Text text, final int max) {
this.origin = text;
this.width = max;
}

@Override
public String asString() throws Exception {
final Text abbreviated;
if (this.origin.asString().length() <= this.width) {
abbreviated = this.origin;
} else {
abbreviated = new FormattedText(
"%s...",
new Sub(
this.origin,
0,
this.width - Abbreviated.ELLIPSES_WIDTH
).asString()
);
}
return abbreviated.asString();
super((Scalar<String>) () -> {
final Text abbreviated;
if (text.asString().length() <= max) {
abbreviated = text;
} else {
abbreviated = new FormattedText(
"%s...",
new Sub(
text,
0,
max - Abbreviated.ELLIPSES_WIDTH
).asString()
);
}
return abbreviated.asString();
});
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/cactoos/text/FormattedText.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
* <p>There is no thread-safety guarantee.
*
* @since 0.1
* @todo #1063:30min All classes implementing Text need to be refactored
* to extend TextEnvelope - asString() should be removed and implementation
* from TextEnvelope should be used. This to-do should be moved to another
* class which need to be refactored.
*/
public final class FormattedText implements Text {

Expand Down

2 comments on commit d70339d

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on d70339d Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 897-f060f15b disappeared from src/main/java/org/cactoos/text/Abbreviated.java, that's why I closed #1063. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on d70339d Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1063-eb6fd66d discovered in src/main/java/org/cactoos/text/FormattedText.java and submitted as #1116. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.