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:
@@ -64,8 +64,7 @@ public class OJCloudHandlerFactory extends BaseThingHandlerFactory {
|
||||
@Override
|
||||
protected @Nullable ThingHandler createHandler(Thing thing) {
|
||||
if (SUPPORTED_THING_TYPES_UIDS.contains(thing.getThingTypeUID())) {
|
||||
OJCloudHandler handler = new OJCloudHandler((Bridge) thing, httpClient);
|
||||
return handler;
|
||||
return new OJCloudHandler((Bridge) thing, httpClient);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -197,8 +197,8 @@ public class ThermostatHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void updateManualSetpoint(Command command) {
|
||||
if (command instanceof QuantityType<?>) {
|
||||
getCurrentThermostat().manualModeSetpoint = (int) (((QuantityType<?>) command).floatValue() * 100);
|
||||
if (command instanceof QuantityType<?> quantityCommand) {
|
||||
getCurrentThermostat().manualModeSetpoint = (int) (quantityCommand.floatValue() * 100);
|
||||
} else {
|
||||
logger.warn("Unable to set value {}", command);
|
||||
}
|
||||
@@ -210,8 +210,8 @@ public class ThermostatHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void updateBoostEndTime(Command command) {
|
||||
if (command instanceof DateTimeType) {
|
||||
getCurrentThermostat().boostEndTime = Date.from(((DateTimeType) command).getZonedDateTime().toInstant());
|
||||
if (command instanceof DateTimeType dateTimeCommand) {
|
||||
getCurrentThermostat().boostEndTime = Date.from(dateTimeCommand.getZonedDateTime().toInstant());
|
||||
} else {
|
||||
logger.warn("Unable to set value {}", command);
|
||||
}
|
||||
@@ -223,9 +223,9 @@ public class ThermostatHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void updateComfortEndTime(Command command) {
|
||||
if (command instanceof DateTimeType) {
|
||||
if (command instanceof DateTimeType dateTimeCommand) {
|
||||
getCurrentThermostat().comfortEndTime = Objects
|
||||
.requireNonNull(Date.from(((DateTimeType) command).getZonedDateTime().toInstant()));
|
||||
.requireNonNull(Date.from(dateTimeCommand.getZonedDateTime().toInstant()));
|
||||
} else {
|
||||
logger.warn("Unable to set value {}", command);
|
||||
}
|
||||
@@ -237,8 +237,8 @@ public class ThermostatHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void updateComfortSetpoint(Command command) {
|
||||
if (command instanceof QuantityType<?>) {
|
||||
getCurrentThermostat().comfortSetpoint = (int) (((QuantityType<?>) command).floatValue() * 100);
|
||||
if (command instanceof QuantityType<?> quantityCommand) {
|
||||
getCurrentThermostat().comfortSetpoint = (int) (quantityCommand.floatValue() * 100);
|
||||
} else {
|
||||
logger.warn("Unable to set value {}", command);
|
||||
}
|
||||
@@ -325,9 +325,9 @@ public class ThermostatHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void updateVacationBeginDay(Command command) {
|
||||
if (command instanceof DateTimeType) {
|
||||
if (command instanceof DateTimeType dateTimeCommand) {
|
||||
getCurrentThermostat().vacationBeginDay = Date
|
||||
.from(((DateTimeType) command).getZonedDateTime().toInstant().truncatedTo(ChronoUnit.DAYS));
|
||||
.from(dateTimeCommand.getZonedDateTime().toInstant().truncatedTo(ChronoUnit.DAYS));
|
||||
} else {
|
||||
logger.warn("Unable to set value {}", command);
|
||||
}
|
||||
@@ -341,9 +341,9 @@ public class ThermostatHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
private void updateVacationEndDay(Command command) {
|
||||
if (command instanceof DateTimeType) {
|
||||
if (command instanceof DateTimeType dateTimeCommand) {
|
||||
getCurrentThermostat().vacationEndDay = Date
|
||||
.from(((DateTimeType) command).getZonedDateTime().toInstant().truncatedTo(ChronoUnit.DAYS));
|
||||
.from(dateTimeCommand.getZonedDateTime().toInstant().truncatedTo(ChronoUnit.DAYS));
|
||||
} else {
|
||||
logger.warn("Unable to set value {}", command);
|
||||
}
|
||||
|
||||
@@ -73,8 +73,7 @@ public final class OJDiscoveryService extends AbstractDiscoveryService implement
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof OJCloudHandler) {
|
||||
final OJCloudHandler bridgeHandler = (OJCloudHandler) handler;
|
||||
if (handler instanceof OJCloudHandler bridgeHandler) {
|
||||
this.bridgeHandler = bridgeHandler;
|
||||
bridgeHandler.setDiscoveryService(this);
|
||||
}
|
||||
|
||||
@@ -196,9 +196,8 @@ public final class RefreshService implements AutoCloseable {
|
||||
}
|
||||
|
||||
private Request createRequest() {
|
||||
Request request = httpClient.newRequest(config.getRestApiUrl() + "/Group/GroupContents")
|
||||
.param("sessionid", sessionId).param("apiKey", config.apiKey).method(HttpMethod.GET);
|
||||
return request;
|
||||
return httpClient.newRequest(config.getRestApiUrl() + "/Group/GroupContents").param("sessionid", sessionId)
|
||||
.param("apiKey", config.apiKey).method(HttpMethod.GET);
|
||||
}
|
||||
|
||||
private void initializationDone(String responseBody) {
|
||||
|
||||
@@ -90,7 +90,7 @@ public class SignInService {
|
||||
if (result.getResponse().getStatus() == 200) {
|
||||
PostSignInResponseModel signInModel = Objects
|
||||
.requireNonNull(gson.fromJson(getContentAsString(), PostSignInResponseModel.class));
|
||||
if (signInModel.errorCode != 0 || signInModel.sessionId.equals("")) {
|
||||
if (signInModel.errorCode != 0 || "".equals(signInModel.sessionId)) {
|
||||
unauthorized.run();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user