Skip to content

Commit 08dff33

Browse files
Stypoxlitetex
authored andcommitted
Use Java 8 streams in NewPipe class
1 parent c2446ec commit 08dff33

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

  • extractor/src/main/java/org/schabi/newpipe/extractor

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,20 @@ public static List<StreamingService> getServices() {
7171
return ServiceList.all();
7272
}
7373

74-
public static StreamingService getService(int serviceId) throws ExtractionException {
75-
for (StreamingService service : ServiceList.all()) {
76-
if (service.getServiceId() == serviceId) {
77-
return service;
78-
}
79-
}
80-
throw new ExtractionException("There's no service with the id = \"" + serviceId + "\"");
81-
}
82-
83-
public static StreamingService getService(String serviceName) throws ExtractionException {
84-
for (StreamingService service : ServiceList.all()) {
85-
if (service.getServiceInfo().getName().equals(serviceName)) {
86-
return service;
87-
}
88-
}
89-
throw new ExtractionException("There's no service with the name = \"" + serviceName + "\"");
74+
public static StreamingService getService(final int serviceId) throws ExtractionException {
75+
return ServiceList.all().stream()
76+
.filter(service -> service.getServiceId() == serviceId)
77+
.findFirst()
78+
.orElseThrow(() -> new ExtractionException(
79+
"There's no service with the id = \"" + serviceId + "\""));
80+
}
81+
82+
public static StreamingService getService(final String serviceName) throws ExtractionException {
83+
return ServiceList.all().stream()
84+
.filter(service -> service.getServiceInfo().getName().equals(serviceName))
85+
.findFirst()
86+
.orElseThrow(() -> new ExtractionException(
87+
"There's no service with the name = \"" + serviceName + "\""));
9088
}
9189

9290
public static StreamingService getServiceByUrl(final String url) throws ExtractionException {

0 commit comments

Comments
 (0)