Skip to content

Commit

Permalink
#198 removed the offset parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciofx committed Jan 26, 2018
1 parent 8ffc394 commit e5e425d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 73 deletions.
41 changes: 5 additions & 36 deletions src/main/java/org/cactoos/text/AbbreviatedText.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public final class AbbreviatedText implements Text {
*/
private final Text origin;

/**
* The position where to start.
*/
private final int offset;

/**
* The max width of the resulting string.
*/
Expand All @@ -66,7 +61,7 @@ public AbbreviatedText(final String text) {
*/
public AbbreviatedText(final Text text) {
// @checkstyle MagicNumber (1 line)
this(text, 0, 80);
this(text, 80);
}

/**
Expand All @@ -75,7 +70,7 @@ public AbbreviatedText(final Text text) {
* @param max Max width of the result string
*/
public AbbreviatedText(final String text, final int max) {
this(text, 0, max);
this(new TextOf(text), max);
}

/**
Expand All @@ -84,49 +79,23 @@ public AbbreviatedText(final String text, final int max) {
* @param max Max width of the result string
*/
public AbbreviatedText(final Text text, final int max) {
// @checkstyle MagicNumber (1 line)
this(text, 0, max);
}

/**
* Ctor.
* @param text A String
* @param off Position where to start
* @param max Max width of the result string
*/
public AbbreviatedText(final String text, final int off, final int max) {
this(new TextOf(text), off, max);
}

/**
* Ctor.
* @param text The Text
* @param off Position where to start
* @param max Max width of result string
*/
public AbbreviatedText(final Text text, final int off, final int max) {
this.origin = text;
this.offset = off;
this.width = max;
}

@Override
public String asString() throws IOException {
final Text abbreviated;
if (this.origin.asString().length() <= this.width) {
abbreviated = new SubText(
this.origin,
this.offset,
this.origin.asString().length()
);
abbreviated = this.origin;
} else {
abbreviated = new FormattedText(
"%s...",
new SubText(
this.origin,
this.offset,
0,
// @checkstyle MagicNumber (1 line)
this.offset + this.width - 3
this.width - 3
).asString()
);
}
Expand Down
37 changes: 0 additions & 37 deletions src/test/java/org/cactoos/text/AbbreviatedTextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,6 @@ public void abbreviatesTextWithWidthBiggerThanLength() {
);
}

@Test
public void abbreviatesTextWithOffsetAndWidthSmaller() {
MatcherAssert.assertThat(
"Can't abbreviate a text with offset and width smaller",
// @checkstyle MagicNumber (1 line)
new AbbreviatedText("it's a beautiful day", 2, 17),
new TextHasString("'s a beautiful...")
);
}

@Test
public void abbreviatesTextWithOffsetAndWidthBigger() {
MatcherAssert.assertThat(
"Can't abbreviate a text with offset and width bigger",
// @checkstyle MagicNumber (1 line)
new AbbreviatedText("game of thrones", 2, 50),
new TextHasString("me of thrones")
);
}

@Test
public void abbreviatesTextBiggerThanDefaultMaxWidth() {
// @checkstyle LineLengthCheck (10 line)
Expand All @@ -146,21 +126,4 @@ public void abbreviatesTextBiggerThanDefaultMaxWidth() {
);
}

@Test
public void abbreviatesTextWithOffsetAndBiggerThanDefaultMaxWidth() {
// @checkstyle LineLengthCheck (10 line)
MatcherAssert.assertThat(
"Can't abbreviate a text with offset and bigger than default max width",
new AbbreviatedText(
"I tried making beer in the bathtub, I tried making synthetic gin, I tried making fudge for a living",
2,
// @checkstyle MagicNumberCheck (1 line)
80
),
new TextHasString(
"tried making beer in the bathtub, I tried making synthetic gin, I tried makin..."
)
);
}

}

0 comments on commit e5e425d

Please sign in to comment.