Skip to content

Commit 54d1577

Browse files
authored
Refactor interfaces for modules (#353)
1 parent 5ca4059 commit 54d1577

109 files changed

Lines changed: 1655 additions & 701 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/com/apptasticsoftware/rssreader/FeedChannel.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,64 @@
1313
import com.apptasticsoftware.rssreader.module.wfw.WfwChannel;
1414
import com.apptasticsoftware.rssreader.module.youtube.YoutubeChannel;
1515

16+
/**
17+
* Unified feed channel interface combining {@link Channel} with all supported namespace module extensions.
18+
* Used by {@link FeedReader} to expose data from Atom, DC, GeoRSS, iTunes, Media RSS,
19+
* OpenSearch, Podcast, PSC, Slash, Spotify, WFW, and YouTube namespaces in a single object.
20+
*/
1621
public interface FeedChannel extends Channel, AtomChannel, DcChannel, GeoRssChannel, ItunesChannel, MediaRssChannel, OpenSearchChannel, PodcastChannel, PscChannel, SlashChannel, SpotifyChannel, WfwChannel, YoutubeChannel {
22+
23+
/**
24+
* Returns {@code true} if this channel contains Atom namespace data.
25+
* Always check this before accessing any Atom-specific fields.
26+
*/
27+
boolean hasAtomChannel();
28+
29+
/**
30+
* Returns {@code true} if this channel contains Dublin Core (DC) namespace data.
31+
* Always check this before accessing any DC-specific fields.
32+
*/
33+
boolean hasDcChannel();
34+
35+
/**
36+
* Returns {@code true} if this channel contains GeoRSS namespace data.
37+
* Always check this before accessing any GeoRSS-specific fields.
38+
*/
39+
boolean hasGeoRssChannel();
40+
41+
/**
42+
* Returns {@code true} if this channel contains iTunes namespace data.
43+
* Always check this before accessing any iTunes-specific fields.
44+
*/
45+
boolean hasItunesChannel();
46+
47+
/**
48+
* Returns {@code true} if this channel contains Media RSS namespace data.
49+
* Always check this before accessing any Media RSS-specific fields.
50+
*/
51+
boolean hasMediaRssChannel();
52+
53+
/**
54+
* Returns {@code true} if this channel contains OpenSearch namespace data.
55+
* Always check this before accessing any OpenSearch-specific fields.
56+
*/
57+
boolean hasOpenSearchChannel();
58+
59+
/**
60+
* Returns {@code true} if this channel contains Podcast namespace data.
61+
* Always check this before accessing any Podcast-specific fields.
62+
*/
63+
boolean hasPodcastChannel();
64+
65+
/**
66+
* Returns {@code true} if this channel contains Spotify namespace data.
67+
* Always check this before accessing any Spotify-specific fields.
68+
*/
69+
boolean hasSpotifyChannel();
70+
71+
/**
72+
* Returns {@code true} if this channel contains YouTube namespace data.
73+
* Always check this before accessing any YouTube-specific fields.
74+
*/
75+
boolean hasYoutubeChannel();
1776
}

src/main/java/com/apptasticsoftware/rssreader/FeedItem.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,73 @@
1313
import com.apptasticsoftware.rssreader.module.wfw.WfwItem;
1414
import com.apptasticsoftware.rssreader.module.youtube.YoutubeItem;
1515

16+
/**
17+
* Unified feed item interface combining {@link Item} with all supported namespace module extensions.
18+
* Used by {@link FeedReader} to expose data from Atom, DC, GeoRSS, iTunes, Media RSS,
19+
* OpenSearch, Podcast, PSC, Slash, Spotify, WFW, and YouTube namespaces in a single object.
20+
*/
1621
public interface FeedItem extends Item, AtomItem, DcItem, GeoRssItem, ItunesItem, MediaRssItem, OpenSearchItem, PodcastItem, PscItem, SlashItem, SpotifyItem, WfwItem, YoutubeItem {
1722

23+
@Override
24+
FeedChannel getChannel();
25+
26+
/**
27+
* Returns {@code true} if this item contains Atom namespace data.
28+
* Always check this before accessing any Atom-specific fields.
29+
*/
30+
boolean hasAtomItem();
31+
32+
/**
33+
* Returns {@code true} if this item contains Dublin Core (DC) namespace data.
34+
* Always check this before accessing any DC-specific fields.
35+
*/
36+
boolean hasDcItem();
37+
38+
/**
39+
* Returns {@code true} if this item contains GeoRSS namespace data.
40+
* Always check this before accessing any GeoRSS-specific fields.
41+
*/
42+
boolean hasGeoRssItem();
43+
44+
/**
45+
* Returns {@code true} if this item contains iTunes namespace data.
46+
* Always check this before accessing any iTunes-specific fields.
47+
*/
48+
boolean hasItunesItem();
49+
50+
/**
51+
* Returns {@code true} if this item contains Media RSS namespace data.
52+
* Always check this before accessing any Media RSS-specific fields.
53+
*/
54+
boolean hasMediaRssItem();
55+
56+
/**
57+
* Returns {@code true} if this item contains Podcast namespace data.
58+
* Always check this before accessing any Podcast-specific fields.
59+
*/
60+
boolean hasPodcastItem();
61+
62+
/**
63+
* Returns {@code true} if this item contains PSC (Podlove Simple Chapters) namespace data.
64+
* Always check this before accessing any PSC-specific fields.
65+
*/
66+
boolean hasPscItem();
67+
68+
/**
69+
* Returns {@code true} if this item contains Slash namespace data.
70+
* Always check this before accessing any Slash-specific fields.
71+
*/
72+
boolean hasSlashItem();
73+
74+
/**
75+
* Returns {@code true} if this item contains WFW (Well-Formed Web) namespace data.
76+
* Always check this before accessing any WFW-specific fields.
77+
*/
78+
boolean hasWfwItem();
79+
80+
/**
81+
* Returns {@code true} if this item contains YouTube namespace data.
82+
* Always check this before accessing any YouTube-specific fields.
83+
*/
84+
boolean hasYoutubeItem();
1885
}

src/main/java/com/apptasticsoftware/rssreader/internal/FeedChannelImpl.java

Lines changed: 102 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,26 @@
2222
import com.apptasticsoftware.rssreader.module.youtube.internal.YoutubeChannelDataImpl;
2323

2424
import java.util.Objects;
25+
import com.apptasticsoftware.rssreader.module.atom.internal.AtomChannelDataProvider;
26+
import com.apptasticsoftware.rssreader.module.dc.internal.DcChannelDataProvider;
27+
import com.apptasticsoftware.rssreader.module.georss.internal.GeoRssChannelDataProvider;
28+
import com.apptasticsoftware.rssreader.module.itunes.internal.ItunesChannelDataProvider;
29+
import com.apptasticsoftware.rssreader.module.mediarss.internal.MediaRssChannelDataProvider;
30+
import com.apptasticsoftware.rssreader.module.opensearch.internal.OpenSearchChannelDataProvider;
31+
import com.apptasticsoftware.rssreader.module.podcast.internal.PodcastChannelDataProvider;
32+
import com.apptasticsoftware.rssreader.module.spotify.internal.SpotifyChannelDataProvider;
33+
import com.apptasticsoftware.rssreader.module.youtube.internal.YoutubeChannelDataProvider;
2534

26-
public class FeedChannelImpl extends ChannelImpl implements FeedChannel {
27-
private final AtomChannelData atomChannelData = new AtomChannelDataImpl();
28-
private final DcChannelData dcChannelData = new DcChannelDataImpl();
29-
private final GeoRssChannelData geoRssChannelData = new GeoRssChannelDataImpl();
30-
private final ItunesChannelData itunesChannelData = new ItunesChannelDataImpl();
31-
private final MediaRssChannelData mediaRssChannelData = new MediaRssChannelDataImpl();
32-
private final OpenSearchChannelData openSearchChannelData = new OpenSearchChannelDataImpl();
33-
private final PodcastChannelData podcastChannelData = new PodcastChannelDataImpl();
34-
private final SpotifyChannelData spotifyChannelData = new SpotifyChannelDataImpl();
35-
private final YoutubeChannelData youtubeChannelData = new YoutubeChannelDataImpl();
35+
public class FeedChannelImpl extends ChannelImpl implements FeedChannel, AtomChannelDataProvider, DcChannelDataProvider, GeoRssChannelDataProvider, ItunesChannelDataProvider, MediaRssChannelDataProvider, OpenSearchChannelDataProvider, PodcastChannelDataProvider, SpotifyChannelDataProvider, YoutubeChannelDataProvider {
36+
private AtomChannelData atomChannelData;
37+
private DcChannelData dcChannelData;
38+
private GeoRssChannelData geoRssChannelData;
39+
private ItunesChannelData itunesChannelData;
40+
private MediaRssChannelData mediaRssChannelData;
41+
private OpenSearchChannelData openSearchChannelData;
42+
private PodcastChannelData podcastChannelData;
43+
private SpotifyChannelData spotifyChannelData;
44+
private YoutubeChannelData youtubeChannelData;
3645

3746
/**
3847
* Constructor
@@ -44,47 +53,119 @@ public FeedChannelImpl(DateTimeParser dateTimeParser) {
4453
}
4554

4655
@Override
47-
public AtomChannelData getAtomChannelData() {
56+
public boolean hasAtomChannel() {
57+
return atomChannelData != null;
58+
}
59+
60+
@Override
61+
public AtomChannelData atomChannelData() {
62+
if (atomChannelData == null) {
63+
atomChannelData = new AtomChannelDataImpl();
64+
}
4865
return atomChannelData;
4966
}
5067

5168
@Override
52-
public DcChannelData getDcChannelData() {
69+
public boolean hasDcChannel() {
70+
return dcChannelData != null;
71+
}
72+
73+
@Override
74+
public DcChannelData dcChannelData() {
75+
if (dcChannelData == null) {
76+
dcChannelData = new DcChannelDataImpl();
77+
}
5378
return dcChannelData;
5479
}
5580

5681
@Override
57-
public GeoRssChannelData getGeoRssChannelData() {
82+
public boolean hasGeoRssChannel() {
83+
return geoRssChannelData != null;
84+
}
85+
86+
@Override
87+
public GeoRssChannelData geoRssChannelData() {
88+
if (geoRssChannelData == null) {
89+
geoRssChannelData = new GeoRssChannelDataImpl();
90+
}
5891
return geoRssChannelData;
5992
}
6093

6194
@Override
62-
public ItunesChannelData getItunesChannelData() {
95+
public boolean hasItunesChannel() {
96+
return itunesChannelData != null;
97+
}
98+
99+
@Override
100+
public ItunesChannelData itunesChannelData() {
101+
if (itunesChannelData == null) {
102+
itunesChannelData = new ItunesChannelDataImpl();
103+
}
63104
return itunesChannelData;
64105
}
65106

66107
@Override
67-
public MediaRssChannelData getMediaRssChannelData() {
108+
public boolean hasMediaRssChannel() {
109+
return mediaRssChannelData != null;
110+
}
111+
112+
@Override
113+
public MediaRssChannelData mediaRssChannelData() {
114+
if (mediaRssChannelData == null) {
115+
mediaRssChannelData = new MediaRssChannelDataImpl();
116+
}
68117
return mediaRssChannelData;
69118
}
70119

71120
@Override
72-
public OpenSearchChannelData getOpenSearchChannelData() {
121+
public boolean hasOpenSearchChannel() {
122+
return openSearchChannelData != null;
123+
}
124+
125+
@Override
126+
public OpenSearchChannelData openSearchChannelData() {
127+
if (openSearchChannelData == null) {
128+
openSearchChannelData = new OpenSearchChannelDataImpl();
129+
}
73130
return openSearchChannelData;
74131
}
75132

76133
@Override
77-
public PodcastChannelData getPodcastChannelData() {
134+
public boolean hasPodcastChannel() {
135+
return podcastChannelData != null;
136+
}
137+
138+
@Override
139+
public PodcastChannelData podcastChannelData() {
140+
if (podcastChannelData == null) {
141+
podcastChannelData = new PodcastChannelDataImpl();
142+
}
78143
return podcastChannelData;
79144
}
80145

81146
@Override
82-
public SpotifyChannelData getSpotifyChannelData() {
147+
public boolean hasSpotifyChannel() {
148+
return spotifyChannelData != null;
149+
}
150+
151+
@Override
152+
public SpotifyChannelData spotifyChannelData() {
153+
if (spotifyChannelData == null) {
154+
spotifyChannelData = new SpotifyChannelDataImpl();
155+
}
83156
return spotifyChannelData;
84157
}
85158

86159
@Override
87-
public YoutubeChannelData getYoutubeChannelData() {
160+
public boolean hasYoutubeChannel() {
161+
return youtubeChannelData != null;
162+
}
163+
164+
@Override
165+
public YoutubeChannelData youtubeChannelData() {
166+
if (youtubeChannelData == null) {
167+
youtubeChannelData = new YoutubeChannelDataImpl();
168+
}
88169
return youtubeChannelData;
89170
}
90171

@@ -93,11 +174,11 @@ public boolean equals(Object o) {
93174
if (!(o instanceof FeedChannelImpl)) return false;
94175
if (!super.equals(o)) return false;
95176
FeedChannelImpl that = (FeedChannelImpl) o;
96-
return Objects.equals(getItunesChannelData(), that.getItunesChannelData()) && Objects.equals(getMediaRssChannelData(), that.getMediaRssChannelData()) && Objects.equals(getOpenSearchChannelData(), that.getOpenSearchChannelData()) && Objects.equals(getPodcastChannelData(), that.getPodcastChannelData()) && Objects.equals(getYoutubeChannelData(), that.getYoutubeChannelData());
177+
return Objects.equals(itunesChannelData(), that.itunesChannelData()) && Objects.equals(mediaRssChannelData(), that.mediaRssChannelData()) && Objects.equals(openSearchChannelData(), that.openSearchChannelData()) && Objects.equals(podcastChannelData(), that.podcastChannelData()) && Objects.equals(youtubeChannelData(), that.youtubeChannelData());
97178
}
98179

99180
@Override
100181
public int hashCode() {
101-
return Objects.hash(super.hashCode(), getItunesChannelData(), getMediaRssChannelData(), getOpenSearchChannelData(), getPodcastChannelData(), getYoutubeChannelData());
182+
return Objects.hash(super.hashCode(), itunesChannelData(), mediaRssChannelData(), openSearchChannelData(), podcastChannelData(), youtubeChannelData());
102183
}
103184
}

0 commit comments

Comments
 (0)