Skip to content

Commit d79e203

Browse files
Stypoxlitetex
authored andcommitted
Fix checkstyle issues in root package extractor/
Note: not all issues were fixed because MediaFormat and ServiceList use a specific formatting that makes sense for them
1 parent ca7c63f commit d79e203

11 files changed

Lines changed: 191 additions & 138 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
import javax.annotation.Nonnull;
1212
import javax.annotation.Nullable;
13+
1314
import java.io.IOException;
1415
import java.util.Objects;
1516

1617
public abstract class Extractor {
1718
/**
1819
* {@link StreamingService} currently related to this extractor.<br>
19-
* Useful for getting other things from a service (like the url handlers for cleaning/accepting/get id from urls).
20+
* Useful for getting other things from a service (like the url handlers for
21+
* cleaning/accepting/get id from urls).
2022
*/
2123
private final StreamingService service;
2224
private final LinkHandler linkHandler;
@@ -27,16 +29,18 @@ public abstract class Extractor {
2729
private ContentCountry forcedContentCountry = null;
2830

2931
private boolean pageFetched = false;
30-
private final Downloader downloader;
32+
// called like this to prevent checkstyle errors about "hiding a field"
33+
private final Downloader theDownloader;
3134

3235
public Extractor(final StreamingService service, final LinkHandler linkHandler) {
3336
this.service = Objects.requireNonNull(service, "service is null");
3437
this.linkHandler = Objects.requireNonNull(linkHandler, "LinkHandler is null");
35-
this.downloader = Objects.requireNonNull(NewPipe.getDownloader(), "downloader is null");
38+
this.theDownloader = Objects.requireNonNull(NewPipe.getDownloader(), "downloader is null");
3639
}
3740

3841
/**
39-
* @return The {@link LinkHandler} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler).
42+
* @return The {@link LinkHandler} of the current extractor object (e.g. a ChannelExtractor
43+
* should return a channel url handler).
4044
*/
4145
@Nonnull
4246
public LinkHandler getLinkHandler() {
@@ -50,13 +54,17 @@ public LinkHandler getLinkHandler() {
5054
* @throws ExtractionException if the pages content is not understood
5155
*/
5256
public void fetchPage() throws IOException, ExtractionException {
53-
if (pageFetched) return;
54-
onFetchPage(downloader);
57+
if (pageFetched) {
58+
return;
59+
}
60+
onFetchPage(theDownloader);
5561
pageFetched = true;
5662
}
5763

5864
protected void assertPageFetched() {
59-
if (!pageFetched) throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()");
65+
if (!pageFetched) {
66+
throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()");
67+
}
6068
}
6169

6270
protected boolean isPageFetched() {
@@ -66,11 +74,12 @@ protected boolean isPageFetched() {
6674
/**
6775
* Fetch the current page.
6876
*
69-
* @param downloader the download to use
77+
* @param downloader the downloader to use
7078
* @throws IOException if the page can not be loaded
7179
* @throws ExtractionException if the pages content is not understood
7280
*/
73-
public abstract void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException;
81+
public abstract void onFetchPage(@Nonnull Downloader downloader)
82+
throws IOException, ExtractionException;
7483

7584
@Nonnull
7685
public String getId() throws ParsingException {
@@ -111,18 +120,18 @@ public int getServiceId() {
111120
}
112121

113122
public Downloader getDownloader() {
114-
return downloader;
123+
return theDownloader;
115124
}
116125

117126
/*//////////////////////////////////////////////////////////////////////////
118127
// Localization
119128
//////////////////////////////////////////////////////////////////////////*/
120129

121-
public void forceLocalization(Localization localization) {
130+
public void forceLocalization(final Localization localization) {
122131
this.forcedLocalization = localization;
123132
}
124133

125-
public void forceContentCountry(ContentCountry contentCountry) {
134+
public void forceContentCountry(final ContentCountry contentCountry) {
126135
this.forcedContentCountry = contentCountry;
127136
}
128137

@@ -133,7 +142,8 @@ public Localization getExtractorLocalization() {
133142

134143
@Nonnull
135144
public ContentCountry getExtractorContentCountry() {
136-
return forcedContentCountry == null ? getService().getContentCountry() : forcedContentCountry;
145+
return forcedContentCountry == null ? getService().getContentCountry()
146+
: forcedContentCountry;
137147
}
138148

139149
@Nonnull

extractor/src/main/java/org/schabi/newpipe/extractor/Info.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public abstract class Info implements Serializable {
1717
*/
1818
private final String id;
1919
/**
20-
* Different than the {@link #originalUrl} in the sense that it <i>may</i> be set as a cleaned url.
20+
* Different than the {@link #originalUrl} in the sense that it <i>may</i> be set as a cleaned
21+
* url.
2122
*
2223
* @see LinkHandler#getUrl()
2324
* @see Extractor#getOriginalUrl()
@@ -33,23 +34,27 @@ public abstract class Info implements Serializable {
3334

3435
private final List<Throwable> errors = new ArrayList<>();
3536

36-
public void addError(Throwable throwable) {
37+
public void addError(final Throwable throwable) {
3738
this.errors.add(throwable);
3839
}
3940

40-
public void addAllErrors(Collection<Throwable> errors) {
41-
this.errors.addAll(errors);
41+
public void addAllErrors(final Collection<Throwable> throwables) {
42+
this.errors.addAll(throwables);
4243
}
4344

44-
public Info(int serviceId, String id, String url, String originalUrl, String name) {
45+
public Info(final int serviceId,
46+
final String id,
47+
final String url,
48+
final String originalUrl,
49+
final String name) {
4550
this.serviceId = serviceId;
4651
this.id = id;
4752
this.url = url;
4853
this.originalUrl = originalUrl;
4954
this.name = name;
5055
}
5156

52-
public Info(int serviceId, LinkHandler linkHandler, String name) {
57+
public Info(final int serviceId, final LinkHandler linkHandler, final String name) {
5358
this(serviceId,
5459
linkHandler.getId(),
5560
linkHandler.getUrl(),
@@ -59,14 +64,16 @@ public Info(int serviceId, LinkHandler linkHandler, String name) {
5964

6065
@Override
6166
public String toString() {
62-
final String ifDifferentString = !url.equals(originalUrl) ? " (originalUrl=\"" + originalUrl + "\")" : "";
63-
return getClass().getSimpleName() + "[url=\"" + url + "\"" + ifDifferentString + ", name=\"" + name + "\"]";
67+
final String ifDifferentString
68+
= url.equals(originalUrl) ? "" : " (originalUrl=\"" + originalUrl + "\")";
69+
return getClass().getSimpleName() + "[url=\"" + url + "\"" + ifDifferentString
70+
+ ", name=\"" + name + "\"]";
6471
}
6572

6673
// if you use an api and want to handle the website url
6774
// overriding original url is essential
68-
public void setOriginalUrl(String url) {
69-
originalUrl = url;
75+
public void setOriginalUrl(final String originalUrl) {
76+
this.originalUrl = originalUrl;
7077
}
7178

7279
public int getServiceId() {

extractor/src/main/java/org/schabi/newpipe/extractor/InfoItem.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public abstract class InfoItem implements Serializable {
2929
private final String name;
3030
private String thumbnailUrl;
3131

32-
public InfoItem(InfoType infoType, int serviceId, String url, String name) {
32+
public InfoItem(final InfoType infoType,
33+
final int serviceId,
34+
final String url,
35+
final String name) {
3336
this.infoType = infoType;
3437
this.serviceId = serviceId;
3538
this.url = url;
@@ -52,7 +55,7 @@ public String getName() {
5255
return name;
5356
}
5457

55-
public void setThumbnailUrl(String thumbnailUrl) {
58+
public void setThumbnailUrl(final String thumbnailUrl) {
5659
this.thumbnailUrl = thumbnailUrl;
5760
}
5861

extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemsCollector.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
3030
*/
3131

32-
public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemExtractor> implements Collector<I, E> {
32+
public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemExtractor>
33+
implements Collector<I, E> {
3334

3435
private final List<I> itemList = new ArrayList<>();
3536
private final List<Throwable> errors = new ArrayList<>();
@@ -77,15 +78,15 @@ public void reset() {
7778
* Add an error
7879
* @param error the error
7980
*/
80-
protected void addError(Exception error) {
81+
protected void addError(final Exception error) {
8182
errors.add(error);
8283
}
8384

8485
/**
8586
* Add an item
8687
* @param item the item
8788
*/
88-
protected void addItem(I item) {
89+
protected void addItem(final I item) {
8990
itemList.add(item);
9091
}
9192

@@ -98,12 +99,12 @@ public int getServiceId() {
9899
}
99100

100101
@Override
101-
public void commit(E extractor) {
102+
public void commit(final E extractor) {
102103
try {
103104
addItem(extract(extractor));
104-
} catch (FoundAdException ae) {
105+
} catch (final FoundAdException ae) {
105106
// found an ad. Maybe a debug line could be placed here
106-
} catch (ParsingException e) {
107+
} catch (final ParsingException e) {
107108
addError(e);
108109
}
109110
}

extractor/src/main/java/org/schabi/newpipe/extractor/ListExtractor.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/**
1414
* Base class to extractors that have a list (e.g. playlists, users).
15+
* @param <R> the info item type this list extractor provides
1516
*/
1617
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
1718
/**
@@ -30,7 +31,7 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
3031
*/
3132
public static final long ITEM_COUNT_MORE_THAN_100 = -3;
3233

33-
public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
34+
public ListExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
3435
super(service, linkHandler);
3536
}
3637

@@ -50,8 +51,9 @@ public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
5051
* @return a {@link InfoItemsPage} corresponding to the requested page
5152
* @see InfoItemsPage#getNextPage()
5253
*/
53-
public abstract InfoItemsPage<R> getPage(final Page page) throws IOException, ExtractionException;
54+
public abstract InfoItemsPage<R> getPage(Page page) throws IOException, ExtractionException;
5455

56+
@Nonnull
5557
@Override
5658
public ListLinkHandler getLinkHandler() {
5759
return (ListLinkHandler) super.getLinkHandler();
@@ -64,15 +66,17 @@ public ListLinkHandler getLinkHandler() {
6466
/**
6567
* A class that is used to wrap a list of gathered items and eventual errors, it
6668
* also contains a field that points to the next available page ({@link #nextPage}).
69+
* @param <T> the info item type that this page is supposed to store and provide
6770
*/
6871
public static class InfoItemsPage<T extends InfoItem> {
6972
private static final InfoItemsPage<InfoItem> EMPTY =
70-
new InfoItemsPage<>(Collections.<InfoItem>emptyList(), null, Collections.<Throwable>emptyList());
73+
new InfoItemsPage<>(Collections.emptyList(), null, Collections.emptyList());
7174

7275
/**
7376
* A convenient method that returns a representation of an empty page.
7477
*
75-
* @return a type-safe page with the list of items and errors empty and the nextPage set to {@code null}.
78+
* @return a type-safe page with the list of items and errors empty and the nextPage set to
79+
* {@code null}.
7680
*/
7781
public static <T extends InfoItem> InfoItemsPage<T> emptyPage() {
7882
//noinspection unchecked
@@ -97,11 +101,13 @@ public static <T extends InfoItem> InfoItemsPage<T> emptyPage() {
97101
*/
98102
private final List<Throwable> errors;
99103

100-
public InfoItemsPage(InfoItemsCollector<T, ?> collector, Page nextPage) {
104+
public InfoItemsPage(final InfoItemsCollector<T, ?> collector, final Page nextPage) {
101105
this(collector.getItems(), nextPage, collector.getErrors());
102106
}
103107

104-
public InfoItemsPage(List<T> itemsList, Page nextPage, List<Throwable> errors) {
108+
public InfoItemsPage(final List<T> itemsList,
109+
final Page nextPage,
110+
final List<Throwable> errors) {
105111
this.itemsList = itemsList;
106112
this.nextPage = nextPage;
107113
this.errors = errors;

extractor/src/main/java/org/schabi/newpipe/extractor/ListInfo.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
1010
private final List<String> contentFilters;
1111
private final String sortFilter;
1212

13-
public ListInfo(int serviceId,
14-
String id,
15-
String url,
16-
String originalUrl,
17-
String name,
18-
List<String> contentFilter,
19-
String sortFilter) {
13+
public ListInfo(final int serviceId,
14+
final String id,
15+
final String url,
16+
final String originalUrl,
17+
final String name,
18+
final List<String> contentFilter,
19+
final String sortFilter) {
2020
super(serviceId, id, url, originalUrl, name);
2121
this.contentFilters = contentFilter;
2222
this.sortFilter = sortFilter;
2323
}
2424

25-
public ListInfo(int serviceId, ListLinkHandler listUrlIdHandler, String name) {
25+
public ListInfo(final int serviceId,
26+
final ListLinkHandler listUrlIdHandler,
27+
final String name) {
2628
super(serviceId, listUrlIdHandler, name);
2729
this.contentFilters = listUrlIdHandler.getContentFilters();
2830
this.sortFilter = listUrlIdHandler.getSortFilter();
@@ -32,7 +34,7 @@ public List<T> getRelatedItems() {
3234
return relatedItems;
3335
}
3436

35-
public void setRelatedItems(List<T> relatedItems) {
37+
public void setRelatedItems(final List<T> relatedItems) {
3638
this.relatedItems = relatedItems;
3739
}
3840

@@ -44,7 +46,7 @@ public Page getNextPage() {
4446
return nextPage;
4547
}
4648

47-
public void setNextPage(Page page) {
49+
public void setNextPage(final Page page) {
4850
this.nextPage = page;
4951
}
5052

extractor/src/main/java/org/schabi/newpipe/extractor/MediaFormat.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,34 @@
2727
*/
2828

2929
public enum MediaFormat {
30+
// @formatter:off
3031
//video and audio combined formats
31-
// id name suffix mime type
32-
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
33-
v3GPP (0x10, "3GPP", "3gp", "video/3gpp"),
34-
WEBM (0x20, "WebM", "webm", "video/webm"),
32+
// id name suffix mimeType
33+
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
34+
v3GPP (0x10, "3GPP", "3gp", "video/3gpp"),
35+
WEBM (0x20, "WebM", "webm", "video/webm"),
3536
// audio formats
36-
M4A (0x100, "m4a", "m4a", "audio/mp4"),
37-
WEBMA (0x200, "WebM", "webm", "audio/webm"),
38-
MP3 (0x300, "MP3", "mp3", "audio/mpeg"),
39-
OPUS (0x400, "opus", "opus", "audio/opus"),
40-
OGG (0x500, "ogg", "ogg", "audio/ogg"),
41-
WEBMA_OPUS (0x200, "WebM Opus", "webm", "audio/webm"),
37+
M4A (0x100, "m4a", "m4a", "audio/mp4"),
38+
WEBMA (0x200, "WebM", "webm", "audio/webm"),
39+
MP3 (0x300, "MP3", "mp3", "audio/mpeg"),
40+
OPUS (0x400, "opus", "opus", "audio/opus"),
41+
OGG (0x500, "ogg", "ogg", "audio/ogg"),
42+
WEBMA_OPUS(0x200, "WebM Opus", "webm", "audio/webm"),
4243
// subtitles formats
43-
VTT (0x1000, "WebVTT", "vtt", "text/vtt"),
44-
TTML (0x2000, "Timed Text Markup Language", "ttml", "application/ttml+xml"),
45-
TRANSCRIPT1 (0x3000, "TranScript v1", "srv1", "text/xml"),
46-
TRANSCRIPT2 (0x4000, "TranScript v2", "srv2", "text/xml"),
47-
TRANSCRIPT3 (0x5000, "TranScript v3", "srv3", "text/xml"),
48-
SRT (0x6000, "SubRip file format", "srt", "text/srt");
44+
VTT (0x1000, "WebVTT", "vtt", "text/vtt"),
45+
TTML (0x2000, "Timed Text Markup Language", "ttml", "application/ttml+xml"),
46+
TRANSCRIPT1(0x3000, "TranScript v1", "srv1", "text/xml"),
47+
TRANSCRIPT2(0x4000, "TranScript v2", "srv2", "text/xml"),
48+
TRANSCRIPT3(0x5000, "TranScript v3", "srv3", "text/xml"),
49+
SRT (0x6000, "SubRip file format", "srt", "text/srt");
50+
// @formatter:on
4951

5052
public final int id;
5153
public final String name;
5254
public final String suffix;
5355
public final String mimeType;
5456

55-
MediaFormat(int id, String name, String suffix, String mimeType) {
57+
MediaFormat(final int id, final String name, final String suffix, final String mimeType) {
5658
this.id = id;
5759
this.name = name;
5860
this.suffix = suffix;

0 commit comments

Comments
 (0)