File tree Expand file tree Collapse file tree
extractor/src/main/java/org/schabi/newpipe/extractor Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments