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:
@@ -422,7 +422,7 @@ public class GatewayWebTargets implements Closeable, HostnameVerifier {
|
||||
* @throws HubProcessingException if any error occurs.
|
||||
*/
|
||||
public void stopShade(int shadeId) throws HubProcessingException {
|
||||
invoke(HttpMethod.PUT, shadeStop, Query.of(IDS, Integer.valueOf(shadeId).toString()), null);
|
||||
invoke(HttpMethod.PUT, shadeStop, Query.of(IDS, Integer.toString(shadeId)), null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -147,10 +147,8 @@ public class AutomationChannelBuilder extends BaseChannelBuilder {
|
||||
String label = getScheduledEventName(referencedName, scheduledEvent);
|
||||
String description = translationProvider.getText("dynamic-channel.automation-enabled.description",
|
||||
referencedName);
|
||||
Channel channel = ChannelBuilder.create(channelUid, CoreItemFactory.SWITCH).withType(channelTypeUid)
|
||||
.withLabel(label).withDescription(description).build();
|
||||
|
||||
return channel;
|
||||
return ChannelBuilder.create(channelUid, CoreItemFactory.SWITCH).withType(channelTypeUid).withLabel(label)
|
||||
.withDescription(description).build();
|
||||
}
|
||||
|
||||
private @Nullable String getReferencedSceneOrSceneCollectionName(ScheduledEvent scheduledEvent) {
|
||||
|
||||
@@ -67,9 +67,9 @@ public class HDPowerViewCommandExtension extends AbstractConsoleCommandExtension
|
||||
|
||||
for (Thing thing : thingRegistry.getAll()) {
|
||||
ThingHandler thingHandler = thing.getHandler();
|
||||
if (thingHandler instanceof HDPowerViewHubHandler) {
|
||||
if (thingHandler instanceof HDPowerViewHubHandler hubHandler) {
|
||||
console.println("Generation 1/2 API hub: " + thing.getLabel());
|
||||
HDPowerViewWebTargets webTargets = ((HDPowerViewHubHandler) thingHandler).getWebTargets();
|
||||
HDPowerViewWebTargets webTargets = hubHandler.getWebTargets();
|
||||
|
||||
try {
|
||||
List<ShadeData> shades = webTargets.getShades().shadeData;
|
||||
@@ -90,9 +90,9 @@ public class HDPowerViewCommandExtension extends AbstractConsoleCommandExtension
|
||||
} catch (HubException e) {
|
||||
console.println("Error retrieving ID's: " + e.getMessage());
|
||||
}
|
||||
} else if (thingHandler instanceof GatewayBridgeHandler) {
|
||||
} else if (thingHandler instanceof GatewayBridgeHandler gatewayHandler) {
|
||||
console.println("Generation 3 API gateway: " + thing.getLabel());
|
||||
GatewayWebTargets webTargets = ((GatewayBridgeHandler) thingHandler).getWebTargets();
|
||||
GatewayWebTargets webTargets = gatewayHandler.getWebTargets();
|
||||
|
||||
try {
|
||||
List<Shade> shades = webTargets.getShades();
|
||||
|
||||
@@ -418,9 +418,9 @@ public class ShadeCapabilitiesDatabase {
|
||||
* @param propertyValue
|
||||
*/
|
||||
public void logPropertyMismatch(String propertyKey, int type, int capabilities, boolean propertyValue) {
|
||||
logger.warn(
|
||||
"The '{}:{}' property actually reported by shade 'type:{}' is different "
|
||||
+ "than expected from its 'capabilities:{}' in the database!{}",
|
||||
propertyKey, propertyValue, type, capabilities, REQUEST_DEVELOPERS_TO_UPDATE);
|
||||
logger.warn("""
|
||||
The '{}:{}' property actually reported by shade 'type:{}' is different \
|
||||
than expected from its 'capabilities:{}' in the database!{}\
|
||||
""", propertyKey, propertyValue, type, capabilities, REQUEST_DEVELOPERS_TO_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.hdpowerview.internal.discovery;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class HDPowerViewDeviceDiscoveryService extends AbstractDiscoveryService
|
||||
private final ShadeCapabilitiesDatabase db = new ShadeCapabilitiesDatabase();
|
||||
|
||||
public HDPowerViewDeviceDiscoveryService(HDPowerViewHubHandler hub) {
|
||||
super(Collections.singleton(HDPowerViewBindingConstants.THING_TYPE_SHADE), 60, true);
|
||||
super(Set.of(HDPowerViewBindingConstants.THING_TYPE_SHADE), 60, true);
|
||||
this.hub = hub;
|
||||
this.scanner = createScanner();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.hdpowerview.internal.discovery;
|
||||
|
||||
import static org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.jmdns.ServiceInfo;
|
||||
@@ -46,7 +45,7 @@ public class HDPowerViewHubDiscoveryParticipant implements MDNSDiscoveryParticip
|
||||
|
||||
@Override
|
||||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
|
||||
return Collections.singleton(THING_TYPE_HUB);
|
||||
return Set.of(THING_TYPE_HUB);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,7 @@ package org.openhab.binding.hdpowerview.internal.discovery;
|
||||
import static org.openhab.binding.hdpowerview.internal.HDPowerViewBindingConstants.*;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class HDPowerViewHubDiscoveryService extends AbstractDiscoveryService {
|
||||
private @Nullable ScheduledFuture<?> backgroundFuture;
|
||||
|
||||
public HDPowerViewHubDiscoveryService() {
|
||||
super(Collections.singleton(THING_TYPE_HUB), 60, true);
|
||||
super(Set.of(THING_TYPE_HUB), 60, true);
|
||||
scanner = createScanner();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.openhab.binding.hdpowerview.internal.discovery;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ShadeDiscoveryService extends AbstractDiscoveryService {
|
||||
private @Nullable ScheduledFuture<?> backgroundFuture;
|
||||
|
||||
public ShadeDiscoveryService(GatewayBridgeHandler hub) {
|
||||
super(Collections.singleton(HDPowerViewBindingConstants.THING_TYPE_SHADE3), 60, true);
|
||||
super(Set.of(HDPowerViewBindingConstants.THING_TYPE_SHADE3), 60, true);
|
||||
this.hub = hub;
|
||||
this.scanner = createScanner();
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ public class ShadePosition {
|
||||
if (shadeCapabilities.supportsPrimary() && shadeCapabilities.supportsSecondary()) {
|
||||
// on dual rail shades constrain percent to not move the lower rail above the upper
|
||||
State secondary = getState(shadeCapabilities, SECONDARY_POSITION);
|
||||
if (secondary instanceof PercentType) {
|
||||
int secPercent = ((PercentType) secondary).intValue();
|
||||
if (secondary instanceof PercentType percentCommand) {
|
||||
int secPercent = percentCommand.intValue();
|
||||
if (percent < secPercent) {
|
||||
percent = secPercent;
|
||||
}
|
||||
@@ -221,8 +221,8 @@ public class ShadePosition {
|
||||
if (shadeCapabilities.supportsPrimary() && shadeCapabilities.supportsSecondary()) {
|
||||
// on dual rail shades constrain percent to not move the upper rail below the lower
|
||||
State primary = getState(shadeCapabilities, PRIMARY_POSITION);
|
||||
if (primary instanceof PercentType) {
|
||||
int primaryPercent = ((PercentType) primary).intValue();
|
||||
if (primary instanceof PercentType percentCommand) {
|
||||
int primaryPercent = percentCommand.intValue();
|
||||
if (percent > primaryPercent) {
|
||||
percent = primaryPercent;
|
||||
}
|
||||
|
||||
@@ -20,5 +20,5 @@ package org.openhab.binding.hdpowerview.internal.dto.gen3;
|
||||
public enum PowerType {
|
||||
BATTERY,
|
||||
HARDWIRED,
|
||||
RECHARGEABLE;
|
||||
RECHARGEABLE
|
||||
}
|
||||
|
||||
@@ -88,8 +88,8 @@ public class GatewayBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) {
|
||||
if (childHandler instanceof ShadeThingHandler) {
|
||||
refreshShade(((ShadeThingHandler) childHandler).getShadeId());
|
||||
if (childHandler instanceof ShadeThingHandler shadeThingHandler) {
|
||||
refreshShade(shadeThingHandler.getShadeId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -601,8 +601,8 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||
continue;
|
||||
}
|
||||
ThingHandler handler = thing.getHandler();
|
||||
if (handler instanceof HDPowerViewShadeHandler) {
|
||||
((HDPowerViewShadeHandler) handler).requestRefreshShadePosition();
|
||||
if (handler instanceof HDPowerViewShadeHandler shadeHandler) {
|
||||
shadeHandler.requestRefreshShadePosition();
|
||||
} else {
|
||||
int shadeId = item.getValue();
|
||||
logger.debug("Shade '{}' handler not initialized", shadeId);
|
||||
@@ -620,8 +620,8 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
||||
continue;
|
||||
}
|
||||
ThingHandler handler = thing.getHandler();
|
||||
if (handler instanceof HDPowerViewShadeHandler) {
|
||||
((HDPowerViewShadeHandler) handler).requestRefreshShadeBatteryLevel();
|
||||
if (handler instanceof HDPowerViewShadeHandler shadeHandler) {
|
||||
shadeHandler.requestRefreshShadeBatteryLevel();
|
||||
} else {
|
||||
int shadeId = item.getValue();
|
||||
logger.debug("Shade '{}' handler not initialized", shadeId);
|
||||
|
||||
@@ -193,8 +193,8 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
||||
HubShadeTimeoutException {
|
||||
switch (channelId) {
|
||||
case CHANNEL_SHADE_POSITION:
|
||||
if (command instanceof PercentType) {
|
||||
moveShade(PRIMARY_POSITION, ((PercentType) command).intValue(), webTargets, shadeId);
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
moveShade(PRIMARY_POSITION, percentCommand.intValue(), webTargets, shadeId);
|
||||
} else if (command instanceof UpDownType) {
|
||||
moveShade(PRIMARY_POSITION, UpDownType.UP == command ? 0 : 100, webTargets, shadeId);
|
||||
} else if (command instanceof StopMoveType) {
|
||||
@@ -207,16 +207,16 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
||||
break;
|
||||
|
||||
case CHANNEL_SHADE_VANE:
|
||||
if (command instanceof PercentType) {
|
||||
moveShade(VANE_TILT_POSITION, ((PercentType) command).intValue(), webTargets, shadeId);
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
moveShade(VANE_TILT_POSITION, percentCommand.intValue(), webTargets, shadeId);
|
||||
} else if (command instanceof OnOffType) {
|
||||
moveShade(VANE_TILT_POSITION, OnOffType.ON == command ? 100 : 0, webTargets, shadeId);
|
||||
}
|
||||
break;
|
||||
|
||||
case CHANNEL_SHADE_SECONDARY_POSITION:
|
||||
if (command instanceof PercentType) {
|
||||
moveShade(SECONDARY_POSITION, ((PercentType) command).intValue(), webTargets, shadeId);
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
moveShade(SECONDARY_POSITION, percentCommand.intValue(), webTargets, shadeId);
|
||||
} else if (command instanceof UpDownType) {
|
||||
moveShade(SECONDARY_POSITION, UpDownType.UP == command ? 0 : 100, webTargets, shadeId);
|
||||
} else if (command instanceof StopMoveType) {
|
||||
@@ -229,11 +229,11 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
||||
break;
|
||||
|
||||
case CHANNEL_SHADE_COMMAND:
|
||||
if (command instanceof StringType) {
|
||||
if (COMMAND_IDENTIFY.equals(((StringType) command).toString())) {
|
||||
if (command instanceof StringType stringCommand) {
|
||||
if (COMMAND_IDENTIFY.equals(stringCommand.toString())) {
|
||||
logger.debug("Identify shade {}", shadeId);
|
||||
identifyShade(webTargets, shadeId);
|
||||
} else if (COMMAND_CALIBRATE.equals(((StringType) command).toString())) {
|
||||
} else if (COMMAND_CALIBRATE.equals(stringCommand.toString())) {
|
||||
logger.debug("Calibrate shade {}", shadeId);
|
||||
calibrateShade(webTargets, shadeId);
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ public class ShadeThingHandler extends BaseThingHandler {
|
||||
try {
|
||||
switch (channelUID.getId()) {
|
||||
case CHANNEL_SHADE_POSITION:
|
||||
if (command instanceof PercentType) {
|
||||
position.setPosition(PRIMARY_POSITION, ((PercentType) command));
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
position.setPosition(PRIMARY_POSITION, percentCommand);
|
||||
webTargets.moveShade(shadeId, new Shade().setShadePosition(position));
|
||||
break;
|
||||
} else if (command instanceof UpDownType) {
|
||||
@@ -134,8 +134,8 @@ public class ShadeThingHandler extends BaseThingHandler {
|
||||
throw new IllegalArgumentException(INVALID_COMMAND);
|
||||
|
||||
case CHANNEL_SHADE_SECONDARY_POSITION:
|
||||
if (command instanceof PercentType) {
|
||||
position.setPosition(SECONDARY_POSITION, ((PercentType) command));
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
position.setPosition(SECONDARY_POSITION, percentCommand);
|
||||
webTargets.moveShade(shadeId, new Shade().setShadePosition(position));
|
||||
break;
|
||||
} else if (command instanceof UpDownType) {
|
||||
@@ -153,8 +153,8 @@ public class ShadeThingHandler extends BaseThingHandler {
|
||||
throw new IllegalArgumentException(INVALID_COMMAND);
|
||||
|
||||
case CHANNEL_SHADE_VANE:
|
||||
if (command instanceof PercentType) {
|
||||
position.setPosition(VANE_TILT_POSITION, ((PercentType) command));
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
position.setPosition(VANE_TILT_POSITION, percentCommand);
|
||||
webTargets.moveShade(shadeId, new Shade().setShadePosition(position));
|
||||
break;
|
||||
} else if (command instanceof UpDownType) {
|
||||
@@ -166,7 +166,8 @@ public class ShadeThingHandler extends BaseThingHandler {
|
||||
throw new IllegalArgumentException(INVALID_COMMAND);
|
||||
|
||||
case CHANNEL_SHADE_COMMAND:
|
||||
if ((command instanceof StringType) && COMMAND_IDENTIFY.equals(((StringType) command).toString())) {
|
||||
if ((command instanceof StringType stringCommand)
|
||||
&& COMMAND_IDENTIFY.equals(stringCommand.toString())) {
|
||||
webTargets.jogShade(shadeId);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.openhab.core.i18n.LocaleProvider;
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class MockedLocaleProvider implements LocaleProvider {
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
return Locale.ENGLISH;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user