Skip to content

Commit 7820dc4

Browse files
Cleanup: Java21, SAT (#4757)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
1 parent 8fbea76 commit 7820dc4

File tree

12 files changed

+18
-17
lines changed

12 files changed

+18
-17
lines changed

bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void installFromCache(String addonId) throws MarketplaceHandlerException
165165
"The local cache folder doesn't contain a single file: " + addonPath, null);
166166
}
167167
try {
168-
karService.install(karFiles.get(0).toUri(), false);
168+
karService.install(karFiles.getFirst().toUri(), false);
169169
} catch (Exception e) {
170170
throw new MarketplaceHandlerException(
171171
"Cannot install KAR from marketplace cache: " + e.getMessage(), e);

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/parser/jackson/AbstractJacksonYAMLParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
public abstract class AbstractJacksonYAMLParser<T> implements Parser<T> {
3333

3434
/** The YAML object mapper instance */
35-
protected static final ObjectMapper yamlMapper;
35+
protected static final ObjectMapper YAML_MAPPER;
3636

3737
static {
38-
yamlMapper = new ObjectMapper(new YAMLFactory());
39-
yamlMapper.findAndRegisterModules();
38+
YAML_MAPPER = new ObjectMapper(new YAMLFactory());
39+
YAML_MAPPER.findAndRegisterModules();
4040
}
4141

4242
@Override
4343
public void serialize(Set<T> dataObjects, OutputStreamWriter writer) throws Exception {
4444
for (T dataObject : dataObjects) {
45-
yamlMapper.writeValue(writer, dataObject);
45+
YAML_MAPPER.writeValue(writer, dataObject);
4646
}
4747
}
4848
}

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/parser/jackson/TemplateYAMLParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public class TemplateYAMLParser extends AbstractJacksonYAMLParser<Template> {
4343
public Set<Template> parse(InputStreamReader reader) throws ParsingException {
4444
try {
4545
Set<Template> templates = new HashSet<>();
46-
JsonNode rootNode = yamlMapper.readTree(reader);
46+
JsonNode rootNode = YAML_MAPPER.readTree(reader);
4747
if (rootNode.isArray()) {
48-
List<RuleTemplateDTO> templateDtos = yamlMapper.convertValue(rootNode,
48+
List<RuleTemplateDTO> templateDtos = YAML_MAPPER.convertValue(rootNode,
4949
new TypeReference<List<RuleTemplateDTO>>() {
5050
});
5151
for (RuleTemplateDTO templateDTO : templateDtos) {
5252
templates.add(RuleTemplateDTOMapper.map(templateDTO));
5353
}
5454
} else {
55-
RuleTemplateDTO templateDto = yamlMapper.convertValue(rootNode, new TypeReference<RuleTemplateDTO>() {
55+
RuleTemplateDTO templateDto = YAML_MAPPER.convertValue(rootNode, new TypeReference<RuleTemplateDTO>() {
5656
});
5757
templates.add(RuleTemplateDTOMapper.map(templateDto));
5858
}

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/parser/ValidationException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package org.openhab.core.automation.parser;
1414

15+
import java.io.Serial;
16+
1517
import org.eclipse.jdt.annotation.NonNullByDefault;
1618
import org.eclipse.jdt.annotation.Nullable;
1719

@@ -23,6 +25,7 @@
2325
@NonNullByDefault
2426
public class ValidationException extends Exception {
2527

28+
@Serial
2629
private static final long serialVersionUID = 1L;
2730

2831
/**

bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.net.URISyntaxException;
2121
import java.net.URL;
2222
import java.nio.file.Files;
23-
import java.nio.file.Paths;
23+
import java.nio.file.Path;
2424
import java.time.DayOfWeek;
2525
import java.time.LocalDate;
2626
import java.time.ZonedDateTime;
@@ -223,7 +223,7 @@ protected void modified(Map<String, Object> config) {
223223
}
224224

225225
private URL getUrl(String filename) throws FileNotFoundException {
226-
if (Files.exists(Paths.get(filename))) {
226+
if (Files.exists(Path.of(filename))) {
227227
try {
228228
return (new URI("file:" + filename)).toURL();
229229
} catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) {

bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/log/LogWebSocket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void onText(String message) {
198198
lastSentTime = System.currentTimeMillis();
199199

200200
// Remove any duplicates from the live log buffer
201-
long newestSequence = logs.get(0).getSequence();
201+
long newestSequence = logs.getFirst().getSequence();
202202
synchronized (deferredLogs) {
203203
Iterator<LogDTO> iterator = deferredLogs.iterator();
204204
while (iterator.hasNext()) {

bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ public void removeModelRepositoryChangeListener(ModelRepositoryChangeListener li
234234

235235
@Override
236236
public void generateSyntaxFromModel(OutputStream out, String modelType, EObject modelContent) {
237-
String result = "";
238237
synchronized (resourceSet) {
239238
String name = "tmp_generated_syntax_%d.%s".formatted(++counter, modelType);
240239
Resource resource = resourceSet.createResource(URI.createURI(name));

bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,6 @@ private <T extends YamlElement> List<T> parseJsonMapNode(@Nullable JsonNode mapN
722722
errors.add("could not create new instance of %s".formatted(elementClass.getSimpleName()));
723723
}
724724
}
725-
726725
} else {
727726
try {
728727
elt = objectMapper.treeToValue(node, elementClass);

bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/QueryablePersistenceService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public String getName() {
108108
*
109109
* @param itemName name of item
110110
* @param alias alias of item
111-
*
112111
* @return a {@link PersistedItem} or null if the item has not been persisted
113112
*/
114113
default @Nullable PersistedItem persistedItem(String itemName, @Nullable String alias) {

bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticsServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ boolean checkSemantics(Item item) {
313313
}
314314
}
315315
} else if (Equipment.class.isAssignableFrom(semanticTag)) {
316-
if (parentLocations.size() > 0 && parentEquipments.size() > 0) {
316+
if (!parentLocations.isEmpty() && !parentEquipments.isEmpty()) {
317317
warnings.add(String.format(
318318
"It belongs to location(s) %s and equipment(s) %s. An Equipment can only belong to one Location or another Equipment, but not both.",
319319
parentLocations.toString(), parentEquipments.toString()));
@@ -333,7 +333,7 @@ boolean checkSemantics(Item item) {
333333
warnings.add(String.format("It is a %s item, not a group. A location should be a Group Item.",
334334
item.getType()));
335335
}
336-
if (parentEquipments.size() > 0) {
336+
if (!parentEquipments.isEmpty()) {
337337
warnings.add(String.format(
338338
"It belongs to equipment(s) %s. A Location can only belong to another Location, not Equipment.",
339339
parentEquipments.toString()));

0 commit comments

Comments
 (0)