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:
@@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.binding.enigma2.internal;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@@ -32,7 +31,7 @@ public class Enigma2BindingConstants {
|
||||
// List of all Thing Type UIDs
|
||||
public static final ThingTypeUID THING_TYPE_DEVICE = new ThingTypeUID(BINDING_ID, "device");
|
||||
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_DEVICE);
|
||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_DEVICE);
|
||||
|
||||
// List of all Channel ids
|
||||
public static final String CHANNEL_VOLUME = "volume";
|
||||
|
||||
@@ -16,8 +16,8 @@ import static org.openhab.binding.enigma2.internal.Enigma2BindingConstants.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -155,10 +155,10 @@ public class Enigma2Handler extends BaseThingHandler {
|
||||
if (command instanceof RefreshType) {
|
||||
client.refreshVolume();
|
||||
updateState(channelUID, new PercentType(client.getVolume()));
|
||||
} else if (command instanceof PercentType) {
|
||||
client.setVolume(((PercentType) command).intValue());
|
||||
} else if (command instanceof DecimalType) {
|
||||
client.setVolume(((DecimalType) command).intValue());
|
||||
} else if (command instanceof PercentType percentCommand) {
|
||||
client.setVolume(percentCommand.intValue());
|
||||
} else if (command instanceof DecimalType decimalCommand) {
|
||||
client.setVolume(decimalCommand.intValue());
|
||||
} else {
|
||||
logger.info("Channel {} only accepts PercentType, DecimalType, RefreshType. Type was {}.", channelUID,
|
||||
command.getClass());
|
||||
@@ -293,7 +293,7 @@ public class Enigma2Handler extends BaseThingHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singleton(Enigma2Actions.class);
|
||||
return Set.of(Enigma2Actions.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -312,13 +312,29 @@ public class Enigma2ClientTest {
|
||||
}
|
||||
|
||||
private void whenAllServices() throws IOException {
|
||||
when(enigma2HttpClient.get(HOST + Enigma2Client.PATH_ALL_SERVICES))
|
||||
.thenReturn("<e2servicelistrecursive>" + "<e2bouquet>" + "<e2servicelist>" + "<e2service>"
|
||||
+ "<e2servicereference>1</e2servicereference>" + "<e2servicename>Channel 1</e2servicename>"
|
||||
+ "</e2service>" + "<e2service>" + "<e2servicereference>2</e2servicereference>"
|
||||
+ "<e2servicename>Channel 2</e2servicename>" + "</e2service>" + "</e2servicelist>"
|
||||
+ "</e2bouquet>" + "<e2bouquet>" + "<e2servicelist>" + "<e2service>"
|
||||
+ "<e2servicereference>3</e2servicereference>" + "<e2servicename>Channel 3</e2servicename>"
|
||||
+ "</e2service>" + "</e2servicelist>" + "</e2bouquet>" + "</e2servicelistrecursive>");
|
||||
when(enigma2HttpClient.get(HOST + Enigma2Client.PATH_ALL_SERVICES)).thenReturn("""
|
||||
<e2servicelistrecursive>\
|
||||
<e2bouquet>\
|
||||
<e2servicelist>\
|
||||
<e2service>\
|
||||
<e2servicereference>1</e2servicereference>\
|
||||
<e2servicename>Channel 1</e2servicename>\
|
||||
</e2service>\
|
||||
<e2service>\
|
||||
<e2servicereference>2</e2servicereference>\
|
||||
<e2servicename>Channel 2</e2servicename>\
|
||||
</e2service>\
|
||||
</e2servicelist>\
|
||||
</e2bouquet>\
|
||||
<e2bouquet>\
|
||||
<e2servicelist>\
|
||||
<e2service>\
|
||||
<e2servicereference>3</e2servicereference>\
|
||||
<e2servicename>Channel 3</e2servicename>\
|
||||
</e2service>\
|
||||
</e2servicelist>\
|
||||
</e2bouquet>\
|
||||
</e2servicelistrecursive>\
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user