Java 17 features (T-Z) (#15576)
- 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:
@@ -964,7 +964,7 @@ public class TeslaChannelSelectorProxy {
|
||||
VEHICLE_NAME("vehicle_name", "name", StringType.class, true) {
|
||||
@Override
|
||||
public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
|
||||
return super.getState(s.replaceAll("\"", ""));
|
||||
return super.getState(s.replace("\"", ""));
|
||||
}
|
||||
},
|
||||
VALET_MODE("valet_mode", "valetmode", OnOffType.class, false) {
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -472,6 +471,6 @@ public class TeslaAccountHandler extends BaseBridgeHandler {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends ThingHandlerService>> getServices() {
|
||||
return Collections.singletonList(TeslaVehicleDiscoveryService.class);
|
||||
return List.of(TeslaVehicleDiscoveryService.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,8 +256,8 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
try {
|
||||
switch (selector) {
|
||||
case CHARGE_LIMIT_SOC: {
|
||||
if (command instanceof PercentType) {
|
||||
setChargeLimit(((PercentType) command).intValue());
|
||||
if (command instanceof PercentType percentCommand) {
|
||||
setChargeLimit(percentCommand.intValue());
|
||||
} else if (command instanceof OnOffType && command == OnOffType.ON) {
|
||||
setChargeLimit(100);
|
||||
} else if (command instanceof OnOffType && command == OnOffType.OFF) {
|
||||
@@ -273,11 +273,11 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
}
|
||||
case CHARGE_AMPS:
|
||||
Integer amps = null;
|
||||
if (command instanceof DecimalType) {
|
||||
amps = ((DecimalType) command).intValue();
|
||||
if (command instanceof DecimalType decimalCommand) {
|
||||
amps = decimalCommand.intValue();
|
||||
}
|
||||
if (command instanceof QuantityType<?>) {
|
||||
QuantityType<?> qamps = ((QuantityType<?>) command).toUnit(Units.AMPERE);
|
||||
if (command instanceof QuantityType<?> quantityCommand) {
|
||||
QuantityType<?> qamps = quantityCommand.toUnit(Units.AMPERE);
|
||||
if (qamps != null) {
|
||||
amps = qamps.intValue();
|
||||
}
|
||||
@@ -324,8 +324,8 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
break;
|
||||
}
|
||||
case CHARGE_TO_MAX: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
setMaxRangeCharging(true);
|
||||
} else {
|
||||
setMaxRangeCharging(false);
|
||||
@@ -334,8 +334,8 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
break;
|
||||
}
|
||||
case CHARGE: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
charge(true);
|
||||
} else {
|
||||
charge(false);
|
||||
@@ -344,32 +344,32 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
break;
|
||||
}
|
||||
case FLASH: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
flashLights();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case HONK_HORN: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
honkHorn();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CHARGEPORT: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
openChargePort();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DOOR_LOCK: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
lockDoors(true);
|
||||
} else {
|
||||
lockDoors(false);
|
||||
@@ -378,8 +378,8 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
break;
|
||||
}
|
||||
case AUTO_COND: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
autoConditioning(true);
|
||||
} else {
|
||||
autoConditioning(false);
|
||||
@@ -388,24 +388,24 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
break;
|
||||
}
|
||||
case WAKEUP: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
wakeUp();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FT: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
openFrunk();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RT: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
if (vehicleState.rt == 0) {
|
||||
openTrunk();
|
||||
}
|
||||
@@ -416,9 +416,9 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
break;
|
||||
}
|
||||
case VALET_MODE: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
int valetpin = ((BigDecimal) getConfig().get(VALETPIN)).intValue();
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
setValetMode(true, valetpin);
|
||||
} else {
|
||||
setValetMode(false, valetpin);
|
||||
@@ -427,16 +427,16 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
break;
|
||||
}
|
||||
case RESET_VALET_PIN: {
|
||||
if (command instanceof OnOffType) {
|
||||
if (((OnOffType) command) == OnOffType.ON) {
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
if (onOffCommand == OnOffType.ON) {
|
||||
resetValetPin();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case STEERINGWHEEL_HEATER: {
|
||||
if (command instanceof OnOffType) {
|
||||
boolean commandBooleanValue = ((OnOffType) command) == OnOffType.ON ? true : false;
|
||||
if (command instanceof OnOffType onOffCommand) {
|
||||
boolean commandBooleanValue = onOffCommand == OnOffType.ON ? true : false;
|
||||
setSteeringWheelHeater(commandBooleanValue);
|
||||
}
|
||||
break;
|
||||
@@ -1025,7 +1025,7 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
case "data:update":
|
||||
logger.debug("Event : Received an update: '{}'", event.value);
|
||||
|
||||
String vals[] = event.value.split(",");
|
||||
String[] vals = event.value.split(",");
|
||||
long currentTimeStamp = Long.parseLong(vals[0]);
|
||||
long systemTimeStamp = System.currentTimeMillis();
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Vehicle {
|
||||
public String option_codes;
|
||||
public String vehicle_id;
|
||||
public String vin;
|
||||
public String tokens[];
|
||||
public String[] tokens;
|
||||
public String state;
|
||||
public boolean remote_start_enabled;
|
||||
public boolean calendar_enabled;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class VehicleData {
|
||||
public String option_codes;
|
||||
public String vehicle_id;
|
||||
public String vin;
|
||||
public String tokens[];
|
||||
public String[] tokens;
|
||||
public String state;
|
||||
public boolean remote_start_enabled;
|
||||
public boolean calendar_enabled;
|
||||
|
||||
Reference in New Issue
Block a user