Java 17 features (T-Z) (#15576)
- 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:
@@ -168,16 +168,16 @@ public class WebexTeamsActions implements ThingActions {
|
||||
}
|
||||
|
||||
public static boolean sendMessage(@Nullable ThingActions actions, @Nullable String text) {
|
||||
if (actions instanceof WebexTeamsActions) {
|
||||
return ((WebexTeamsActions) actions).sendMessage(text);
|
||||
if (actions instanceof WebexTeamsActions teamsActions) {
|
||||
return teamsActions.sendMessage(text);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean sendMessage(@Nullable ThingActions actions, @Nullable String text, @Nullable String attach) {
|
||||
if (actions instanceof WebexTeamsActions) {
|
||||
return ((WebexTeamsActions) actions).sendMessage(text, attach);
|
||||
if (actions instanceof WebexTeamsActions teamsActions) {
|
||||
return teamsActions.sendMessage(text, attach);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
|
||||
}
|
||||
@@ -185,8 +185,8 @@ public class WebexTeamsActions implements ThingActions {
|
||||
|
||||
public static boolean sendRoomMessage(@Nullable ThingActions actions, @Nullable String roomId,
|
||||
@Nullable String text) {
|
||||
if (actions instanceof WebexTeamsActions) {
|
||||
return ((WebexTeamsActions) actions).sendRoomMessage(roomId, text);
|
||||
if (actions instanceof WebexTeamsActions teamsActions) {
|
||||
return teamsActions.sendRoomMessage(roomId, text);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
|
||||
}
|
||||
@@ -194,8 +194,8 @@ public class WebexTeamsActions implements ThingActions {
|
||||
|
||||
public static boolean sendRoomMessage(@Nullable ThingActions actions, @Nullable String roomId,
|
||||
@Nullable String text, @Nullable String attach) {
|
||||
if (actions instanceof WebexTeamsActions) {
|
||||
return ((WebexTeamsActions) actions).sendRoomMessage(roomId, text, attach);
|
||||
if (actions instanceof WebexTeamsActions teamsActions) {
|
||||
return teamsActions.sendRoomMessage(roomId, text, attach);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
|
||||
}
|
||||
@@ -203,8 +203,8 @@ public class WebexTeamsActions implements ThingActions {
|
||||
|
||||
public static boolean sendPersonMessage(@Nullable ThingActions actions, @Nullable String personEmail,
|
||||
@Nullable String text) {
|
||||
if (actions instanceof WebexTeamsActions) {
|
||||
return ((WebexTeamsActions) actions).sendPersonMessage(personEmail, text);
|
||||
if (actions instanceof WebexTeamsActions teamsActions) {
|
||||
return teamsActions.sendPersonMessage(personEmail, text);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
|
||||
}
|
||||
@@ -212,8 +212,8 @@ public class WebexTeamsActions implements ThingActions {
|
||||
|
||||
public static boolean sendPersonMessage(@Nullable ThingActions actions, @Nullable String personEmail,
|
||||
@Nullable String text, @Nullable String attach) {
|
||||
if (actions instanceof WebexTeamsActions) {
|
||||
return ((WebexTeamsActions) actions).sendPersonMessage(personEmail, text, attach);
|
||||
if (actions instanceof WebexTeamsActions teamsActions) {
|
||||
return teamsActions.sendPersonMessage(personEmail, text, attach);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
|
||||
}
|
||||
@@ -221,8 +221,8 @@ public class WebexTeamsActions implements ThingActions {
|
||||
|
||||
@Override
|
||||
public void setThingHandler(@Nullable ThingHandler handler) {
|
||||
if (handler instanceof WebexTeamsHandler) {
|
||||
this.handler = (WebexTeamsHandler) handler;
|
||||
if (handler instanceof WebexTeamsHandler teamsHandler) {
|
||||
this.handler = teamsHandler;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -90,7 +90,7 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
|
||||
// creates list of available Actions
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singletonList(WebexTeamsActions.class);
|
||||
return List.of(WebexTeamsActions.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,8 +74,8 @@ public class WebexTeamsHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
@Override
|
||||
protected synchronized void removeHandler(ThingHandler thingHandler) {
|
||||
if (thingHandler instanceof WebexTeamsHandler) {
|
||||
authService.removeWebexTeamsHandler((WebexTeamsHandler) thingHandler);
|
||||
if (thingHandler instanceof WebexTeamsHandler webexTeamsHandler) {
|
||||
authService.removeWebexTeamsHandler(webexTeamsHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,7 @@ public class WebexTeamsApi {
|
||||
public Person getPerson() throws WebexTeamsApiException, WebexAuthenticationException {
|
||||
URI url = getUri(WEBEX_API_ENDPOINT + "/people/me");
|
||||
|
||||
Person person = request(url, HttpMethod.GET, Person.class, null);
|
||||
return person;
|
||||
return request(url, HttpMethod.GET, Person.class, null);
|
||||
}
|
||||
|
||||
private URI getUri(String url) throws WebexTeamsApiException {
|
||||
@@ -133,8 +132,7 @@ public class WebexTeamsApi {
|
||||
// Obtain the input stream on the response content
|
||||
try (InputStream input = new ByteArrayInputStream(response.getContent())) {
|
||||
Reader reader = new InputStreamReader(input);
|
||||
O entity = gson.fromJson(reader, clazz);
|
||||
return entity;
|
||||
return gson.fromJson(reader, clazz);
|
||||
} catch (IOException | JsonIOException | JsonSyntaxException e) {
|
||||
logger.warn("Exception while processing API response: {}", e.getMessage());
|
||||
throw new WebexTeamsApiException("Exception while processing API response", e);
|
||||
|
||||
Reference in New Issue
Block a user