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:
Holger Friedrich
2023-09-13 08:03:31 +02:00
committed by GitHub
parent 641b482551
commit ab58f4ffb4
471 changed files with 1624 additions and 1868 deletions

View File

@@ -155,7 +155,7 @@ public class PS3Handler extends BaseThingHandler {
private void wakeMethod(DatagramPacket srchPacket, DatagramPacket receivePacket, DatagramPacket wakePacket,
int triesLeft) {
try (DatagramSocket searchSocket = new DatagramSocket(); DatagramSocket wakeSocket = new DatagramSocket();) {
try (DatagramSocket searchSocket = new DatagramSocket(); DatagramSocket wakeSocket = new DatagramSocket()) {
wakeSocket.setBroadcast(true);
searchSocket.setBroadcast(true);
searchSocket.setSoTimeout(1000);

View File

@@ -48,14 +48,17 @@ public class PS4Crypto {
private final Logger logger = LoggerFactory.getLogger(PS4Crypto.class);
// Public key is from ps4-waker (https://github.com/dhleong/ps4-waker)
private static final String PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----"
+ "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxfAO/MDk5ovZpp7xlG9J"
+ "JKc4Sg4ztAz+BbOt6Gbhub02tF9bryklpTIyzM0v817pwQ3TCoigpxEcWdTykhDL"
+ "cGhAbcp6E7Xh8aHEsqgtQ/c+wY1zIl3fU//uddlB1XuipXthDv6emXsyyU/tJWqc"
+ "zy9HCJncLJeYo7MJvf2TE9nnlVm1x4flmD0k1zrvb3MONqoZbKb/TQVuVhBv7SM+"
+ "U5PSi3diXIx1Nnj4vQ8clRNUJ5X1tT9XfVmKQS1J513XNZ0uYHYRDzQYujpLWucu"
+ "ob7v50wCpUm3iKP1fYCixMP6xFm0jPYz1YQaMV35VkYwc40qgk3av0PDS+1G0dCm" + "swIDAQAB"
+ "-----END PUBLIC KEY-----";
private static final String PUBLIC_KEY = """
-----BEGIN PUBLIC KEY-----\
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxfAO/MDk5ovZpp7xlG9J\
JKc4Sg4ztAz+BbOt6Gbhub02tF9bryklpTIyzM0v817pwQ3TCoigpxEcWdTykhDL\
cGhAbcp6E7Xh8aHEsqgtQ/c+wY1zIl3fU//uddlB1XuipXthDv6emXsyyU/tJWqc\
zy9HCJncLJeYo7MJvf2TE9nnlVm1x4flmD0k1zrvb3MONqoZbKb/TQVuVhBv7SM+\
U5PSi3diXIx1Nnj4vQ8clRNUJ5X1tT9XfVmKQS1J513XNZ0uYHYRDzQYujpLWucu\
ob7v50wCpUm3iKP1fYCixMP6xFm0jPYz1YQaMV35VkYwc40qgk3av0PDS+1G0dCm\
swIDAQAB\
-----END PUBLIC KEY-----\
""";
private final byte[] remoteSeed = new byte[16];
private final byte[] randomSeed = new byte[16];

View File

@@ -120,20 +120,20 @@ public class PS4Handler extends BaseThingHandler {
if (command instanceof RefreshType) {
refreshFromState(channelUID);
} else {
if (command instanceof StringType) {
if (command instanceof StringType stringCommand) {
switch (channelUID.getId()) {
case CHANNEL_APPLICATION_ID:
if (!currentApplicationId.equals(((StringType) command).toString())) {
updateApplicationTitleid(((StringType) command).toString());
if (!currentApplicationId.equals(stringCommand.toString())) {
updateApplicationTitleid(stringCommand.toString());
startApplication(currentApplicationId);
}
break;
case CHANNEL_OSK_TEXT:
setOSKText(((StringType) command).toString());
setOSKText(stringCommand.toString());
break;
case CHANNEL_SEND_KEY:
int ps4Key = 0;
switch (((StringType) command).toString()) {
switch (stringCommand.toString()) {
case SEND_KEY_UP:
ps4Key = PS4_KEY_UP;
break;
@@ -168,12 +168,11 @@ public class PS4Handler extends BaseThingHandler {
default:
break;
}
} else if (command instanceof OnOffType) {
OnOffType onOff = (OnOffType) command;
} else if (command instanceof OnOffType onOffCommand) {
switch (channelUID.getId()) {
case CHANNEL_POWER:
if (currentPower != onOff) {
currentPower = onOff;
if (currentPower != onOffCommand) {
currentPower = onOffCommand;
if (currentPower.equals(OnOffType.ON)) {
turnOnPS4();
} else if (currentPower.equals(OnOffType.OFF)) {
@@ -183,9 +182,9 @@ public class PS4Handler extends BaseThingHandler {
break;
case CHANNEL_CONNECT:
boolean connected = socketChannelHandler != null && socketChannelHandler.isChannelOpen();
if (connected && onOff.equals(OnOffType.OFF)) {
if (connected && onOffCommand.equals(OnOffType.OFF)) {
sendByeBye();
} else if (!connected && onOff.equals(OnOffType.ON)) {
} else if (!connected && onOffCommand.equals(OnOffType.ON)) {
scheduler.execute(() -> login());
}
break;

View File

@@ -254,7 +254,7 @@ public class PlayStationDiscovery extends AbstractDiscoveryService {
properties.put(Thing.PROPERTY_HARDWARE_VERSION, hwVersion);
properties.put(Thing.PROPERTY_FIRMWARE_VERSION, formatPS4Version(systemVersion));
properties.put(Thing.PROPERTY_MAC_ADDRESS, hostIdToMacAddress(hostId));
ThingUID uid = hostType.equalsIgnoreCase("PS5") ? new ThingUID(THING_TYPE_PS5, hostId)
ThingUID uid = "PS5".equalsIgnoreCase(hostType) ? new ThingUID(THING_TYPE_PS5, hostId)
: new ThingUID(THING_TYPE_PS4, hostId);
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(hostName)
@@ -408,10 +408,10 @@ public class PlayStationDiscovery extends AbstractDiscoveryService {
hwVersion = PS4HW_CUH1000;
break;
case "bc60a7": // Ethernet
if (ethId.equals("7b")) {
if ("7b".equals(ethId)) {
hwVersion = PS4HW_CUH2000;
}
if (ethId.equals("8f")) {
if ("8f".equals(ethId)) {
hwVersion = PS4HW_CUH7000;
}
break;
@@ -423,10 +423,10 @@ public class PlayStationDiscovery extends AbstractDiscoveryService {
break;
case "40490f": // WiFi
case "5c9656": // WiFi
if (ethId.equals("07")) {
if ("07".equals(ethId)) {
hwVersion = PS4HW_CUH2000;
}
if (ethId.equals("da")) {
if ("da".equals(ethId)) {
hwVersion = PS4HW_CUH7000;
}
break;