Java 17 features (H-M) (#15520)
- add missing @override - Java style array syntax - remove redundant modifiers - always move String constants to left side in comparisons - simplify lambda expressions and return statements - use replace instead of replaceAll w/o regex - instanceof matching and multiline strings - remove null check before instanceof Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -81,8 +81,7 @@ public class JellyfinHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
@Override
|
||||
protected synchronized void removeHandler(ThingHandler thingHandler) {
|
||||
if (thingHandler instanceof JellyfinServerHandler) {
|
||||
var serverHandler = (JellyfinServerHandler) thingHandler;
|
||||
if (thingHandler instanceof JellyfinServerHandler serverHandler) {
|
||||
unregisterAuthenticationServlet(serverHandler);
|
||||
}
|
||||
super.removeHandler(thingHandler);
|
||||
|
||||
@@ -105,8 +105,8 @@ public class JellyfinClientDiscoveryService extends AbstractDiscoveryService imp
|
||||
|
||||
@Override
|
||||
public void setThingHandler(ThingHandler thingHandler) {
|
||||
if (thingHandler instanceof JellyfinServerHandler) {
|
||||
bridgeHandler = (JellyfinServerHandler) thingHandler;
|
||||
if (thingHandler instanceof JellyfinServerHandler bridgeHandler) {
|
||||
this.bridgeHandler = bridgeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ public class JellyfinClientDiscoveryService extends AbstractDiscoveryService imp
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
activate(new HashMap<>());
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class JellyfinServerDiscoveryService extends AbstractDiscoveryService {
|
||||
new SystemApi(jellyClient).getPublicSystemInfo(asyncResponse);
|
||||
try {
|
||||
var publicSystemInfo = asyncResponse.awaitContent();
|
||||
discoverServer(uri.getHost(), uri.getPort(), uri.getScheme().equalsIgnoreCase("https"), uri.getPath(),
|
||||
discoverServer(uri.getHost(), uri.getPort(), "https".equalsIgnoreCase(uri.getScheme()), uri.getPath(),
|
||||
publicSystemInfo);
|
||||
} catch (SyncCallback.SyncCallbackError | ApiClientException e) {
|
||||
logger.warn("Discovery error: {}", e.getMessage());
|
||||
|
||||
@@ -243,9 +243,8 @@ public class JellyfinClientHandler extends BaseThingHandler {
|
||||
|
||||
private UUID parseItemUUID(Command command) throws NumberFormatException {
|
||||
var itemId = command.toFullString().replace("-", "");
|
||||
UUID itemUUID = new UUID(new BigInteger(itemId.substring(0, 16), 16).longValue(),
|
||||
return new UUID(new BigInteger(itemId.substring(0, 16), 16).longValue(),
|
||||
new BigInteger(itemId.substring(16), 16).longValue());
|
||||
return itemUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -385,9 +384,9 @@ public class JellyfinClientHandler extends BaseThingHandler {
|
||||
var typeMatcher = typeSearchPattern.matcher(terms);
|
||||
boolean searchByTypeEnabled = typeMatcher.matches();
|
||||
var type = searchByTypeEnabled ? typeMatcher.group("type") : "";
|
||||
boolean movieSearchEnabled = !searchByTypeEnabled || type.equals("movie");
|
||||
boolean seriesSearchEnabled = !searchByTypeEnabled || type.equals("series");
|
||||
boolean episodeSearchEnabled = !searchByTypeEnabled || type.equals("episode");
|
||||
boolean movieSearchEnabled = !searchByTypeEnabled || "movie".equals(type);
|
||||
boolean seriesSearchEnabled = !searchByTypeEnabled || "series".equals(type);
|
||||
boolean episodeSearchEnabled = !searchByTypeEnabled || "episode".equals(type);
|
||||
var searchTerms = searchByTypeEnabled ? typeMatcher.group("terms") : terms;
|
||||
runItemSearchByType(searchTerms, playCommand, movieSearchEnabled, seriesSearchEnabled, episodeSearchEnabled);
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ package org.openhab.binding.jellyfin.internal.handler;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -118,7 +118,7 @@ public class JellyfinServerHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(JellyfinClientDiscoveryService.class);
|
||||
return Set.of(JellyfinClientDiscoveryService.class);
|
||||
}
|
||||
|
||||
public String getServerUrl() {
|
||||
@@ -225,8 +225,8 @@ public class JellyfinServerHandler extends BaseBridgeHandler {
|
||||
logger.warn("Api error: {}", e.getMessage());
|
||||
var cause = e.getCause();
|
||||
boolean unauthenticated = false;
|
||||
if (cause instanceof InvalidStatusException) {
|
||||
var status = ((InvalidStatusException) cause).getStatus();
|
||||
if (cause instanceof InvalidStatusException invalidStatusException) {
|
||||
var status = invalidStatusException.getStatus();
|
||||
if (status == 401) {
|
||||
unauthenticated = true;
|
||||
}
|
||||
@@ -398,8 +398,8 @@ public class JellyfinServerHandler extends BaseBridgeHandler {
|
||||
if (handler == null) {
|
||||
return;
|
||||
}
|
||||
if (handler instanceof JellyfinClientHandler) {
|
||||
updateClientState((JellyfinClientHandler) handler, sessions);
|
||||
if (handler instanceof JellyfinClientHandler clientHandler) {
|
||||
updateClientState(clientHandler, sessions);
|
||||
} else {
|
||||
logger.warn("Found unknown thing-handler instance: {}", handler);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class SyncResponse<T> extends SyncCallback<Response<T>> {
|
||||
return awaitResult();
|
||||
} catch (SyncCallbackError e) {
|
||||
var cause = e.getCause();
|
||||
if (cause instanceof ApiClientException) {
|
||||
throw (ApiClientException) cause;
|
||||
if (cause instanceof ApiClientException apiClientException) {
|
||||
throw apiClientException;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user