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:
@@ -225,8 +225,8 @@ public class PulseaudioClient {
|
||||
*/
|
||||
public @Nullable Sink getSink(String name) {
|
||||
for (AbstractAudioDeviceConfig item : items) {
|
||||
if (item.getPaName().equalsIgnoreCase(name) && item instanceof Sink) {
|
||||
return (Sink) item;
|
||||
if (item.getPaName().equalsIgnoreCase(name) && item instanceof Sink sink) {
|
||||
return sink;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -239,8 +239,8 @@ public class PulseaudioClient {
|
||||
*/
|
||||
public @Nullable Sink getSink(int id) {
|
||||
for (AbstractAudioDeviceConfig item : items) {
|
||||
if (item.getId() == id && item instanceof Sink) {
|
||||
return (Sink) item;
|
||||
if (item.getId() == id && item instanceof Sink sink) {
|
||||
return sink;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -253,8 +253,8 @@ public class PulseaudioClient {
|
||||
*/
|
||||
public @Nullable Source getSource(int id) {
|
||||
for (AbstractAudioDeviceConfig item : items) {
|
||||
if (item.getId() == id && item instanceof Source) {
|
||||
return (Source) item;
|
||||
if (item.getId() == id && item instanceof Source source) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -362,8 +362,10 @@ public class PulseaudioClient {
|
||||
currentTry++;
|
||||
} while (currentTry < 3);
|
||||
|
||||
logger.warn("The pulseaudio binding tried 3 times to load the module-simple-protocol-tcp"
|
||||
+ " on random port on the pulseaudio server and give up trying");
|
||||
logger.warn("""
|
||||
The pulseaudio binding tried 3 times to load the module-simple-protocol-tcp\
|
||||
on random port on the pulseaudio server and give up trying\
|
||||
""");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +83,8 @@ public class PulseaudioDeviceDiscoveryService extends AbstractDiscoveryService i
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
// All devices need this parameter
|
||||
properties.put(PulseaudioBindingConstants.DEVICE_PARAMETER_NAME_OR_DESCRIPTION, uidName);
|
||||
if (device instanceof Sink) {
|
||||
if (((Sink) device).isCombinedSink()) {
|
||||
if (device instanceof Sink sink) {
|
||||
if (sink.isCombinedSink()) {
|
||||
thingType = PulseaudioBindingConstants.COMBINED_SINK_THING_TYPE;
|
||||
} else {
|
||||
thingType = PulseaudioBindingConstants.SINK_THING_TYPE;
|
||||
|
||||
@@ -16,7 +16,6 @@ import static org.openhab.binding.pulseaudio.internal.PulseaudioBindingConstants
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -57,8 +56,8 @@ import org.slf4j.LoggerFactory;
|
||||
public class PulseaudioBridgeHandler extends BaseBridgeHandler implements PulseAudioBindingConfigurationListener {
|
||||
private final Logger logger = LoggerFactory.getLogger(PulseaudioBridgeHandler.class);
|
||||
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
|
||||
.singleton(PulseaudioBindingConstants.BRIDGE_THING_TYPE);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set
|
||||
.of(PulseaudioBindingConstants.BRIDGE_THING_TYPE);
|
||||
|
||||
public String host = "localhost";
|
||||
public int port = 4712;
|
||||
@@ -215,8 +214,8 @@ public class PulseaudioBridgeHandler extends BaseBridgeHandler implements PulseA
|
||||
|
||||
@Override
|
||||
public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) {
|
||||
if (childHandler instanceof PulseaudioHandler) {
|
||||
this.childHandlersInitialized.add((PulseaudioHandler) childHandler);
|
||||
if (childHandler instanceof PulseaudioHandler pulsaudioHandler) {
|
||||
this.childHandlersInitialized.add(pulsaudioHandler);
|
||||
} else {
|
||||
logger.error("This bridge can only support PulseaudioHandler child");
|
||||
}
|
||||
|
||||
@@ -252,8 +252,8 @@ public class PulseaudioHandler extends BaseThingHandler {
|
||||
return null;
|
||||
}
|
||||
ThingHandler handler = bridge.getHandler();
|
||||
if (handler instanceof PulseaudioBridgeHandler) {
|
||||
return (PulseaudioBridgeHandler) handler;
|
||||
if (handler instanceof PulseaudioBridgeHandler pulseaudioBridgeHandler) {
|
||||
return pulseaudioBridgeHandler;
|
||||
} else {
|
||||
logger.debug("No available bridge handler found for device {} bridge {} .",
|
||||
safeGetDeviceNameOrDescription(), bridge.getUID());
|
||||
@@ -300,25 +300,22 @@ public class PulseaudioHandler extends BaseThingHandler {
|
||||
briHandler.getClient().setVolumePercent(device, newVolume);
|
||||
updateState = new PercentType(newVolume);
|
||||
savedVolume = newVolume;
|
||||
} else if (command instanceof PercentType) {
|
||||
DecimalType volume = (DecimalType) command;
|
||||
} else if (command instanceof PercentType volume) {
|
||||
briHandler.getClient().setVolumePercent(device, volume.intValue());
|
||||
updateState = (PercentType) command;
|
||||
updateState = volume;
|
||||
savedVolume = volume.intValue();
|
||||
} else if (command instanceof DecimalType) {
|
||||
// set volume
|
||||
DecimalType volume = (DecimalType) command;
|
||||
} else if (command instanceof DecimalType volume) {
|
||||
briHandler.getClient().setVolume(device, volume.intValue());
|
||||
updateState = (DecimalType) command;
|
||||
updateState = volume;
|
||||
savedVolume = volume.intValue();
|
||||
}
|
||||
} else if (channelUID.getId().equals(MUTE_CHANNEL)) {
|
||||
if (command instanceof OnOffType) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
briHandler.getClient().setMute(device, OnOffType.ON.equals(command));
|
||||
updateState = (OnOffType) command;
|
||||
updateState = onOffCommand;
|
||||
}
|
||||
} else if (channelUID.getId().equals(SLAVES_CHANNEL)) {
|
||||
if (device instanceof Sink && ((Sink) device).isCombinedSink()) {
|
||||
if (device instanceof Sink sink && sink.isCombinedSink()) {
|
||||
if (command instanceof StringType) {
|
||||
List<Sink> slaves = new ArrayList<>();
|
||||
for (String slaveName : command.toString().split(",")) {
|
||||
@@ -335,16 +332,16 @@ public class PulseaudioHandler extends BaseThingHandler {
|
||||
logger.warn("{} is no combined sink", device);
|
||||
}
|
||||
} else if (channelUID.getId().equals(ROUTE_TO_SINK_CHANNEL)) {
|
||||
if (device instanceof SinkInput) {
|
||||
if (device instanceof SinkInput input) {
|
||||
Sink newSink = null;
|
||||
if (command instanceof DecimalType) {
|
||||
newSink = briHandler.getClient().getSink(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
newSink = briHandler.getClient().getSink(decimalCommand.intValue());
|
||||
} else {
|
||||
newSink = briHandler.getClient().getSink(command.toString());
|
||||
}
|
||||
if (newSink != null) {
|
||||
logger.debug("rerouting {} to {}", device, newSink);
|
||||
briHandler.getClient().moveSinkInput(((SinkInput) device), newSink);
|
||||
briHandler.getClient().moveSinkInput(input, newSink);
|
||||
updateState = new StringType(newSink.getPaName());
|
||||
} else {
|
||||
logger.warn("no sink {} found", command.toString());
|
||||
@@ -405,12 +402,12 @@ public class PulseaudioHandler extends BaseThingHandler {
|
||||
updateState(MUTE_CHANNEL, OnOffType.from(device.isMuted()));
|
||||
org.openhab.binding.pulseaudio.internal.items.AbstractAudioDeviceConfig.State state = device.getState();
|
||||
updateState(STATE_CHANNEL, state != null ? new StringType(state.toString()) : new StringType("-"));
|
||||
if (device instanceof SinkInput) {
|
||||
updateState(ROUTE_TO_SINK_CHANNEL, new StringType(
|
||||
Optional.ofNullable(((SinkInput) device).getSink()).map(Sink::getPaName).orElse("-")));
|
||||
if (device instanceof SinkInput input) {
|
||||
updateState(ROUTE_TO_SINK_CHANNEL,
|
||||
new StringType(Optional.ofNullable(input.getSink()).map(Sink::getPaName).orElse("-")));
|
||||
}
|
||||
if (device instanceof Sink && ((Sink) device).isCombinedSink()) {
|
||||
updateState(SLAVES_CHANNEL, new StringType(String.join(",", ((Sink) device).getCombinedSinkNames())));
|
||||
if (device instanceof Sink sink && sink.isCombinedSink()) {
|
||||
updateState(SLAVES_CHANNEL, new StringType(String.join(",", sink.getCombinedSinkNames())));
|
||||
}
|
||||
audioSinkSetup();
|
||||
audioSourceSetup();
|
||||
|
||||
Reference in New Issue
Block a user