[transform] Code optimization for Java17: instanceof matching and multiline strings (#15483)

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-08-24 06:41:36 +02:00
committed by GitHub
parent db651f9e92
commit 6e49c6e6ec
13 changed files with 111 additions and 107 deletions

View File

@@ -65,9 +65,9 @@ public class XPathTransformationProfile implements StateProfile {
if (paramSource == null) {
paramSource = "%s";
}
if (paramFunction instanceof String && paramSource instanceof String) {
function = (String) paramFunction;
sourceFormat = (String) paramSource;
if (paramFunction instanceof String pFunction && paramSource instanceof String pFormat) {
function = pFunction;
sourceFormat = pFormat;
} else {
logger.error("Parameter '{}' and '{}' have to be Strings. Profile will be inactive.", FUNCTION_PARAM,
SOURCE_FORMAT_PARAM);

View File

@@ -17,19 +17,21 @@ package org.openhab.transform.xpath.internal;
*/
public abstract class AbstractTransformationServiceTest {
protected String source = "<?xml version=\"1.0\"?><xml_api_reply version=\"1\"><weather module_id=\"0\""
+ " tab_id=\"0\" mobile_row=\"0\" mobile_zipped=\"1\" row=\"0\" section=\"0\" ><forecast_information>"
+ "<city data=\"Krefeld, North Rhine-Westphalia\"/><postal_code data=\"Krefeld Germany\"/>"
+ "<latitude_e6 data=\"\"/><longitude_e6 data=\"\"/><forecast_date data=\"2011-03-01\"/>"
+ "<current_date_time data=\"2011-03-01 15:20:00 +0000\"/><unit_system data=\"SI\"/></forecast_information>"
+ "<current_conditions><condition data=\"Meistens bew<65>lkt\"/><temp_f data=\"46\"/><temp_c data=\"8\"/>"
+ "<humidity data=\"Feuchtigkeit: 66 %\"/><icon data=\"/ig/images/weather/mostly_cloudy.gif\"/>"
+ "<wind_condition data=\"Wind: N mit 26 km/h\"/></current_conditions><forecast_conditions><day_of_week data=\"Di.\"/>"
+ "<low data=\"-1\"/><high data=\"6\"/><icon data=\"/ig/images/weather/sunny.gif\"/><condition data=\"Klar\"/>"
+ "</forecast_conditions><forecast_conditions><day_of_week data=\"Mi.\"/><low data=\"-1\"/><high data=\"8\"/>"
+ "<icon data=\"/ig/images/weather/sunny.gif\"/><condition data=\"Klar\"/></forecast_conditions><forecast_conditions>"
+ "<day_of_week data=\"Do.\"/><low data=\"-1\"/><high data=\"8\"/><icon data=\"/ig/images/weather/sunny.gif\"/>"
+ "<condition data=\"Klar\"/></forecast_conditions><forecast_conditions><day_of_week data=\"Fr.\"/><low data=\"0\"/>"
+ "<high data=\"8\"/><icon data=\"/ig/images/weather/sunny.gif\"/><condition data=\"Klar\"/></forecast_conditions>"
+ "</weather></xml_api_reply>";
protected String source = """
<?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0"\
tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" ><forecast_information>\
<city data="Krefeld, North Rhine-Westphalia"/><postal_code data="Krefeld Germany"/>\
<latitude_e6 data=""/><longitude_e6 data=""/><forecast_date data="2011-03-01"/>\
<current_date_time data="2011-03-01 15:20:00 +0000"/><unit_system data="SI"/></forecast_information>\
<current_conditions><condition data="Meistens bew<65>lkt"/><temp_f data="46"/><temp_c data="8"/>\
<humidity data="Feuchtigkeit: 66 %"/><icon data="/ig/images/weather/mostly_cloudy.gif"/>\
<wind_condition data="Wind: N mit 26 km/h"/></current_conditions><forecast_conditions><day_of_week data="Di."/>\
<low data="-1"/><high data="6"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Klar"/>\
</forecast_conditions><forecast_conditions><day_of_week data="Mi."/><low data="-1"/><high data="8"/>\
<icon data="/ig/images/weather/sunny.gif"/><condition data="Klar"/></forecast_conditions><forecast_conditions>\
<day_of_week data="Do."/><low data="-1"/><high data="8"/><icon data="/ig/images/weather/sunny.gif"/>\
<condition data="Klar"/></forecast_conditions><forecast_conditions><day_of_week data="Fr."/><low data="0"/>\
<high data="8"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Klar"/></forecast_conditions>\
</weather></xml_api_reply>\
""";
}