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:
@@ -39,7 +39,7 @@ public enum StreamCommand {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static StreamCommand fromValue(String value) {
|
||||
|
||||
@@ -109,8 +109,8 @@ public class AmpliPiGroupHandler extends BaseThingHandler implements AmpliPiStat
|
||||
}
|
||||
break;
|
||||
case AmpliPiBindingConstants.CHANNEL_VOLUME:
|
||||
if (command instanceof PercentType) {
|
||||
update.setVolDelta(AmpliPiUtils.percentTypeToVolume((PercentType) command));
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
update.setVolDelta(AmpliPiUtils.percentTypeToVolume(percentCommand));
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
if (groupState != null) {
|
||||
if (IncreaseDecreaseType.INCREASE.equals(command)) {
|
||||
@@ -125,14 +125,13 @@ public class AmpliPiGroupHandler extends BaseThingHandler implements AmpliPiStat
|
||||
}
|
||||
break;
|
||||
case AmpliPiBindingConstants.CHANNEL_SOURCE:
|
||||
if (command instanceof DecimalType) {
|
||||
update.setSourceId(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
update.setSourceId(decimalCommand.intValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (bridgeHandler != null) {
|
||||
String url = bridgeHandler.getUrl() + "/api/groups/" + getId(thing);
|
||||
;
|
||||
StringContentProvider contentProvider = new StringContentProvider(gson.toJson(update));
|
||||
try {
|
||||
ContentResponse response = httpClient.newRequest(url).method(HttpMethod.PATCH)
|
||||
|
||||
@@ -99,12 +99,11 @@ public class AmpliPiHandler extends BaseBridgeHandler {
|
||||
if (CHANNEL_PRESET.equals(channelUID.getId())) {
|
||||
if (command instanceof RefreshType) {
|
||||
updateState(channelUID, UnDefType.NULL);
|
||||
} else if (command instanceof DecimalType) {
|
||||
DecimalType preset = (DecimalType) command;
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
try {
|
||||
ContentResponse response = this.httpClient
|
||||
.newRequest(url + "/api/presets/" + preset.intValue() + "/load").method(HttpMethod.POST)
|
||||
.timeout(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS).send();
|
||||
.newRequest(url + "/api/presets/" + decimalCommand.intValue() + "/load")
|
||||
.method(HttpMethod.POST).timeout(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS).send();
|
||||
if (response.getStatus() != HttpStatus.OK_200) {
|
||||
logger.error("AmpliPi API returned HTTP status {}.", response.getStatus());
|
||||
logger.debug("Content: {}", response.getContentAsString());
|
||||
@@ -115,11 +114,10 @@ public class AmpliPiHandler extends BaseBridgeHandler {
|
||||
}
|
||||
}
|
||||
} else if (channelUID.getId().startsWith(CHANNEL_INPUT)) {
|
||||
if (command instanceof StringType) {
|
||||
StringType input = (StringType) command;
|
||||
if (command instanceof StringType stringCommand) {
|
||||
int source = Integer.valueOf(channelUID.getId().substring(CHANNEL_INPUT.length())) - 1;
|
||||
SourceUpdate update = new SourceUpdate();
|
||||
update.setInput(input.toString());
|
||||
update.setInput(stringCommand.toString());
|
||||
try {
|
||||
StringContentProvider contentProvider = new StringContentProvider(gson.toJson(update));
|
||||
ContentResponse response = this.httpClient.newRequest(url + "/api/sources/" + source)
|
||||
|
||||
@@ -109,8 +109,8 @@ public class AmpliPiZoneHandler extends BaseThingHandler implements AmpliPiStatu
|
||||
}
|
||||
break;
|
||||
case AmpliPiBindingConstants.CHANNEL_VOLUME:
|
||||
if (command instanceof PercentType) {
|
||||
update.setVol(AmpliPiUtils.percentTypeToVolume((PercentType) command));
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
update.setVol(AmpliPiUtils.percentTypeToVolume(percentCommand));
|
||||
} else if (command instanceof IncreaseDecreaseType) {
|
||||
if (zoneState != null) {
|
||||
if (IncreaseDecreaseType.INCREASE.equals(command)) {
|
||||
@@ -125,8 +125,8 @@ public class AmpliPiZoneHandler extends BaseThingHandler implements AmpliPiStatu
|
||||
}
|
||||
break;
|
||||
case AmpliPiBindingConstants.CHANNEL_SOURCE:
|
||||
if (command instanceof DecimalType) {
|
||||
update.setSourceId(((DecimalType) command).intValue());
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
update.setSourceId(decimalCommand.intValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class InputStateOptionProvider extends BaseDynamicStateDescriptionProvide
|
||||
}
|
||||
|
||||
private @Nullable String getLabel(Stream stream) {
|
||||
if (stream.getType().equals("internetradio")) {
|
||||
if ("internetradio".equals(stream.getType())) {
|
||||
return stream.getName();
|
||||
} else {
|
||||
return stream.getType().substring(0, 1).toUpperCase() + stream.getType().substring(1);
|
||||
|
||||
@@ -54,10 +54,9 @@ public class AmpliPiMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant
|
||||
public @Nullable DiscoveryResult createResult(ServiceInfo service) {
|
||||
ThingUID uid = getThingUID(service);
|
||||
if (uid != null) {
|
||||
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withLabel("AmpliPi Controller")
|
||||
return DiscoveryResultBuilder.create(uid).withLabel("AmpliPi Controller")
|
||||
.withProperty(AmpliPiBindingConstants.CFG_PARAM_HOSTNAME, getIpAddress(service).getHostAddress())
|
||||
.withRepresentationProperty(AmpliPiBindingConstants.CFG_PARAM_HOSTNAME).build();
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -68,7 +67,7 @@ public class AmpliPiMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant
|
||||
if (service.getName().equals(AMPLIPI_API)) {
|
||||
InetAddress ip = getIpAddress(service);
|
||||
if (ip != null) {
|
||||
String id = ip.toString().substring(1).replaceAll("\\.", "");
|
||||
String id = ip.toString().substring(1).replace(".", "");
|
||||
return new ThingUID(AmpliPiBindingConstants.THING_TYPE_CONTROLLER, id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user