Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/main/java/com/apptasticsoftware/rssreader/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,24 @@ public Optional<String> getPubDate() {
* Get the publication date for the content in the channel.
* @return publication date
*/
public Optional<ZonedDateTime> getPubDateZonedDateTime() {
public Optional<ZonedDateTime> getPubDateAsZonedDateTime() {
return getPubDate().map(dateTimeParser::parse);
}

/**
* Get the publication date for the content in the channel.
*
* @deprecated
* As of version 3.12.0, replaced by {@link Channel#getPubDateAsZonedDateTime()}
*
* @return publication date
*/
@SuppressWarnings("java:S1133")
@Deprecated(since = "3.12.0", forRemoval = true)
public Optional<ZonedDateTime> getPubDateZonedDateTime() {
return getPubDateAsZonedDateTime();
}

/**
* Set the publication date for the content in the channel.
* @param pubDate publication date
Expand All @@ -281,10 +295,24 @@ public Optional<String> getLastBuildDate() {
* Get the last time the content of the channel changed.
* @return last build date
*/
public Optional<ZonedDateTime> getLastBuildDateZonedDateTime() {
public Optional<ZonedDateTime> getLastBuildDateAsZonedDateTime() {
return getLastBuildDate().map(dateTimeParser::parse);
}

/**
* Get the last time the content of the channel changed.
*
* @deprecated
* As of version 3.12.0, replaced by {@link Channel#getLastBuildDateAsZonedDateTime()}
*
* @return last build date
*/
@SuppressWarnings("java:S1133")
@Deprecated(since = "3.12.0", forRemoval = true)
public Optional<ZonedDateTime> getLastBuildDateZonedDateTime() {
return getLastBuildDateAsZonedDateTime();
}

/**
* Set the last time the content of the channel changed.
* @param lastBuildDate last build date
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/com/apptasticsoftware/rssreader/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,24 @@ public void setPubDate(String pubDate) {
*
* @return publication date
*/
public Optional<ZonedDateTime> getPubDateZonedDateTime() {
public Optional<ZonedDateTime> getPubDateAsZonedDateTime() {
return getPubDate().map(dateTimeParser::parse);
}

/**
* Get a ZonedDateTime that indicates when the item was published.
*
* @deprecated
* As of version 3.12.0, replaced by {@link Item#getPubDateAsZonedDateTime()}
*
* @return publication date
*/
@SuppressWarnings("java:S1133")
@Deprecated(since = "3.12.0", forRemoval = true)
public Optional<ZonedDateTime> getPubDateZonedDateTime() {
return getPubDateAsZonedDateTime();
}

/**
* Get a string that indicates when the item was updated.
*
Expand All @@ -307,10 +321,24 @@ public void setUpdated(String updated) {
*
* @return publication date
*/
public Optional<ZonedDateTime> getUpdatedZonedDateTime() {
public Optional<ZonedDateTime> getUpdatedAsZonedDateTime() {
return getUpdated().map(dateTimeParser::parse);
}

/**
* Get a ZonedDateTime that indicates when the item was updated.
*
* @deprecated
* As of version 3.12.0, replaced by {@link Item#getUpdatedAsZonedDateTime()}
*
* @return publication date
*/
@SuppressWarnings("java:S1133")
@Deprecated(since = "3.12.0", forRemoval = true)
public Optional<ZonedDateTime> getUpdatedZonedDateTime() {
return getUpdatedAsZonedDateTime();
}

/**
* Get comments relating to the item.
* @return comments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static <I extends Item> Comparator<I> oldestItemFirst() {
*/
public static <I extends Item> Comparator<I> oldestPublishedItemFirst() {
return Comparator.comparing((I i) ->
i.getPubDateZonedDateTime().orElse(null),
i.getPubDateAsZonedDateTime().orElse(null),
Comparator.nullsLast(Comparator.naturalOrder()));
}

Expand All @@ -71,7 +71,7 @@ public static <I extends Item> Comparator<I> oldestPublishedItemFirst() {
*/
public static <I extends Item> Comparator<I> oldestUpdatedItemFirst() {
return Comparator.comparing((I i) ->
i.getUpdatedZonedDateTime().orElse(i.getPubDateZonedDateTime().orElse(null)),
i.getUpdatedAsZonedDateTime().orElse(i.getPubDateAsZonedDateTime().orElse(null)),
Comparator.nullsLast(Comparator.naturalOrder()));
}

Expand Down Expand Up @@ -133,7 +133,7 @@ public static <I extends Item> Comparator<I> newestItemFirst() {
*/
public static <I extends Item> Comparator<I> newestPublishedItemFirst() {
return Comparator.comparing((I i) ->
i.getPubDateZonedDateTime().orElse(null),
i.getPubDateAsZonedDateTime().orElse(null),
Comparator.nullsLast(Comparator.naturalOrder())).reversed();
}

Expand All @@ -144,7 +144,7 @@ public static <I extends Item> Comparator<I> newestPublishedItemFirst() {
*/
public static <I extends Item> Comparator<I> newestUpdatedItemFirst() {
return Comparator.comparing((I i) ->
i.getUpdatedZonedDateTime().orElse(i.getPubDateZonedDateTime().orElse(null)),
i.getUpdatedAsZonedDateTime().orElse(i.getPubDateAsZonedDateTime().orElse(null)),
Comparator.nullsLast(Comparator.naturalOrder())).reversed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ void testReadTimeout() throws IOException {
verify(2, items);
}

@SuppressWarnings("java:S5738")
private static void verify(int expectedSize, List<Item> items) {
assertEquals(expectedSize, items.size());

Expand Down Expand Up @@ -184,8 +185,10 @@ private static void verify(int expectedSize, List<Item> items) {
assertEquals("http://example.org/2003/12/13/atom04", items.get(2).getLink().orElse(null));
assertEquals("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b", items.get(2).getGuid().orElse(null));
assertEquals("2003-12-13T09:28:28-04:00", items.get(2).getPubDate().orElse(null));
assertEquals(1071322108, items.get(2).getPubDateAsZonedDateTime().map(ZonedDateTime::toEpochSecond).orElse(null));
assertEquals(1071322108, items.get(2).getPubDateZonedDateTime().map(ZonedDateTime::toEpochSecond).orElse(null));
assertEquals("2003-12-13T18:30:01Z", items.get(2).getUpdated().orElse(null));
assertEquals(1071340201, items.get(2).getUpdatedAsZonedDateTime().map(ZonedDateTime::toEpochSecond).orElse(null));
assertEquals(1071340201, items.get(2).getUpdatedZonedDateTime().map(ZonedDateTime::toEpochSecond).orElse(null));
assertEquals(47, items.get(2).getDescription().orElse("").length());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void readRdfFeedExample1() {
assertEquals("doi:10.1080/19322909.2024.2326687", item.getGuid().orElse(""));
}

@SuppressWarnings("java:S5738")
@Test
void readRdfFeedExample2() {
var list = new RssReader().read(fromFile("rdf-feed-example2.xml")).collect(Collectors.toList());
Expand All @@ -50,6 +51,7 @@ void readRdfFeedExample2() {
assertEquals("pater@slashdot.org", item.getChannel().getManagingEditor().orElse(""));
assertEquals("Copyright © 2000 Slashdot", item.getChannel().getCopyright().orElse(""));
assertEquals("2000-12-17T01:17-05:00", item.getChannel().getPubDate().orElse(""));
assertEquals(Default.getDateTimeParser().parse("2000-12-17T01:17-05:00"), item.getChannel().getPubDateAsZonedDateTime().orElse(null));
assertEquals(Default.getDateTimeParser().parse("2000-12-17T01:17-05:00"), item.getChannel().getPubDateZonedDateTime().orElse(null));

assertEquals("Jupiter Moon Ganymede May Have An Ocean", item.getTitle().orElse(""));
Expand All @@ -58,6 +60,7 @@ void readRdfFeedExample2() {
" salt water ocean on it. Kind of ...", item.getDescription().orElse(""));
assertEquals("timothy", item.getAuthor().orElse(""));
assertEquals("2000-12-17T01:17", item.getPubDate().orElse(""));
assertEquals(Default.getDateTimeParser().parse("2000-12-17T01:17"), item.getPubDateAsZonedDateTime().orElse(null));
assertEquals(Default.getDateTimeParser().parse("2000-12-17T01:17"), item.getPubDateZonedDateTime().orElse(null));
assertEquals(1, item.getCategories().size());
assertEquals("space", item.getCategories().get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void rssWorldOfTank() throws IOException {
assertThat(channel.getLanguage(), isPresentAndIs("en"));
assertThat(channel.getLink(), is("https://worldoftanks.eu/en/news/"));
assertThat(channel.getPubDate(), isPresent());
assertThat(channel.getPubDateZonedDateTime(), isPresent());
assertThat(channel.getPubDateAsZonedDateTime(), isPresent());
assertThat(channel.getImage(), isPresent());
assertThat(channel.getImage().map(Image::getTitle).orElse(null), containsString("World of Tanks"));
assertThat(channel.getImage().map(Image::getLink).orElse(null), is("https://worldoftanks.eu/en/news/"));
Expand Down Expand Up @@ -456,7 +456,7 @@ void zonedDateTime() throws IOException {
ZonedDateTime dateTime = items.stream()
.sorted()
.findFirst()
.flatMap(Item::getPubDateZonedDateTime)
.flatMap(Item::getPubDateAsZonedDateTime)
.orElse(null);
assertNotNull(dateTime);
}
Expand All @@ -474,7 +474,7 @@ void dateTime() throws IOException {

Optional<ZonedDateTime> dateTime = items.stream()
.findFirst()
.flatMap(Item::getPubDateZonedDateTime);
.flatMap(Item::getPubDateAsZonedDateTime);

assertThat(dateTime, isPresent());
}
Expand Down Expand Up @@ -510,7 +510,7 @@ void httpClient() throws IOException, KeyManagementException, NoSuchAlgorithmExc
assertThat(channel.getCopyright(), isPresentAndIs("© Breaking Media AB"));
assertThat(channel.getGenerator(), isEmpty());
assertThat(channel.getLastBuildDate(), isPresent());
assertThat(channel.getLastBuildDateZonedDateTime(), isPresent());
assertThat(channel.getLastBuildDateAsZonedDateTime(), isPresent());

// Validate item
assertNotNull(item);
Expand All @@ -519,7 +519,7 @@ void httpClient() throws IOException, KeyManagementException, NoSuchAlgorithmExc
assertThat(item.getTitle(), isPresentAnd(not(emptyString())));
assertThat(item.getDescription(), anyOf(isEmpty(), isPresentAnd(not(emptyString()))));
assertThat(item.getPubDate(), isPresent());
assertThat(item.getPubDateZonedDateTime(), isPresent());
assertThat(item.getPubDateAsZonedDateTime(), isPresent());
assertThat(item.getLink(), isPresent());
}
}
Expand Down Expand Up @@ -706,9 +706,9 @@ void testAtomFeed() {
assertEquals("http://example.org/2003/12/13/atom04", items.get(2).getLink().orElse(null));
assertEquals("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b", items.get(2).getGuid().orElse(null));
assertEquals("2003-12-13T09:28:28-04:00", items.get(2).getPubDate().orElse(null));
assertEquals(1071322108, items.get(2).getPubDateZonedDateTime().map(ZonedDateTime::toEpochSecond).orElse(null));
assertEquals(1071322108, items.get(2).getPubDateAsZonedDateTime().map(ZonedDateTime::toEpochSecond).orElse(null));
assertEquals("2003-12-13T18:30:01Z", items.get(2).getUpdated().orElse(null));
assertEquals(1071340201, items.get(2).getUpdatedZonedDateTime().map(ZonedDateTime::toEpochSecond).orElse(null));
assertEquals(1071340201, items.get(2).getUpdatedAsZonedDateTime().map(ZonedDateTime::toEpochSecond).orElse(null));
assertEquals(47, items.get(2).getDescription().orElse("").length());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void testTimestampSortTest() {

var timestamps = new RssReader().read(urlList)
.sorted()
.map(Item::getPubDateZonedDateTime)
.map(Item::getPubDateAsZonedDateTime)
.flatMap(Optional::stream)
.map(t -> t.toInstant().toEpochMilli())
.collect(Collectors.toList());
Expand Down
Loading