Java 17 features (A-G) (#15516)
- 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:
@@ -63,9 +63,9 @@ public class AllPlayBindingProperties {
|
||||
private int getIntegerProperty(Dictionary<String, Object> properties, String propertyKey, int defaultValue) {
|
||||
Object configValue = properties.get(propertyKey);
|
||||
int value = defaultValue;
|
||||
if (configValue instanceof String) {
|
||||
if (configValue instanceof String stringValue) {
|
||||
try {
|
||||
value = Integer.parseInt((String) configValue);
|
||||
value = Integer.parseInt(stringValue);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn("Unable to convert value {} for config property {} to integer. Using default value.",
|
||||
configValue, propertyKey);
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.allplay.internal;
|
||||
|
||||
import static org.openhab.binding.allplay.internal.AllPlayBindingConstants.SPEAKER_THING_TYPE;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
@@ -54,7 +53,7 @@ public class AllPlayHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(AllPlayHandlerFactory.class);
|
||||
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(SPEAKER_THING_TYPE);
|
||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(SPEAKER_THING_TYPE);
|
||||
private final Map<String, ServiceRegistration<AudioSink>> audioSinkRegistrations = new ConcurrentHashMap<>();
|
||||
|
||||
private AllPlay allPlay;
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.allplay.internal.discovery;
|
||||
|
||||
import static org.openhab.binding.allplay.internal.AllPlayBindingConstants.SPEAKER_THING_TYPE;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -46,7 +45,7 @@ public class AllPlaySpeakerDiscoveryService extends AbstractDiscoveryService imp
|
||||
private final Logger logger = LoggerFactory.getLogger(AllPlaySpeakerDiscoveryService.class);
|
||||
|
||||
private static final int DISCOVERY_TIMEOUT = 30;
|
||||
private static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Collections.singleton(SPEAKER_THING_TYPE);
|
||||
private static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPES_UIDS = Set.of(SPEAKER_THING_TYPE);
|
||||
private AllPlay allPlay;
|
||||
|
||||
public AllPlaySpeakerDiscoveryService() {
|
||||
|
||||
@@ -343,8 +343,8 @@ public class AllPlayHandler extends BaseThingHandler
|
||||
* @throws SpeakerException Exception if the volume change failed
|
||||
*/
|
||||
public void handleVolumeCommand(Command command) throws SpeakerException {
|
||||
if (command instanceof PercentType) {
|
||||
speaker.volume().setVolume(convertPercentToAbsoluteVolume((PercentType) command));
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
speaker.volume().setVolume(convertPercentToAbsoluteVolume(percentCommand));
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
int stepSize = (command == IncreaseDecreaseType.DECREASE ? -getVolumeStepSize() : getVolumeStepSize());
|
||||
speaker.volume().adjustVolume(stepSize);
|
||||
|
||||
Reference in New Issue
Block a user