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:
@@ -13,7 +13,6 @@
|
||||
package org.openhab.binding.fmiweather.internal.client;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -36,6 +35,6 @@ public class FMISID implements QueryParameter {
|
||||
|
||||
@Override
|
||||
public List<Map.Entry<String, String>> toRequestParameters() {
|
||||
return Collections.singletonList(new AbstractMap.SimpleImmutableEntry<>("fmisid", fmisid));
|
||||
return List.of(new AbstractMap.SimpleImmutableEntry<>("fmisid", fmisid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.openhab.binding.fmiweather.internal.client;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -37,6 +36,6 @@ public class LatLon implements QueryParameter {
|
||||
|
||||
@Override
|
||||
public List<Map.Entry<String, String>> toRequestParameters() {
|
||||
return Collections.singletonList(new AbstractMap.SimpleImmutableEntry<>("latlon", latlon));
|
||||
return List.of(new AbstractMap.SimpleImmutableEntry<>("latlon", latlon));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class AbstractWeatherHandlerTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static final List<Object[]> parametersForFloorToEvenMinutes() {
|
||||
public static List<Object[]> parametersForFloorToEvenMinutes() {
|
||||
return Arrays.asList(new Object[][] { //
|
||||
{ 1626605128L /* 2021-07-18 10:45:28 */, 1, 1626605100 /* 10:45 */ }, //
|
||||
{ 1626605128L /* 2021-07-18 10:45:28 */, 5, 1626605100 /* 10:45 */ }, //
|
||||
@@ -101,7 +101,7 @@ public class AbstractWeatherHandlerTest {
|
||||
assertEquals(expected, floorToEvenMinutes(epochSeconds, roundMinutes));
|
||||
}
|
||||
|
||||
public static final List<Object[]> parametersForCeilToEvenMinutes() {
|
||||
public static List<Object[]> parametersForCeilToEvenMinutes() {
|
||||
return Arrays.asList(new Object[][] { //
|
||||
{ 1626605128L /* 2021-07-18 10:45:28 */, 1, 1626605160 /* 10:46 */ }, //
|
||||
{ 1626605128L /* 2021-07-18 10:45:28 */, 5, 1626605400 /* 10:50 */ }, //
|
||||
@@ -117,7 +117,7 @@ public class AbstractWeatherHandlerTest {
|
||||
assertEquals(expected, ceilToEvenMinutes(epochSeconds, roundMinutes));
|
||||
}
|
||||
|
||||
public static final List<Object[]> parametersForLastValidIndex() {
|
||||
public static List<Object[]> parametersForLastValidIndex() {
|
||||
return Arrays.asList(new Object[][] { //
|
||||
{ "no nulls", 1, new BigDecimal[] { bd(1), bd(2) } }, //
|
||||
{ "one null in beginning", 1, new BigDecimal[] { null, bd(2) } }, //
|
||||
|
||||
@@ -40,20 +40,24 @@ public class FMIRequestTest {
|
||||
@Test
|
||||
public void testObservationRequestToUrl() {
|
||||
ObservationRequest request = new ObservationRequest(new FMISID("101023"), 1552215664L, 1552215665L, 61);
|
||||
assertThat(request.toUrl(), is(
|
||||
"https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage"
|
||||
+ "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&fmisid=101023"
|
||||
+ "¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa"));
|
||||
assertThat(request.toUrl(),
|
||||
is("""
|
||||
https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage\
|
||||
&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&fmisid=101023\
|
||||
¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa\
|
||||
"""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForecastRequestToUrl() {
|
||||
ForecastRequest request = new ForecastRequest(new LatLon(new BigDecimal("9"), new BigDecimal("8")), 1552215664L,
|
||||
1552215665L, 61);
|
||||
assertThat(request.toUrl(), is(
|
||||
"https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::forecast::harmonie::surface::point::multipointcoverage"
|
||||
+ "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&latlon=9,8"
|
||||
+ "¶meters=Temperature,Humidity,WindDirection,WindSpeedMS,WindGust,Pressure,Precipitation1h,TotalCloudCover,WeatherSymbol3"));
|
||||
assertThat(request.toUrl(),
|
||||
is("""
|
||||
https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::forecast::harmonie::surface::point::multipointcoverage\
|
||||
&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&latlon=9,8\
|
||||
¶meters=Temperature,Humidity,WindDirection,WindSpeedMS,WindGust,Pressure,Precipitation1h,TotalCloudCover,WeatherSymbol3\
|
||||
"""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,9 +72,11 @@ public class FMIRequestTest {
|
||||
}
|
||||
};
|
||||
ObservationRequest request = new ObservationRequest(location, 1552215664L, 1552215665L, 61);
|
||||
assertThat(request.toUrl(), is(
|
||||
"https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage"
|
||||
+ "&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&lat=MYLAT&lon=FOO&special=x,y,z"
|
||||
+ "¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa"));
|
||||
assertThat(request.toUrl(),
|
||||
is("""
|
||||
https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::multipointcoverage\
|
||||
&starttime=2019-03-10T11:01:04Z&endtime=2019-03-10T11:01:05Z×tep=61&lat=MYLAT&lon=FOO&special=x,y,z\
|
||||
¶meters=t2m,rh,wd_10min,ws_10min,wg_10min,p_sea,r_1h,snow_aws,vis,n_man,wawa\
|
||||
"""));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user