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:
@@ -16,7 +16,6 @@ import static org.openhab.binding.neeo.internal.NeeoConstants.BRIDGE_TYPE_BRAIN;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -50,7 +49,7 @@ public class NeeoBrainDiscovery implements MDNSDiscoveryParticipant {
|
||||
|
||||
@Override
|
||||
public Set<@Nullable ThingTypeUID> getSupportedThingTypeUIDs() {
|
||||
return Collections.singleton(BRIDGE_TYPE_BRAIN);
|
||||
return Set.of(BRIDGE_TYPE_BRAIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
package org.openhab.binding.neeo.internal.discovery;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -46,8 +45,7 @@ public class NeeoDeviceDiscoveryService extends AbstractDiscoveryService {
|
||||
private final Logger logger = LoggerFactory.getLogger(NeeoDeviceDiscoveryService.class);
|
||||
|
||||
/** The device thing type we support */
|
||||
private static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Collections
|
||||
.singleton(NeeoConstants.THING_TYPE_DEVICE);
|
||||
private static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Set.of(NeeoConstants.THING_TYPE_DEVICE);
|
||||
|
||||
/** The timeout (in seconds) for searching the room */
|
||||
private static final int SEARCH_TIME = 10;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
package org.openhab.binding.neeo.internal.discovery;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -44,8 +43,7 @@ public class NeeoRoomDiscoveryService extends AbstractDiscoveryService {
|
||||
private final Logger logger = LoggerFactory.getLogger(NeeoRoomDiscoveryService.class);
|
||||
|
||||
/** The room bridge type we support */
|
||||
private static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Collections
|
||||
.singleton(NeeoConstants.BRIDGE_TYPE_ROOM);
|
||||
private static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Set.of(NeeoConstants.BRIDGE_TYPE_ROOM);
|
||||
|
||||
/** The timeout (in seconds) for searching the brain */
|
||||
private static final int SEARCH_TIME = 10;
|
||||
|
||||
@@ -339,8 +339,8 @@ public class NeeoDeviceHandler extends BaseThingHandler {
|
||||
final Bridge parent = getBridge();
|
||||
if (parent != null) {
|
||||
final BridgeHandler handler = parent.getHandler();
|
||||
if (handler instanceof NeeoRoomHandler) {
|
||||
return ((NeeoRoomHandler) handler);
|
||||
if (handler instanceof NeeoRoomHandler roomHandler) {
|
||||
return roomHandler;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -317,8 +317,8 @@ public class NeeoRoomHandler extends BaseBridgeHandler {
|
||||
final Bridge parent = getBridge();
|
||||
if (parent != null) {
|
||||
final BridgeHandler handler = parent.getHandler();
|
||||
if (handler instanceof NeeoBrainHandler) {
|
||||
return ((NeeoBrainHandler) handler);
|
||||
if (handler instanceof NeeoBrainHandler brainHandler) {
|
||||
return brainHandler;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -41,9 +41,9 @@ public class NeeoDevicesDeserializer implements JsonDeserializer<@Nullable NeeoD
|
||||
Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
|
||||
Objects.requireNonNull(context, "context cannot be null");
|
||||
|
||||
if (jsonElement instanceof JsonObject) {
|
||||
if (jsonElement instanceof JsonObject jsonObject) {
|
||||
final List<NeeoDevice> scenarios = new ArrayList<>();
|
||||
for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
|
||||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||
final NeeoDevice device = context.deserialize(entry.getValue(), NeeoDevice.class);
|
||||
scenarios.add(device);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,9 @@ public class NeeoMacrosDeserializer implements JsonDeserializer<@Nullable NeeoMa
|
||||
Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
|
||||
Objects.requireNonNull(context, "context cannot be null");
|
||||
|
||||
if (jsonElement instanceof JsonObject) {
|
||||
if (jsonElement instanceof JsonObject jsonObject) {
|
||||
final List<NeeoMacro> scenarios = new ArrayList<>();
|
||||
for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
|
||||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||
final NeeoMacro macro = context.deserialize(entry.getValue(), NeeoMacro.class);
|
||||
scenarios.add(macro);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,9 @@ public class NeeoRecipesDeserializer implements JsonDeserializer<@Nullable NeeoR
|
||||
Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
|
||||
Objects.requireNonNull(context, "context cannot be null");
|
||||
|
||||
if (jsonElement instanceof JsonObject) {
|
||||
if (jsonElement instanceof JsonObject jsonObject) {
|
||||
final List<NeeoRecipe> recipes = new ArrayList<>();
|
||||
for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
|
||||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||
final NeeoRecipe recipe = context.deserialize(entry.getValue(), NeeoRecipe.class);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ public class NeeoRoomsDeserializer implements JsonDeserializer<@Nullable NeeoRoo
|
||||
@Nullable JsonDeserializationContext context) throws JsonParseException {
|
||||
Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
|
||||
Objects.requireNonNull(context, "context cannot be null");
|
||||
if (jsonElement instanceof JsonObject) {
|
||||
if (jsonElement instanceof JsonObject jsonObject) {
|
||||
final List<NeeoRoom> recipes = new ArrayList<>();
|
||||
for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
|
||||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||
final NeeoRoom room = context.deserialize(entry.getValue(), NeeoRoom.class);
|
||||
recipes.add(room);
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ public class NeeoScenariosDeserializer implements JsonDeserializer<@Nullable Nee
|
||||
@Nullable JsonDeserializationContext context) throws JsonParseException {
|
||||
Objects.requireNonNull(jsonElement, "jsonElement cannot be null");
|
||||
Objects.requireNonNull(context, "context cannot be null");
|
||||
if (jsonElement instanceof JsonObject) {
|
||||
if (jsonElement instanceof JsonObject jsonObject) {
|
||||
final List<NeeoScenario> scenarios = new ArrayList<>();
|
||||
for (Map.Entry<String, JsonElement> entry : ((JsonObject) jsonElement).entrySet()) {
|
||||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
|
||||
final NeeoScenario scenario = context.deserialize(entry.getValue(), NeeoScenario.class);
|
||||
scenarios.add(scenario);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user