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:
@@ -264,8 +264,8 @@ public class HydrawiseGraphQLClient {
|
||||
private void sendGraphQLMutation(String content)
|
||||
throws HydrawiseConnectionException, HydrawiseAuthenticationException, HydrawiseCommandException {
|
||||
Mutation mutation = new Mutation(content);
|
||||
logger.debug("Sending Mutation {}", gson.toJson(mutation).toString());
|
||||
String response = sendGraphQLRequest(gson.toJson(mutation).toString());
|
||||
logger.debug("Sending Mutation {}", gson.toJson(mutation));
|
||||
String response = sendGraphQLRequest(gson.toJson(mutation));
|
||||
logger.debug("Mutation response {}", response);
|
||||
try {
|
||||
MutationResponse mResponse = gson.fromJson(response, MutationResponse.class);
|
||||
@@ -273,7 +273,7 @@ public class HydrawiseGraphQLClient {
|
||||
throw new HydrawiseCommandException("Malformed response: " + response);
|
||||
}
|
||||
Optional<MutationResponseStatus> status = mResponse.data.values().stream().findFirst();
|
||||
if (!status.isPresent()) {
|
||||
if (status.isEmpty()) {
|
||||
throw new HydrawiseCommandException("Unknown response: " + response);
|
||||
}
|
||||
if (status.get().status != StatusCode.OK) {
|
||||
|
||||
@@ -27,6 +27,6 @@ public class MutationResponse {
|
||||
public enum StatusCode {
|
||||
OK,
|
||||
WARNING,
|
||||
ERROR;
|
||||
ERROR
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,7 @@ public class HydrawiseLocalApiClient {
|
||||
public LocalScheduleResponse getLocalSchedule()
|
||||
throws HydrawiseConnectionException, HydrawiseAuthenticationException {
|
||||
String json = doGet(localGetURL);
|
||||
LocalScheduleResponse response = gson.fromJson(json, LocalScheduleResponse.class);
|
||||
return response;
|
||||
return gson.fromJson(json, LocalScheduleResponse.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +190,7 @@ public class HydrawiseLocalApiClient {
|
||||
throws HydrawiseConnectionException, HydrawiseAuthenticationException, HydrawiseCommandException {
|
||||
String json = doGet(url);
|
||||
SetZoneResponse response = gson.fromJson(json, SetZoneResponse.class);
|
||||
if (response.messageType.equals("error")) {
|
||||
if ("error".equals(response.messageType)) {
|
||||
throw new HydrawiseCommandException(response.message);
|
||||
}
|
||||
return response.message;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
*/
|
||||
package org.openhab.binding.hydrawise.internal.discovery;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@@ -46,7 +46,7 @@ public class HydrawiseCloudControllerDiscoveryService extends AbstractDiscoveryS
|
||||
HydrawiseAccountHandler handler;
|
||||
|
||||
public HydrawiseCloudControllerDiscoveryService() {
|
||||
super(Collections.singleton(HydrawiseBindingConstants.THING_TYPE_CONTROLLER), TIMEOUT, true);
|
||||
super(Set.of(HydrawiseBindingConstants.THING_TYPE_CONTROLLER), TIMEOUT, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,8 +103,7 @@ public class HydrawiseCloudControllerDiscoveryService extends AbstractDiscoveryS
|
||||
String.valueOf(id));
|
||||
thingDiscovered(DiscoveryResultBuilder.create(thingUID).withLabel(label).withBridge(bridgeUID)
|
||||
.withProperty(HydrawiseBindingConstants.CONFIG_CONTROLLER_ID, id)
|
||||
.withRepresentationProperty(String.valueOf(HydrawiseBindingConstants.CONFIG_CONTROLLER_ID))
|
||||
.build());
|
||||
.withRepresentationProperty(HydrawiseBindingConstants.CONFIG_CONTROLLER_ID).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -122,7 +123,7 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(HydrawiseCloudControllerDiscoveryService.class);
|
||||
return Set.of(HydrawiseCloudControllerDiscoveryService.class);
|
||||
}
|
||||
|
||||
public void addControllerListeners(HydrawiseControllerListener listener) {
|
||||
@@ -209,7 +210,7 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
|
||||
if (response == null) {
|
||||
throw new HydrawiseConnectionException("Malformed response");
|
||||
}
|
||||
if (response.errors != null && response.errors.size() > 0) {
|
||||
if (response.errors != null && !response.errors.isEmpty()) {
|
||||
throw new HydrawiseConnectionException(response.errors.stream().map(error -> error.message).reduce("",
|
||||
(messages, message) -> messages + message + ". "));
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ public class HydrawiseLocalHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
updateGroupState(CHANNEL_GROUP_ALLZONES, CHANNEL_ZONE_RUN,
|
||||
status.running.size() > 0 ? OnOffType.ON : OnOffType.OFF);
|
||||
!status.running.isEmpty() ? OnOffType.ON : OnOffType.OFF);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user