Java 17 features (N-S) (#15565)
- 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 Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.remoteopenhab.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -34,10 +33,10 @@ public class RemoteopenhabBindingConstants {
|
||||
public static final ThingTypeUID THING_TYPE_THING = new ThingTypeUID(BINDING_ID, "thing");
|
||||
|
||||
// All supported Bridge types
|
||||
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES_UIDS = Collections.singleton(BRIDGE_TYPE_SERVER);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_BRIDGE_TYPES_UIDS = Set.of(BRIDGE_TYPE_SERVER);
|
||||
|
||||
// All supported Thing types
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_THING);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_THING);
|
||||
|
||||
// List of all channel types
|
||||
public static final String CHANNEL_TYPE_TRIGGER = "trigger";
|
||||
|
||||
@@ -59,8 +59,8 @@ public class RemoteopenhabDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
@Override
|
||||
public void setThingHandler(ThingHandler handler) {
|
||||
if (handler instanceof RemoteopenhabBridgeHandler) {
|
||||
this.bridgeHandler = (RemoteopenhabBridgeHandler) handler;
|
||||
if (handler instanceof RemoteopenhabBridgeHandler remoteopenhabBridgeHandler) {
|
||||
this.bridgeHandler = remoteopenhabBridgeHandler;
|
||||
this.restClient = bridgeHandler.gestRestClient();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -552,7 +552,7 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
|
||||
} else if (acceptedItemType.startsWith(CoreItemFactory.NUMBER + ":")) {
|
||||
// Item type Number with dimension
|
||||
if (stateType == null || "Quantity".equals(stateType)) {
|
||||
List<Class<? extends State>> stateTypes = Collections.singletonList(QuantityType.class);
|
||||
List<Class<? extends State>> stateTypes = List.of(QuantityType.class);
|
||||
channelState = TypeParser.parseState(stateTypes, state);
|
||||
} else if ("Decimal".equals(stateType)) {
|
||||
channelState = new DecimalType(state);
|
||||
@@ -661,6 +661,6 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(RemoteopenhabDiscoveryService.class);
|
||||
return Set.of(RemoteopenhabDiscoveryService.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,12 +621,10 @@ public class RemoteopenhabRestClient {
|
||||
String statusLine = statusCode + " " + response.getReason();
|
||||
throw new RemoteopenhabException("@text/exception.http-call-failed", statusLine);
|
||||
}
|
||||
String encoding = response.getEncoding() != null ? response.getEncoding().replaceAll("\"", "").trim()
|
||||
String encoding = response.getEncoding() != null ? response.getEncoding().replace("\"", "").trim()
|
||||
: StandardCharsets.UTF_8.name();
|
||||
return new String(response.getContent(), encoding);
|
||||
}
|
||||
} catch (RemoteopenhabException e) {
|
||||
throw e;
|
||||
} catch (ExecutionException e) {
|
||||
// After a long network outage, the first HTTP request will fail with an EOFException exception.
|
||||
// We retry the request a second time in this case.
|
||||
|
||||
Reference in New Issue
Block a user