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:
@@ -226,7 +226,6 @@ public class AmcrestHandler extends ChannelDuplexHandler {
|
||||
// If a camera does not need to poll a request as often as snapshots, it can be
|
||||
// added here. Binding steps through the list.
|
||||
public ArrayList<String> getLowPriorityRequests() {
|
||||
ArrayList<String> lowPriorityRequests = new ArrayList<String>(1);
|
||||
return lowPriorityRequests;
|
||||
return new ArrayList<String>(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,6 @@ public class DoorBirdHandler extends ChannelDuplexHandler {
|
||||
// If a camera does not need to poll a request as often as snapshots, it can be
|
||||
// added here. Binding steps through the list.
|
||||
public ArrayList<String> getLowPriorityRequests() {
|
||||
ArrayList<String> lowPriorityRequests = new ArrayList<String>(1);
|
||||
return lowPriorityRequests;
|
||||
return new ArrayList<String>(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,9 +123,9 @@ public class Helper {
|
||||
for (Enumeration<InetAddress> enumIpAddr = networkInterface.getInetAddresses(); enumIpAddr
|
||||
.hasMoreElements();) {
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (!inetAddress.isLoopbackAddress() && inetAddress.getHostAddress().toString().length() < 18
|
||||
if (!inetAddress.isLoopbackAddress() && inetAddress.getHostAddress().length() < 18
|
||||
&& inetAddress.isSiteLocalAddress()) {
|
||||
ipAddress = inetAddress.getHostAddress().toString();
|
||||
ipAddress = inetAddress.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,8 +197,8 @@ public class InstarHandler extends ChannelDuplexHandler {
|
||||
ipCameraHandler.sendHttpGET("/param.cgi?cmd=setaudioalarmattr&enable=0");
|
||||
} else if (OnOffType.ON.equals(command)) {
|
||||
ipCameraHandler.sendHttpGET("/param.cgi?cmd=setaudioalarmattr&enable=1");
|
||||
} else if (command instanceof PercentType) {
|
||||
int value = ((PercentType) command).toBigDecimal().divide(BigDecimal.TEN).intValue();
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
int value = percentCommand.toBigDecimal().divide(BigDecimal.TEN).intValue();
|
||||
ipCameraHandler.sendHttpGET("/param.cgi?cmd=setaudioalarmattr&enable=1&threshold=" + value);
|
||||
}
|
||||
return;
|
||||
@@ -253,8 +253,8 @@ public class InstarHandler extends ChannelDuplexHandler {
|
||||
ipCameraHandler.sendHttpGET("/cgi-bin/hi3510/param.cgi?cmd=setaudioalarmattr&-aa_enable=0");
|
||||
} else if (OnOffType.ON.equals(command)) {
|
||||
ipCameraHandler.sendHttpGET("/cgi-bin/hi3510/param.cgi?cmd=setaudioalarmattr&-aa_enable=1");
|
||||
} else if (command instanceof PercentType) {
|
||||
int value = ((PercentType) command).toBigDecimal().divide(BigDecimal.TEN).intValue();
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
int value = percentCommand.toBigDecimal().divide(BigDecimal.TEN).intValue();
|
||||
ipCameraHandler.sendHttpGET(
|
||||
"/cgi-bin/hi3510/param.cgi?cmd=setaudioalarmattr&-aa_enable=1&-aa_value=" + value * 10);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class IpCameraBindingConstants {
|
||||
public static final String INSTAR_HANDLER = "instarHandler";
|
||||
public static final String REOLINK_HANDLER = "reolinkHandler";
|
||||
|
||||
public static enum FFmpegFormat {
|
||||
public enum FFmpegFormat {
|
||||
HLS,
|
||||
GIF,
|
||||
RECORD,
|
||||
|
||||
@@ -145,15 +145,14 @@ public class MyNettyAuthHandler extends ChannelDuplexHandler {
|
||||
if (msg == null || ctx == null) {
|
||||
return;
|
||||
}
|
||||
if (msg instanceof HttpResponse) {
|
||||
HttpResponse response = (HttpResponse) msg;
|
||||
if (msg instanceof HttpResponse response) {
|
||||
if (response.status().code() == 401) {
|
||||
ctx.close();
|
||||
if (!response.headers().isEmpty()) {
|
||||
String authenticate = "";
|
||||
for (CharSequence name : response.headers().names()) {
|
||||
for (CharSequence value : response.headers().getAll(name)) {
|
||||
if (name.toString().equalsIgnoreCase("WWW-Authenticate")) {
|
||||
if ("WWW-Authenticate".equalsIgnoreCase(name.toString())) {
|
||||
authenticate = value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,8 +242,8 @@ public class ReolinkHandler extends ChannelDuplexHandler {
|
||||
ipCameraHandler.sendHttpPOST("/api.cgi?cmd=SetWhiteLed" + ipCameraHandler.reolinkAuth,
|
||||
"[{\"cmd\": \"SetWhiteLed\",\"param\": {\"WhiteLed\": {\"state\": 1,\"channel\": "
|
||||
+ ipCameraHandler.cameraConfig.getNvrChannel() + ",\"mode\": 1}}}]");
|
||||
} else if (command instanceof PercentType) {
|
||||
int value = ((PercentType) command).toBigDecimal().intValue();
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
int value = percentCommand.toBigDecimal().intValue();
|
||||
ipCameraHandler.sendHttpPOST("/api.cgi?cmd=SetWhiteLed" + ipCameraHandler.reolinkAuth,
|
||||
"[{\"cmd\": \"SetWhiteLed\",\"param\": {\"WhiteLed\": {\"state\": 1,\"channel\": "
|
||||
+ ipCameraHandler.cameraConfig.getNvrChannel() + ",\"mode\": 1,\"bright\": " + value
|
||||
|
||||
@@ -28,10 +28,10 @@ import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -218,8 +218,7 @@ public class IpCameraHandler extends BaseThingHandler {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (msg instanceof HttpResponse) {
|
||||
HttpResponse response = (HttpResponse) msg;
|
||||
if (msg instanceof HttpResponse response) {
|
||||
if (response.status().code() == 200) {
|
||||
if (!response.headers().isEmpty()) {
|
||||
for (String name : response.headers().names()) {
|
||||
@@ -264,8 +263,7 @@ public class IpCameraHandler extends BaseThingHandler {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (msg instanceof HttpContent) {
|
||||
HttpContent content = (HttpContent) msg;
|
||||
if (msg instanceof HttpContent content) {
|
||||
if (mjpegUri.equals(requestUrl) && !(content instanceof LastHttpContent)) {
|
||||
// multiple MJPEG stream packets come back as this.
|
||||
byte[] chunkedFrame = new byte[content.content().readableBytes()];
|
||||
@@ -368,8 +366,7 @@ public class IpCameraHandler extends BaseThingHandler {
|
||||
if (ctx == null) {
|
||||
return;
|
||||
}
|
||||
if (evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent e = (IdleStateEvent) evt;
|
||||
if (evt instanceof IdleStateEvent e) {
|
||||
// If camera does not use the channel for X amount of time it will close.
|
||||
if (e.state() == IdleState.READER_IDLE) {
|
||||
String urlToKeepOpen = "";
|
||||
@@ -1154,9 +1151,9 @@ public class IpCameraHandler extends BaseThingHandler {
|
||||
} else if (OnOffType.OFF.equals(command) || DecimalType.ZERO.equals(command)) {
|
||||
ffmpegMotionAlarmEnabled = false;
|
||||
noMotionDetected(CHANNEL_FFMPEG_MOTION_ALARM);
|
||||
} else if (command instanceof PercentType) {
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
ffmpegMotionAlarmEnabled = true;
|
||||
motionThreshold = ((PercentType) command).toBigDecimal();
|
||||
motionThreshold = percentCommand.toBigDecimal();
|
||||
}
|
||||
setupFfmpegFormat(FFmpegFormat.RTSP_ALARMS);
|
||||
return;
|
||||
@@ -1887,6 +1884,6 @@ public class IpCameraHandler extends BaseThingHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(IpCameraActions.class);
|
||||
return Set.of(IpCameraActions.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ public class OnvifCodec extends ChannelDuplexHandler {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (msg instanceof HttpContent) {
|
||||
HttpContent content = (HttpContent) msg;
|
||||
if (msg instanceof HttpContent content) {
|
||||
incomingMessage += content.content().toString(CharsetUtil.UTF_8);
|
||||
}
|
||||
if (msg instanceof LastHttpContent) {
|
||||
|
||||
@@ -72,7 +72,7 @@ import io.netty.handler.timeout.IdleStateHandler;
|
||||
|
||||
@NonNullByDefault
|
||||
public class OnvifConnection {
|
||||
public static enum RequestType {
|
||||
public enum RequestType {
|
||||
AbsoluteMove,
|
||||
AddPTZConfiguration,
|
||||
ContinuousMoveLeft,
|
||||
|
||||
@@ -86,7 +86,7 @@ public class OnvifDiscovery {
|
||||
for (Enumeration<InetAddress> enumIpAddr = networkInterface.getInetAddresses(); enumIpAddr
|
||||
.hasMoreElements();) {
|
||||
InetAddress inetAddress = enumIpAddr.nextElement();
|
||||
if (!inetAddress.isLoopbackAddress() && inetAddress.getHostAddress().toString().length() < 18
|
||||
if (!inetAddress.isLoopbackAddress() && inetAddress.getHostAddress().length() < 18
|
||||
&& inetAddress.isSiteLocalAddress()) {
|
||||
if (inetAddress.getHostAddress().equals(primaryHostAddress)) {
|
||||
results.add(networkInterface);
|
||||
|
||||
Reference in New Issue
Block a user