Skip to content

Commit 0996316

Browse files
Use Java 21 language features
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
1 parent 669b791 commit 0996316

File tree

9 files changed

+81
-83
lines changed

9 files changed

+81
-83
lines changed

bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/parser/gson/RuleGSONParserTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void basicRuleTest() throws Exception {
101101

102102
triggers = rule.getTriggers();
103103
assertThat(triggers, hasSize(2));
104-
Trigger trigger = triggers.get(0);
104+
Trigger trigger = triggers.getFirst();
105105
assertThat(trigger.getId(), is("2"));
106106
assertThat(trigger.getLabel(), is(emptyOrNullString()));
107107
assertThat(trigger.getDescription(), is(emptyOrNullString()));
@@ -118,7 +118,7 @@ public void basicRuleTest() throws Exception {
118118

119119
conditions = rule.getConditions();
120120
assertThat(conditions, hasSize(2));
121-
Condition condition = conditions.get(0);
121+
Condition condition = conditions.getFirst();
122122
assertThat(condition.getId(), is("3"));
123123
assertThat(condition.getLabel(), is(emptyOrNullString()));
124124
assertThat(condition.getDescription(), is(emptyOrNullString()));
@@ -137,7 +137,7 @@ public void basicRuleTest() throws Exception {
137137

138138
actions = rule.getActions();
139139
assertThat(actions, hasSize(2));
140-
Action action = actions.get(0);
140+
Action action = actions.getFirst();
141141
assertThat(action.getId(), is("1"));
142142
assertThat(action.getLabel(), is(emptyOrNullString()));
143143
assertThat(action.getDescription(), is(emptyOrNullString()));
@@ -183,7 +183,7 @@ public void fullRuleTest() throws Exception {
183183

184184
List<ConfigDescriptionParameter> configDescriptions = rule.getConfigurationDescriptions();
185185
assertThat(configDescriptions, hasSize(5));
186-
ConfigDescriptionParameter parameter = configDescriptions.get(0);
186+
ConfigDescriptionParameter parameter = configDescriptions.getFirst();
187187
assertThat(parameter.getName(), is("textParam"));
188188
assertThat(parameter.getLabel(), is("Text parameter"));
189189
assertThat(parameter.getDescription(), is("This is a text parameter."));
@@ -201,14 +201,14 @@ public void fullRuleTest() throws Exception {
201201
assertFalse(parameter.getLimitToOptions());
202202
List<ParameterOption> options = parameter.getOptions();
203203
assertThat(options, hasSize(2));
204-
assertThat(options.get(0).getLabel(), is("First Option"));
205-
assertThat(options.get(0).getValue(), is("1st"));
204+
assertThat(options.getFirst().getLabel(), is("First Option"));
205+
assertThat(options.getFirst().getValue(), is("1st"));
206206
assertThat(options.get(1).getLabel(), is("Second Option"));
207207
assertThat(options.get(1).getValue(), is("2nd"));
208208
List<FilterCriteria> filterCriterias = parameter.getFilterCriteria();
209209
assertThat(filterCriterias, hasSize(2));
210-
assertThat(filterCriterias.get(0).getName(), is("filter1"));
211-
assertThat(filterCriterias.get(0).getValue(), is(".*"));
210+
assertThat(filterCriterias.getFirst().getName(), is("filter1"));
211+
assertThat(filterCriterias.getFirst().getValue(), is(".*"));
212212
assertThat(filterCriterias.get(1).getName(), is("filter2"));
213213
assertThat(filterCriterias.get(1).getValue(), is("a.*"));
214214
parameter = configDescriptions.get(1);
@@ -282,7 +282,7 @@ public void fullRuleTest() throws Exception {
282282

283283
List<Trigger> triggers = rule.getTriggers();
284284
assertThat(triggers, hasSize(2));
285-
Trigger trigger = triggers.get(0);
285+
Trigger trigger = triggers.getFirst();
286286
assertThat(trigger.getId(), is("first"));
287287
assertThat(trigger.getLabel(), is("First Trigger"));
288288
assertThat(trigger.getDescription(), is("The first trigger."));
@@ -299,7 +299,7 @@ public void fullRuleTest() throws Exception {
299299

300300
List<Condition> conditions = rule.getConditions();
301301
assertThat(conditions, hasSize(4));
302-
Condition condition = conditions.get(0);
302+
Condition condition = conditions.getFirst();
303303
assertThat(condition.getId(), is("holiday"));
304304
assertThat(condition.getLabel(), is("Is Holiday"));
305305
assertThat(condition.getDescription(), is("It must be a holiday."));
@@ -329,7 +329,7 @@ public void fullRuleTest() throws Exception {
329329

330330
List<Action> actions = rule.getActions();
331331
assertThat(actions, hasSize(2));
332-
Action action = actions.get(0);
332+
Action action = actions.getFirst();
333333
assertThat(action.getId(), is("greet"));
334334
assertThat(action.getLabel(), is("Greet"));
335335
assertThat(action.getDescription(), is("Greets the person."));

bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/parser/gson/TemplateGSONParserTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void basicTemplateTest() throws Exception {
6565

6666
List<ConfigDescriptionParameter> configDescriptions = template.getConfigurationDescriptions();
6767
assertThat(configDescriptions, hasSize(1));
68-
ConfigDescriptionParameter parameter = configDescriptions.get(0);
68+
ConfigDescriptionParameter parameter = configDescriptions.getFirst();
6969
assertThat(parameter.getName(), is("startLevel"));
7070
assertThat(parameter.getLabel(), is("Start Level"));
7171
assertThat(parameter.getDescription(), is("The start level which will trigger the rule."));
@@ -86,7 +86,7 @@ public void basicTemplateTest() throws Exception {
8686

8787
List<Trigger> triggers = template.getTriggers();
8888
assertThat(triggers, hasSize(2));
89-
Trigger trigger = triggers.get(0);
89+
Trigger trigger = triggers.getFirst();
9090
assertThat(trigger.getId(), is("3"));
9191
assertThat(trigger.getLabel(), is(emptyOrNullString()));
9292
assertThat(trigger.getDescription(), is(emptyOrNullString()));
@@ -103,7 +103,7 @@ public void basicTemplateTest() throws Exception {
103103

104104
List<Condition> conditions = template.getConditions();
105105
assertThat(conditions, hasSize(2));
106-
Condition condition = conditions.get(0);
106+
Condition condition = conditions.getFirst();
107107
assertThat(condition.getId(), is("4"));
108108
assertThat(condition.getLabel(), is(emptyOrNullString()));
109109
assertThat(condition.getDescription(), is(emptyOrNullString()));
@@ -122,7 +122,7 @@ public void basicTemplateTest() throws Exception {
122122

123123
List<Action> actions = template.getActions();
124124
assertThat(actions, hasSize(2));
125-
Action action = actions.get(0);
125+
Action action = actions.getFirst();
126126
assertThat(action.getId(), is("1"));
127127
assertThat(action.getLabel(), is(emptyOrNullString()));
128128
assertThat(action.getDescription(), is(emptyOrNullString()));
@@ -160,7 +160,7 @@ public void fullTemplateTest() throws Exception {
160160

161161
List<ConfigDescriptionParameter> configDescriptions = template.getConfigurationDescriptions();
162162
assertThat(configDescriptions, hasSize(5));
163-
ConfigDescriptionParameter parameter = configDescriptions.get(0);
163+
ConfigDescriptionParameter parameter = configDescriptions.getFirst();
164164
assertThat(parameter.getName(), is("textParam"));
165165
assertThat(parameter.getLabel(), is("Text parameter"));
166166
assertThat(parameter.getDescription(), is("This is a text parameter."));
@@ -178,14 +178,14 @@ public void fullTemplateTest() throws Exception {
178178
assertFalse(parameter.getLimitToOptions());
179179
List<ParameterOption> options = parameter.getOptions();
180180
assertThat(options, hasSize(2));
181-
assertThat(options.get(0).getLabel(), is("First Option"));
182-
assertThat(options.get(0).getValue(), is("Welcome"));
181+
assertThat(options.getFirst().getLabel(), is("First Option"));
182+
assertThat(options.getFirst().getValue(), is("Welcome"));
183183
assertThat(options.get(1).getLabel(), is("Second Option"));
184184
assertThat(options.get(1).getValue(), is("Willkommen"));
185185
List<FilterCriteria> filterCriterias = parameter.getFilterCriteria();
186186
assertThat(filterCriterias, hasSize(2));
187-
assertThat(filterCriterias.get(0).getName(), is("filter1"));
188-
assertThat(filterCriterias.get(0).getValue(), is(".*"));
187+
assertThat(filterCriterias.getFirst().getName(), is("filter1"));
188+
assertThat(filterCriterias.getFirst().getValue(), is(".*"));
189189
assertThat(filterCriterias.get(1).getName(), is("filter2"));
190190
assertThat(filterCriterias.get(1).getValue(), is("a.*"));
191191
parameter = configDescriptions.get(1);
@@ -259,7 +259,7 @@ public void fullTemplateTest() throws Exception {
259259

260260
List<Trigger> triggers = template.getTriggers();
261261
assertThat(triggers, hasSize(2));
262-
Trigger trigger = triggers.get(0);
262+
Trigger trigger = triggers.getFirst();
263263
assertThat(trigger.getId(), is("first"));
264264
assertThat(trigger.getLabel(), is("First Trigger"));
265265
assertThat(trigger.getDescription(), is("The first trigger."));
@@ -276,7 +276,7 @@ public void fullTemplateTest() throws Exception {
276276

277277
List<Condition> conditions = template.getConditions();
278278
assertThat(conditions, hasSize(4));
279-
Condition condition = conditions.get(0);
279+
Condition condition = conditions.getFirst();
280280
assertThat(condition.getId(), is("holiday"));
281281
assertThat(condition.getLabel(), is("Is Holiday"));
282282
assertThat(condition.getDescription(), is("It must be a holiday."));
@@ -306,7 +306,7 @@ public void fullTemplateTest() throws Exception {
306306

307307
List<Action> actions = template.getActions();
308308
assertThat(actions, hasSize(2));
309-
Action action = actions.get(0);
309+
Action action = actions.getFirst();
310310
assertThat(action.getId(), is("greet"));
311311
assertThat(action.getLabel(), is("Greet"));
312312
assertThat(action.getDescription(), is("Greets the person."));
@@ -347,7 +347,7 @@ public void multipleTemplatesTest() throws Exception {
347347

348348
List<ConfigDescriptionParameter> configDescriptions = template.getConfigurationDescriptions();
349349
assertThat(configDescriptions, hasSize(3));
350-
ConfigDescriptionParameter parameter = configDescriptions.get(0);
350+
ConfigDescriptionParameter parameter = configDescriptions.getFirst();
351351
assertThat(parameter.getName(), is("consumption"));
352352
assertThat(parameter.getLabel(), is("Consumption Item"));
353353
assertThat(parameter.getDescription(), is("Data source for current consumption"));
@@ -367,8 +367,8 @@ public void multipleTemplatesTest() throws Exception {
367367
assertThat(options, is(empty()));
368368
List<FilterCriteria> filterCriterias = parameter.getFilterCriteria();
369369
assertThat(filterCriterias, hasSize(1));
370-
assertThat(filterCriterias.get(0).getName(), is("type"));
371-
assertThat(filterCriterias.get(0).getValue(), is("Number"));
370+
assertThat(filterCriterias.getFirst().getName(), is("type"));
371+
assertThat(filterCriterias.getFirst().getValue(), is("Number"));
372372
parameter = configDescriptions.get(1);
373373
assertThat(parameter.getName(), is("light"));
374374
assertThat(parameter.getLabel(), is("Color Item"));
@@ -407,7 +407,7 @@ public void multipleTemplatesTest() throws Exception {
407407

408408
List<Trigger> triggers = template.getTriggers();
409409
assertThat(triggers, hasSize(1));
410-
Trigger trigger = triggers.get(0);
410+
Trigger trigger = triggers.getFirst();
411411
assertThat(trigger.getId(), is("trigger"));
412412
assertThat(trigger.getLabel(), is("Current consumption changes"));
413413
assertThat(trigger.getDescription(), is("Triggers whenever the current consumption changes its value"));
@@ -420,7 +420,7 @@ public void multipleTemplatesTest() throws Exception {
420420

421421
List<Action> actions = template.getActions();
422422
assertThat(actions, hasSize(1));
423-
Action action = actions.get(0);
423+
Action action = actions.getFirst();
424424
assertThat(action.getId(), is("setcolor"));
425425
assertThat(action.getLabel(), is("Change the light color"));
426426
assertThat(action.getDescription(),
@@ -444,7 +444,7 @@ public void multipleTemplatesTest() throws Exception {
444444

445445
configDescriptions = template.getConfigurationDescriptions();
446446
assertThat(configDescriptions, hasSize(6));
447-
parameter = configDescriptions.get(0);
447+
parameter = configDescriptions.getFirst();
448448
assertThat(parameter.getName(), is("itemTargetTime"));
449449
assertThat(parameter.getLabel(), is("Target Time (DateTime Item)"));
450450
assertThat(parameter.getDescription(), is(
@@ -545,7 +545,7 @@ public void multipleTemplatesTest() throws Exception {
545545

546546
triggers = template.getTriggers();
547547
assertThat(triggers, hasSize(1));
548-
trigger = triggers.get(0);
548+
trigger = triggers.getFirst();
549549
assertThat(trigger.getId(), is("1"));
550550
assertThat(trigger.getLabel(), is(emptyOrNullString()));
551551
assertThat(trigger.getDescription(), is(emptyOrNullString()));
@@ -558,7 +558,7 @@ public void multipleTemplatesTest() throws Exception {
558558

559559
actions = template.getActions();
560560
assertThat(actions, hasSize(1));
561-
action = actions.get(0);
561+
action = actions.getFirst();
562562
assertThat(action.getId(), is("2"));
563563
assertThat(action.getLabel(), is("Calculate & set the target brightness"));
564564
assertThat(action.getDescription(),

bundles/org.openhab.core.config.discovery.usbserial.windowsregistry/src/main/java/org/openhab/core/config/discovery/usbserial/windowsregistry/internal/WindowMessageHandler.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,14 @@ public LRESULT callback(HWND hWnd, int uMsg, WPARAM wParam, LPARAM lParam) {
227227

228228
@Nullable
229229
private LRESULT onDeviceChange(WPARAM wParam, LPARAM lParam) {
230-
switch (wParam.intValue()) {
231-
case DBT.DBT_DEVICEARRIVAL:
232-
return onDeviceAddedOrRemoved(lParam, true);
233-
case DBT.DBT_DEVICEREMOVECOMPLETE:
234-
return onDeviceAddedOrRemoved(lParam, false);
235-
case DBT.DBT_DEVNODES_CHANGED:
236-
// LRESULT(1) aka TRUE means that the message was processed. This message is non-specific
237-
// (basically means "something changed"), so we don't want to take any action.
238-
return new LRESULT(1);
239-
default:
240-
return null;
241-
}
230+
return switch (wParam.intValue()) {
231+
case DBT.DBT_DEVICEARRIVAL -> onDeviceAddedOrRemoved(lParam, true);
232+
case DBT.DBT_DEVICEREMOVECOMPLETE -> onDeviceAddedOrRemoved(lParam, false);
233+
// LRESULT(1) aka TRUE means that the message was processed. This message is non-specific
234+
// (basically means "something changed"), so we don't want to take any action.
235+
case DBT.DBT_DEVNODES_CHANGED -> new LRESULT(1);
236+
default -> null;
237+
};
242238
}
243239

244240
@Nullable

bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public Response httpGetPersistenceHealth(@Context HttpHeaders headers) {
400400
persistenceProblems.add(new PersistenceServiceProblem(
401401
PersistenceServiceProblem.PERSISTENCE_NO_STRATEGY, serviceId, items, editable));
402402
} else if (strategies.size() == 1
403-
&& PersistenceStrategy.Globals.RESTORE.equals(strategies.get(0))) {
403+
&& PersistenceStrategy.Globals.RESTORE.equals(strategies.getFirst())) {
404404
persistenceProblems.add(new PersistenceServiceProblem(
405405
PersistenceServiceProblem.PERSISTENCE_NO_STORE_STRATEGY, serviceId, items,
406406
editable));

bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/items/YamlItemDTOTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,6 @@ public void testExpireMetadataWarning() throws IOException {
609609
assertEquals(1, warnings.size());
610610
assertEquals(
611611
"item \"item_name\": \"expire\" field is redundant with \"expire\" metadata; value \"5m\" will be considered",
612-
warnings.get(0));
612+
warnings.getFirst());
613613
}
614614
}

bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/items/fileconverter/YamlItemFileConverterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ private YamlItemDTO convertWithMetadata(Metadata metadata, String itemType) {
116116

117117
List<YamlElement> elements = repository.getElements();
118118
assertEquals(1, elements.size());
119-
assertInstanceOf(YamlItemDTO.class, elements.get(0));
120-
return (YamlItemDTO) elements.get(0);
119+
assertInstanceOf(YamlItemDTO.class, elements.getFirst());
120+
return (YamlItemDTO) elements.getFirst();
121121
}
122122

123123
private static class CapturingYamlModelRepository implements YamlModelRepository {

0 commit comments

Comments
 (0)