Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 9, 2018
2 parents 050dd73 + 494523f commit 504649d
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 115 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/cactoos/text/Base64Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

/**
* Decodes the origin text using the Base64 encoding scheme.
*
* @since 0.20.2
* @todo #897:30min Continue refactoring all classes implementing Text to extend
* TextEnvelope - asString() should be removed and implementation from
* TextEnvelope should be used.
*/
public final class Base64Text implements Text {

Expand Down Expand Up @@ -66,5 +68,4 @@ public String asString() throws Exception {
)
).asString();
}

}
4 changes: 0 additions & 4 deletions src/main/java/org/cactoos/text/JoinedText.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
* <p>There is no thread-safety guarantee.
*
* @since 0.9
* @todo #878:30min Continue refactoring all classes implementing Text to extend
* TextEnvelope - in most cases asString should be removed and implementation
* from TextEnvelope should be used.
*/
public final class JoinedText extends TextEnvelope {

Expand Down Expand Up @@ -86,5 +83,4 @@ public JoinedText(final Text delimit, final Iterable<Text> txts) {
return joint.toString();
});
}

}
25 changes: 9 additions & 16 deletions src/main/java/org/cactoos/time/DateAsText.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import org.cactoos.Text;
import org.cactoos.Scalar;
import org.cactoos.text.TextEnvelope;

/**
* Formatter for {@link Date} instances.
* @since 0.27
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class DateAsText implements Text {

/**
* Internal text carrying the formatted date.
*/
private final ZonedDateTimeAsText text;
public final class DateAsText extends TextEnvelope {

/**
* Formats current time using the ISO format.
Expand Down Expand Up @@ -124,16 +120,13 @@ public DateAsText(final Date date, final String format,
* @param formatter The formatter to use.
*/
public DateAsText(final Date date, final DateTimeFormatter formatter) {
this.text = new ZonedDateTimeAsText(
ZonedDateTime.ofInstant(date.toInstant(), ZoneId.of("UTC")),
super((Scalar<String>) () -> new ZonedDateTimeAsText(
ZonedDateTime.ofInstant(
date.toInstant(),
ZoneId.of("UTC")
),
formatter
);
).asString());
}

@Override
public String asString() {
return this.text.asString();
}

}

25 changes: 6 additions & 19 deletions src/main/java/org/cactoos/time/LocalDateAsText.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,15 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.cactoos.Text;
import org.cactoos.scalar.UncheckedScalar;
import org.cactoos.Scalar;
import org.cactoos.text.TextEnvelope;

/**
* Formatter for {@link java.time.LocalDate} instances.
* @since 0.27
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class LocalDateAsText implements Text {

/**
* Scalar carrying the formatted date.
*/
private final UncheckedScalar<String> formatted;
public final class LocalDateAsText extends TextEnvelope {

/**
* Formats date using ISO date time format.
Expand Down Expand Up @@ -80,16 +75,8 @@ public LocalDateAsText(final LocalDate date, final String format,
*/
public LocalDateAsText(final LocalDate date,
final DateTimeFormatter formatter) {
this.formatted = new UncheckedScalar<>(
() -> formatter.format(
ZonedDateTime.of(date, LocalTime.MIN, ZoneId.systemDefault())
)
);
super((Scalar<String>) () -> formatter.format(
ZonedDateTime.of(date, LocalTime.MIN, ZoneId.systemDefault())
));
}

@Override
public String asString() {
return this.formatted.value();
}

}
22 changes: 6 additions & 16 deletions src/main/java/org/cactoos/time/LocalDateTimeAsText.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.cactoos.Text;
import org.cactoos.scalar.UncheckedScalar;
import org.cactoos.Scalar;
import org.cactoos.text.TextEnvelope;

/**
* Formatter for {@link java.time.LocalDateTime} instances.
* @since 0.27
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class LocalDateTimeAsText implements Text {

/**
* Scalar carrying the formatted date.
*/
private final UncheckedScalar<String> formatted;
public final class LocalDateTimeAsText extends TextEnvelope {

/**
* Formats date using ISO date time format.
Expand Down Expand Up @@ -78,14 +73,9 @@ public LocalDateTimeAsText(final LocalDateTime date, final String format,
*/
public LocalDateTimeAsText(final LocalDateTime date,
final DateTimeFormatter formatter) {
this.formatted = new UncheckedScalar<>(
() -> formatter.format(date.atZone(ZoneId.systemDefault()))
super((Scalar<String>) () -> formatter.format(
date.atZone(ZoneId.systemDefault())
)
);
}

@Override
public String asString() {
return this.formatted.value();
}

}
21 changes: 4 additions & 17 deletions src/main/java/org/cactoos/time/OffsetDateTimeAsText.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,15 @@
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.cactoos.Text;
import org.cactoos.scalar.UncheckedScalar;
import org.cactoos.Scalar;
import org.cactoos.text.TextEnvelope;

/**
* Formatter for {@link java.time.OffsetDateTime} instances.
* @since 0.27
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class OffsetDateTimeAsText implements Text {

/**
* Scalar carrying the formatted date.
*/
private final UncheckedScalar<String> formatted;
public final class OffsetDateTimeAsText extends TextEnvelope {

/**
* Formats date using ISO date time format.
Expand Down Expand Up @@ -78,14 +73,6 @@ public OffsetDateTimeAsText(final OffsetDateTime date, final String format,
*/
public OffsetDateTimeAsText(final OffsetDateTime date,
final DateTimeFormatter formatter) {
this.formatted = new UncheckedScalar<>(
() -> formatter.format(date)
);
super((Scalar<String>) () -> formatter.format(date));
}

@Override
public String asString() {
return this.formatted.value();
}

}
21 changes: 4 additions & 17 deletions src/main/java/org/cactoos/time/ZonedDateTimeAsText.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,15 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.cactoos.Text;
import org.cactoos.scalar.UncheckedScalar;
import org.cactoos.Scalar;
import org.cactoos.text.TextEnvelope;

/**
* Formatter for {@link java.time.ZonedDateTime} instances.
* @since 0.27
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class ZonedDateTimeAsText implements Text {

/**
* Scalar carrying the formatted date.
*/
private final UncheckedScalar<String> formatted;
public final class ZonedDateTimeAsText extends TextEnvelope {

/**
* Formats date using ISO date time format.
Expand Down Expand Up @@ -77,14 +72,6 @@ public ZonedDateTimeAsText(final ZonedDateTime date, final String format,
*/
public ZonedDateTimeAsText(final ZonedDateTime date,
final DateTimeFormatter formatter) {
this.formatted = new UncheckedScalar<>(
() -> formatter.format(date)
);
super((Scalar<String>) () -> formatter.format(date));
}

@Override
public String asString() {
return this.formatted.value();
}

}
17 changes: 10 additions & 7 deletions src/test/java/org/cactoos/time/DateAsTextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.cactoos.time;

import java.io.IOException;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
Expand All @@ -40,7 +41,7 @@
public final class DateAsTextTest {

@Test
public void formatsCurrentTime() {
public void formatsCurrentTime() throws IOException {
MatcherAssert.assertThat(
"Can't format current time",
new DateAsText().asString(),
Expand All @@ -49,7 +50,7 @@ public void formatsCurrentTime() {
}

@Test
public void dateFormattedUsingIsoFormatter() {
public void dateFormattedUsingIsoFormatter() throws IOException {
final Calendar calendar =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2017, Calendar.DECEMBER, 13, 14, 15, 16);
Expand All @@ -62,7 +63,7 @@ public void dateFormattedUsingIsoFormatter() {
}

@Test
public void dateFormattedUsingCustomFormat() {
public void dateFormattedUsingCustomFormat() throws IOException {
final Calendar calendar =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2017, Calendar.DECEMBER, 13, 14, 15, 16);
Expand All @@ -76,7 +77,8 @@ public void dateFormattedUsingCustomFormat() {
}

@Test
public void dateFormattedUsingCustomFormatDifferentLocale() {
public void dateFormattedUsingCustomFormatDifferentLocale()
throws IOException {
final Calendar calendar =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2017, Calendar.DECEMBER, 13, 14, 15, 16);
Expand All @@ -90,7 +92,7 @@ public void dateFormattedUsingCustomFormatDifferentLocale() {
}

@Test
public void millisFormattedUsingIsoFormatter() {
public void millisFormattedUsingIsoFormatter() throws IOException {
final Calendar calendar =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2017, Calendar.DECEMBER, 13, 14, 15, 16);
Expand All @@ -103,7 +105,7 @@ public void millisFormattedUsingIsoFormatter() {
}

@Test
public void millisFormattedUsingCustomFormat() {
public void millisFormattedUsingCustomFormat() throws IOException {
final Calendar calendar =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2017, Calendar.DECEMBER, 13, 14, 15, 16);
Expand All @@ -118,7 +120,8 @@ public void millisFormattedUsingCustomFormat() {
}

@Test
public void millisFormattedUsingCustomFormatDifferentLocale() {
public void millisFormattedUsingCustomFormatDifferentLocale()
throws IOException {
final Calendar calendar =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(2017, Calendar.DECEMBER, 13, 14, 15, 16);
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/org/cactoos/time/LocalDateAsTextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.cactoos.time;

import java.io.IOException;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.time.LocalTime;
Expand All @@ -42,7 +43,7 @@
public final class LocalDateAsTextTest {

@Test
public void localDateFormattedAsIsoDateTime() {
public void localDateFormattedAsIsoDateTime() throws IOException {
final LocalDate date = LocalDate.of(2017, 12, 13);
MatcherAssert.assertThat(
"Can't format a LocalDate with default/ISO format.",
Expand All @@ -58,7 +59,7 @@ public void localDateFormattedAsIsoDateTime() {
}

@Test
public void localDateFormattedWithFormatString() {
public void localDateFormattedWithFormatString() throws IOException {
final LocalDate date = LocalDate.of(2017, 12, 13);
MatcherAssert.assertThat(
"Can't format a LocalDate with format.",
Expand All @@ -68,7 +69,8 @@ public void localDateFormattedWithFormatString() {
}

@Test
public void localDateFormattedWithFormatStringWithLocale() {
public void localDateFormattedWithFormatStringWithLocale()
throws IOException {
final LocalDate date = LocalDate.of(2017, 12, 13);
MatcherAssert.assertThat(
"Can't format a LocalDate with format using locale.",
Expand All @@ -80,12 +82,11 @@ public void localDateFormattedWithFormatStringWithLocale() {
}

@Test
public void currentLocalDateAsText() {
public void currentLocalDateAsText() throws IOException {
MatcherAssert.assertThat(
"Can't format a LocalDate with ISO format.",
new LocalDateAsText(LocalDate.now()).asString(),
Matchers.notNullValue()
);
}

}
Loading

2 comments on commit 504649d

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 504649d Jul 9, 2018

Choose a reason for hiding this comment

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

Puzzle 878-f712c12a disappeared from src/main/java/org/cactoos/text/JoinedText.java, that's why I closed #897. 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 504649d Jul 9, 2018

Choose a reason for hiding this comment

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

Puzzle 897-9c9a3952 discovered in src/main/java/org/cactoos/text/Base64Text.java and submitted as #929. 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.