From 40d079ae809d81376321e002b39707bab4dc6944 Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Mon, 6 Jan 2025 23:22:43 +0100 Subject: [PATCH] Java 21 language features (#4535) * Java 21 language features * use getFirst and getLast methods * replace new Locale by Locale.of * replace Paths.get by Path.of * use ThreadLocalRandom.current().nextDouble() * add @Serial annotations Signed-off-by: Holger Friedrich --- .../MarketplaceBundleInstaller.java | 2 +- .../MarketplaceHandlerException.java | 3 + .../SerializedNameAnnotationIntrospector.java | 2 + .../AbstractRemoteAddonServiceTest.java | 2 +- .../core/addon/AddonInfoListReaderTest.java | 10 +- .../openhab/core/audio/AudioException.java | 3 + .../UnsupportedAudioFormatException.java | 3 + .../UnsupportedAudioStreamException.java | 3 + .../core/audio/internal/AudioServlet.java | 2 + .../internal/MediaActionTypeProvider.java | 4 +- .../internal/ScriptEngineFactoryHelper.java | 4 +- .../internal/ScriptEngineManagerImpl.java | 2 +- .../handler/AbstractScriptModuleHandler.java | 4 +- .../provider/ScriptModuleTypeProvider.java | 2 +- .../commands/AutomationCommandList.java | 2 +- .../automation/internal/commands/Printer.java | 4 +- .../exception/UncomparableException.java | 3 + ...nnotationActionModuleTypeProviderTest.java | 2 +- ...atedThingActionModuleTypeProviderTest.java | 2 +- .../util/ActionInputHelperTest.java | 2 +- .../openhab/core/config/core/ConfigUtil.java | 2 +- .../validation/ConfigValidationException.java | 2 + .../core/ConfigDescriptionBuilderTest.java | 4 +- .../core/ConfigDescriptionRegistryTest.java | 26 ++-- .../core/config/core/ConfigurationTest.java | 2 +- .../core/dto/ConfigDescriptionDTOTest.java | 4 +- ...dataConfigDescriptionProviderImplTest.java | 10 +- .../core/status/ConfigStatusServiceTest.java | 6 +- .../xml/util/XmlDocumentReaderTest.java | 23 ++-- .../upnp/tests/UpnpAddonFinderTests.java | 2 +- .../discovery/sddp/SddpDiscoveryService.java | 2 +- .../internal/SysfsUsbSerialScanner.java | 9 +- .../internal/AutomaticInboxProcessor.java | 4 +- .../discovery/internal/PersistentInbox.java | 2 +- .../DiscoveryConsoleCommandExtension.java | 2 +- .../discovery/inbox/InboxPredicatesTest.java | 25 ++-- .../internal/AutomaticInboxProcessorTest.java | 26 ++-- .../dispatch/internal/ConfigDispatcher.java | 2 +- .../org/openhab/core/id/InstanceUUIDTest.java | 5 +- .../core/io/bin2json/ConversionException.java | 3 + .../karaf/internal/CompleterWrapperTest.java | 8 +- .../core/io/console/StringsCompleterTest.java | 18 +-- .../ItemConsoleCommandCompleterTest.java | 12 +- .../ItemConsoleCommandExtensionTest.java | 16 +-- .../internal/AbstractAuthPageServlet.java | 2 + .../auth/internal/AuthorizePageServlet.java | 2 + .../internal/ChangePasswordPageServlet.java | 2 + .../internal/CreateAPITokenPageServlet.java | 2 + .../metrics/ThingStateMetricTest.java | 4 +- .../HttpClientInitializationException.java | 3 + .../core/io/rest/auth/internal/JwtHelper.java | 4 +- .../auth/internal/TokenEndpointException.java | 3 + .../link/ItemChannelLinkResource.java | 2 +- .../service/ConfigurableServiceResource.java | 6 +- ...nrichedConfigDescriptionDTOMapperTest.java | 6 +- .../persistence/PersistenceResourceTest.java | 2 +- .../thing/EnrichedThingDTOMapperTest.java | 4 +- .../sitemap/SitemapSubscriptionService.java | 6 +- .../sitemap/internal/SitemapResourceTest.java | 28 ++--- .../rest/sse/internal/util/SseUtilTest.java | 30 ++--- .../core/io/rest/LocaleServiceImpl.java | 4 +- .../io/rest/internal/filter/CorsFilter.java | 2 +- .../io/rest/internal/filter/ProxyFilter.java | 2 +- .../core/io/rest/JSONResponseTest.java | 3 +- .../exception/ModbusConnectionException.java | 3 + .../ModbusSlaveErrorResponseException.java | 2 + .../exception/ModbusSlaveIOException.java | 3 + .../exception/ModbusTransportException.java | 3 + ...expectedResponseFunctionCodeException.java | 3 + ...ModbusUnexpectedResponseSizeException.java | 3 + ...odbusUnexpectedTransactionIdException.java | 3 + ...ModbusSlaveErrorResponseExceptionImpl.java | 2 + .../internal/ModbusSlaveIOExceptionImpl.java | 2 + .../io/transport/modbus/test/SmokeTest.java | 8 +- .../core/io/transport/mqtt/MqttException.java | 3 + .../transport/serial/PortInUseException.java | 3 + .../UnsupportedCommOperationException.java | 3 + .../io/websocket/CommonWebSocketServlet.java | 2 + .../event/EventProcessingException.java | 3 + .../core/karaf/internal/FeatureInstaller.java | 3 +- .../core/internal/ModelRepositoryImpl.java | 4 +- .../internal/folder/FolderObserverTest.java | 3 +- .../item/BindingConfigParseException.java | 3 + .../item/internal/GenericItemProvider.java | 2 +- .../lsp/internal/MappingUriExtensions.java | 5 +- .../model/rule/scoping/RulesClassCache.java | 2 + .../internal/engine/ScriptEngineImpl.java | 8 +- .../actions/TransformationException.java | 3 + .../core/model/script/actions/Voice.java | 8 +- .../model/script/engine/ScriptException.java | 2 + .../engine/ScriptExecutionException.java | 3 + .../script/engine/ScriptParsingException.java | 2 + .../ThingSyntacticSequencerExtension.java | 4 +- .../internal/YamlModelRepositoryImplTest.java | 6 +- .../extensions/PersistenceExtensions.java | 7 +- .../internal/PersistenceManagerTest.java | 8 +- .../internal/SemanticsMetadataProvider.java | 6 +- .../internal/SemanticsServiceImplTest.java | 18 +-- .../migration/TypeMigrationException.java | 3 + .../json/internal/JsonStorageTest.java | 4 +- .../handler/MagicChattyThingHandler.java | 5 +- .../handler/MagicTimeSeriesHandler.java | 3 +- .../openhab/core/test/java/JavaOSGiTest.java | 4 +- .../openhab/core/thing/ChannelGroupUID.java | 2 +- .../org/openhab/core/thing/ChannelUID.java | 2 +- .../java/org/openhab/core/thing/ThingUID.java | 2 +- .../core/thing/internal/ThingManagerImpl.java | 2 +- .../xml/internal/ThingDescriptionList.java | 2 + .../org/openhab/core/thing/ThingUIDTest.java | 2 +- .../binding/builder/ThingBuilderTest.java | 2 +- .../internal/ThingDescriptionReaderTest.java | 6 +- .../AbstractFileTransformationService.java | 3 +- .../transform/TransformationException.java | 3 + .../core/ui/icon/internal/IconServlet.java | 2 + .../core/ui/internal/chart/ChartServlet.java | 2 + .../DefaultChartProvider.java | 6 +- .../ui/internal/proxy/AsyncProxyServlet.java | 2 + .../internal/proxy/BlockingProxyServlet.java | 2 + .../internal/proxy/ProxyServletService.java | 2 + .../org/openhab/core/voice/KSException.java | 3 + .../org/openhab/core/voice/STTException.java | 3 + .../org/openhab/core/voice/TTSException.java | 3 + .../internal/text/StandardInterpreter.java | 4 +- .../text/AbstractRuleBasedInterpreter.java | 6 +- .../voice/text/ExpressionCardinality.java | 2 +- .../voice/text/InterpretationException.java | 3 + .../main/java/org/openhab/core/OpenHAB.java | 3 +- .../core/auth/AuthenticationException.java | 3 + .../client/oauth2/AccessTokenResponse.java | 2 + .../auth/client/oauth2/OAuthException.java | 3 + .../client/oauth2/OAuthResponseException.java | 3 + .../openhab/core/cache/lru/LRUMediaCache.java | 3 +- .../osgi/ResourceBundleClassLoader.java | 2 +- .../core/events/TopicGlobEventFilter.java | 4 +- .../common/DuplicateExecutionException.java | 3 + .../internal/items/GroupFunctionHelper.java | 10 +- .../internal/service/WatchServiceImpl.java | 4 +- .../core/items/ItemLookupException.java | 3 + .../core/items/ItemNotFoundException.java | 3 + .../core/items/ItemNotUniqueException.java | 2 + .../core/library/types/DecimalType.java | 2 + .../openhab/core/library/types/HSBType.java | 4 +- .../core/library/types/PercentType.java | 2 + .../openhab/core/library/types/PointType.java | 2 +- .../core/library/types/QuantityType.java | 2 + .../core/library/unit/CurrencyUnit.java | 2 + .../java/org/openhab/core/net/NetUtil.java | 6 +- .../openhab/core/scheduler/CronAdjuster.java | 2 +- .../cache/lru/LRUMediaCacheEntryTest.java | 2 +- .../osgi/ResourceBundleClassLoaderTest.java | 3 +- .../internal/common/SafeCallerImplTest.java | 2 +- .../internal/scheduler/SchedulerImplTest.java | 2 +- .../openhab/core/items/GenericItemTest.java | 8 +- .../org/openhab/core/net/NetUtilTest.java | 4 +- .../addon/xml/test/AddonInfoI18nTest.java | 2 +- .../core/addon/xml/test/AddonInfoTest.java | 6 +- .../test/HostFragmentSupportTest.java | 2 +- .../internal/BasicConditionHandlerTest.java | 5 +- .../automation/internal/RuleEngineTest.java | 14 +-- .../core/ConfigOptionRegistryOSGiTest.java | 4 +- .../discovery/internal/InboxOSGiTest.java | 8 +- .../internal/ConfigDispatcherOSGiTest.java | 5 +- .../net/tests/internal/TestHttpServlet.java | 2 + .../tests/internal/TestWebSocketServlet.java | 3 + .../internal/item/ItemResourceOSGiTest.java | 4 +- .../profile/ProfileTypeResourceTest.java | 4 +- ...hedItemDTOMapperWithTransformOSGiTest.java | 4 +- .../internal/GenericItemProviderTest.java | 4 +- .../rule/runtime/DSLRuleProviderTest.java | 18 +-- .../GenericItemChannelLinkProviderTest.java | 4 +- .../test/hue/GenericThingProviderTest.java | 4 +- .../internal/JsonStorageServiceOSGiTest.java | 5 +- .../i18n/TranslationProviderOSGiTest.java | 4 +- .../openhab/core/items/GroupItemOSGiTest.java | 20 ++-- .../core/items/ItemRegistryImplTest.java | 8 +- .../openhab/core/thing/ThingChannelsTest.java | 2 +- .../binding/ChangeThingTypeOSGiTest.java | 4 +- .../core/thing/binding/ThingFactoryTest.java | 19 ++- ...nelCommandDescriptionProviderOSGiTest.java | 8 +- .../internal/ChannelLinkNotifierOSGiTest.java | 2 +- ...annelStateDescriptionProviderOSGiTest.java | 8 +- .../internal/ThingManagerOSGiJavaTest.java | 4 +- .../thing/internal/ThingManagerOSGiTest.java | 112 +++++++++--------- .../firmware/FirmwareUpdateServiceTest.java | 16 +-- .../internal/update/ThingUpdateOSGiTest.java | 4 +- .../thing/xml/test/ChannelTypesI18nTest.java | 2 +- .../thing/xml/test/ThingTypeI18nTest.java | 4 +- .../core/thing/xml/test/ThingTypesTest.java | 6 +- .../core/tools/i18n/plugin/Translations.java | 2 +- .../plugin/XmlToTranslationsConverter.java | 6 +- 190 files changed, 596 insertions(+), 445 deletions(-) diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceBundleInstaller.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceBundleInstaller.java index 44a105f22df..4f74c5cefda 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceBundleInstaller.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceBundleInstaller.java @@ -86,7 +86,7 @@ protected void installFromCache(BundleContext bundleContext, String addonId) thr "The local cache folder doesn't contain a single file: " + addonPath, null); } - try (FileInputStream fileInputStream = new FileInputStream(bundleFiles.get(0).toFile())) { + try (FileInputStream fileInputStream = new FileInputStream(bundleFiles.getFirst().toFile())) { Bundle bundle = bundleContext.installBundle(addonId, fileInputStream); try { bundle.start(); diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceHandlerException.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceHandlerException.java index 4232668d3e5..c7a349f008c 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceHandlerException.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceHandlerException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.addon.marketplace; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -24,6 +26,7 @@ @NonNullByDefault public class MarketplaceHandlerException extends Exception { + @Serial private static final long serialVersionUID = -5652014141471618161L; /** diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/SerializedNameAnnotationIntrospector.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/SerializedNameAnnotationIntrospector.java index 0651be89efb..70970944d9c 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/SerializedNameAnnotationIntrospector.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/SerializedNameAnnotationIntrospector.java @@ -12,6 +12,7 @@ */ package org.openhab.core.addon.marketplace.internal.community; +import java.io.Serial; import java.util.List; import java.util.Optional; import java.util.stream.Stream; @@ -32,6 +33,7 @@ */ @NonNullByDefault final class SerializedNameAnnotationIntrospector extends AnnotationIntrospector { + @Serial private static final long serialVersionUID = 1L; @Override diff --git a/bundles/org.openhab.core.addon.marketplace/src/test/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonServiceTest.java b/bundles/org.openhab.core.addon.marketplace/src/test/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonServiceTest.java index a00c16cc145..78634383d45 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/test/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonServiceTest.java +++ b/bundles/org.openhab.core.addon.marketplace/src/test/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonServiceTest.java @@ -142,7 +142,7 @@ public void testInstalledAddonIsStillPresentAfterRemoteIsDisabledOrMissing() { // check only the installed addon is present addons = addonService.getAddons(null); assertThat(addons, hasSize(1)); - assertThat(addons.get(0).getUid(), is(getFullAddonId(TEST_ADDON))); + assertThat(addons.getFirst().getUid(), is(getFullAddonId(TEST_ADDON))); } @Test diff --git a/bundles/org.openhab.core.addon/src/test/java/org/openhab/core/addon/AddonInfoListReaderTest.java b/bundles/org.openhab.core.addon/src/test/java/org/openhab/core/addon/AddonInfoListReaderTest.java index 9a433ab6873..aa77733aff4 100644 --- a/bundles/org.openhab.core.addon/src/test/java/org/openhab/core/addon/AddonInfoListReaderTest.java +++ b/bundles/org.openhab.core.addon/src/test/java/org/openhab/core/addon/AddonInfoListReaderTest.java @@ -84,26 +84,26 @@ void testAddonInfoListReader() { assertNotNull(addons); List addonsInfos = addons.getAddons(); assertEquals(1, addonsInfos.size()); - AddonInfo addon = addonsInfos.get(0); + AddonInfo addon = addonsInfos.getFirst(); assertNotNull(addon); List discoveryMethods = addon.getDiscoveryMethods(); assertNotNull(discoveryMethods); assertEquals(2, discoveryMethods.size()); - AddonDiscoveryMethod method = discoveryMethods.get(0); + AddonDiscoveryMethod method = discoveryMethods.getFirst(); assertNotNull(method); assertEquals("mdns", method.getServiceType()); List parameters = method.getParameters(); assertNotNull(parameters); assertEquals(1, parameters.size()); - AddonParameter parameter = parameters.get(0); + AddonParameter parameter = parameters.getFirst(); assertNotNull(parameter); assertEquals("mdnsServiceType", parameter.getName()); assertEquals("_printer._tcp.local.", parameter.getValue()); List matchProperties = method.getMatchProperties(); assertNotNull(matchProperties); assertEquals(2, matchProperties.size()); - AddonMatchProperty property = matchProperties.get(0); + AddonMatchProperty property = matchProperties.getFirst(); assertNotNull(property); assertEquals("rp", property.getName()); assertEquals(".*", property.getRegex()); @@ -118,7 +118,7 @@ void testAddonInfoListReader() { matchProperties = method.getMatchProperties(); assertNotNull(matchProperties); assertEquals(1, matchProperties.size()); - property = matchProperties.get(0); + property = matchProperties.getFirst(); assertNotNull(property); assertEquals("modelName", property.getName()); assertEquals("Philips hue bridge", property.getRegex()); diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/AudioException.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/AudioException.java index cfdfbd219f6..0a061086134 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/AudioException.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/AudioException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.audio; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -24,6 +26,7 @@ @NonNullByDefault public class AudioException extends Exception { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/UnsupportedAudioFormatException.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/UnsupportedAudioFormatException.java index 9bd71726432..480594dd85c 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/UnsupportedAudioFormatException.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/UnsupportedAudioFormatException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.audio; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -25,6 +27,7 @@ @NonNullByDefault public class UnsupportedAudioFormatException extends AudioException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/UnsupportedAudioStreamException.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/UnsupportedAudioStreamException.java index 038516d59af..023f4156d72 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/UnsupportedAudioStreamException.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/UnsupportedAudioStreamException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.audio; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -24,6 +26,7 @@ @NonNullByDefault public class UnsupportedAudioStreamException extends AudioException { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioServlet.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioServlet.java index 350319a72d3..124537808bc 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioServlet.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioServlet.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.Serial; import java.nio.file.Files; import java.util.Collections; import java.util.List; @@ -72,6 +73,7 @@ @NonNullByDefault public class AudioServlet extends HttpServlet implements AudioHTTPServer { + @Serial private static final long serialVersionUID = -3364664035854567854L; private static final List WAV_MIME_TYPES = List.of("audio/wav", "audio/x-wav", "audio/vnd.wave"); diff --git a/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaActionTypeProvider.java b/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaActionTypeProvider.java index 947f8a7a0b2..daae48dac8b 100644 --- a/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaActionTypeProvider.java +++ b/bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/MediaActionTypeProvider.java @@ -16,7 +16,7 @@ import java.io.File; import java.math.BigDecimal; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -138,7 +138,7 @@ private ConfigDescriptionParameter getVolumeConfigDescParam(@Nullable Locale loc */ private List getSoundOptions() { List options = new ArrayList<>(); - File soundsDir = Paths.get(OpenHAB.getConfigFolder(), AudioManager.SOUND_DIR).toFile(); + File soundsDir = Path.of(OpenHAB.getConfigFolder(), AudioManager.SOUND_DIR).toFile(); if (soundsDir.isDirectory()) { for (String fileName : soundsDir.list()) { if (fileName.contains(".") && !fileName.startsWith(".")) { diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineFactoryHelper.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineFactoryHelper.java index 8cb2f84551e..59686f51b93 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineFactoryHelper.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineFactoryHelper.java @@ -42,7 +42,7 @@ private ScriptEngineFactoryHelper() { public static Map.@Nullable Entry getParameterOption(ScriptEngineFactory engineFactory) { List scriptTypes = engineFactory.getScriptTypes(); if (!scriptTypes.isEmpty()) { - ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0)); + ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.getFirst()); if (scriptEngine != null) { Map.Entry parameterOption = Map.entry(getPreferredMimeType(engineFactory), getLanguageName(scriptEngine.getFactory())); @@ -66,7 +66,7 @@ public static String getPreferredMimeType(ScriptEngineFactory factory) { } List mimeTypes = new ArrayList<>(scriptTypes); mimeTypes.removeIf(mimeType -> !mimeType.contains("application") || "application/python".equals(mimeType)); - return mimeTypes.isEmpty() ? scriptTypes.get(0) : mimeTypes.get(0); + return mimeTypes.isEmpty() ? scriptTypes.getFirst() : mimeTypes.getFirst(); } public static String getLanguageName(javax.script.ScriptEngineFactory factory) { diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java index 9bff5d844f7..a9cabd7b2fd 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java @@ -79,7 +79,7 @@ public void addScriptEngineFactory(ScriptEngineFactory engineFactory) { } if (logger.isDebugEnabled()) { if (!scriptTypes.isEmpty()) { - ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0)); + ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.getFirst()); if (scriptEngine != null) { javax.script.ScriptEngineFactory factory = scriptEngine.getFactory(); logger.debug( diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java index e04d601b260..00cb5f0fb6e 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/AbstractScriptModuleHandler.java @@ -105,9 +105,9 @@ protected void compileScript() throws ScriptException { Optional engine = getScriptEngine(); if (engine.isPresent()) { ScriptEngine scriptEngine = engine.get(); - if (scriptEngine instanceof Compilable) { + if (scriptEngine instanceof Compilable compilable) { logger.debug("Pre-compiling script of rule with UID '{}'", ruleUID); - compiledScript = Optional.ofNullable(((Compilable) scriptEngine).compile(script)); + compiledScript = Optional.ofNullable(compilable.compile(script)); } } } diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/provider/ScriptModuleTypeProvider.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/provider/ScriptModuleTypeProvider.java index 586d81c796a..7b564098b9e 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/provider/ScriptModuleTypeProvider.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/provider/ScriptModuleTypeProvider.java @@ -161,7 +161,7 @@ public void setScriptEngineFactory(ScriptEngineFactory engineFactory) { public void unsetScriptEngineFactory(ScriptEngineFactory engineFactory) { List scriptTypes = engineFactory.getScriptTypes(); if (!scriptTypes.isEmpty()) { - ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.get(0)); + ScriptEngine scriptEngine = engineFactory.createScriptEngine(scriptTypes.getFirst()); if (scriptEngine != null) { parameterOptions.remove(ScriptEngineFactoryHelper.getPreferredMimeType(engineFactory)); logger.trace("ParameterOptions: {}", parameterOptions); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandList.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandList.java index a41a84f8d68..43333c06027 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandList.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/AutomationCommandList.java @@ -126,7 +126,7 @@ protected String parseOptionsAndParameters(String[] parameterValues) { } if (getLocale) { String l = parameterValue; - locale = new Locale(l); + locale = Locale.of(l); getLocale = false; } if (getId && getLocale) { diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Printer.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Printer.java index 7d02d3891dd..ebcfefda683 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Printer.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/commands/Printer.java @@ -339,7 +339,7 @@ private static List collectRecords(int[] columnWidths, String prop, Coll if (list != null && !list.isEmpty()) { for (Object element : list) { if (element instanceof String string) { - res.add(Utils.getColumn(columnWidths[0], values.get(0)) + string); + res.add(Utils.getColumn(columnWidths[0], values.getFirst()) + string); if (isFirst) { isFirst = false; values.set(0, ""); @@ -347,7 +347,7 @@ private static List collectRecords(int[] columnWidths, String prop, Coll } else if (element instanceof Module module) { List moduleRecords = getModuleRecords(module); for (String elementRecord : moduleRecords) { - res.add(Utils.getColumn(columnWidths[0], values.get(0)) + elementRecord); + res.add(Utils.getColumn(columnWidths[0], values.getFirst()) + elementRecord); if (isFirst) { isFirst = false; values.set(0, ""); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/exception/UncomparableException.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/exception/UncomparableException.java index 334ab754254..5d561aef87b 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/exception/UncomparableException.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/exception/UncomparableException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.automation.internal.module.exception; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,5 +24,6 @@ @NonNullByDefault public class UncomparableException extends Exception { + @Serial private static final long serialVersionUID = 4891205711357448390L; } diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/provider/AnnotationActionModuleTypeProviderTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/provider/AnnotationActionModuleTypeProviderTest.java index 06db9be58df..dad928affe5 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/provider/AnnotationActionModuleTypeProviderTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/internal/module/provider/AnnotationActionModuleTypeProviderTest.java @@ -196,7 +196,7 @@ public void testMultiServiceAnnotationActions() { List parameterOptions = cdp.getOptions(); assertEquals(1, parameterOptions.size()); - ParameterOption po = parameterOptions.get(0); + ParameterOption po = parameterOptions.getFirst(); assertEquals("conf2", po.getValue()); } } diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProviderTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProviderTest.java index 8bca395d3d3..8a5b9bd54f3 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProviderTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/thingsupport/AnnotatedThingActionModuleTypeProviderTest.java @@ -211,7 +211,7 @@ moduleTypeI18nServiceMock, new AnnotationActionModuleTypeHelper(actionInputsHelp List parameterOptions = cdp.getOptions(); assertEquals(1, parameterOptions.size()); - ParameterOption po = parameterOptions.get(0); + ParameterOption po = parameterOptions.getFirst(); assertEquals("binding:thing-type:test2", po.getValue()); } } diff --git a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelperTest.java b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelperTest.java index f4e54be56e3..c1b176233de 100644 --- a/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelperTest.java +++ b/bundles/org.openhab.core.automation/src/test/java/org/openhab/core/automation/util/ActionInputHelperTest.java @@ -208,7 +208,7 @@ public void testMapActionInputsToConfigDescriptionParametersWhenOk() { List params = helper .mapActionInputsToConfigDescriptionParameters(List.of(input1, input2)); assertThat(params.size(), is(2)); - checkParameter(params.get(0), "Boolean", ConfigDescriptionParameter.Type.BOOLEAN, PARAM_LABEL, + checkParameter(params.getFirst(), "Boolean", ConfigDescriptionParameter.Type.BOOLEAN, PARAM_LABEL, PARAM_DESCRIPTION, true, "false", null, null, null); checkParameter(params.get(1), "String", ConfigDescriptionParameter.Type.TEXT, PARAM_LABEL, PARAM_DESCRIPTION, false, null, null, null, null); diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigUtil.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigUtil.java index 74faff64725..cecefe96813 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigUtil.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/ConfigUtil.java @@ -262,7 +262,7 @@ private static Collection normalizeCollection(Collection<@NonNull ?> col for (final Object it : collection) { final Object normalized = normalizeType(it, null); lst.add(normalized); - if (normalized.getClass() != lst.get(0).getClass()) { + if (normalized.getClass() != lst.getFirst().getClass()) { throw new IllegalArgumentException( "Invalid configuration property. Heterogeneous collection value!"); } diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/validation/ConfigValidationException.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/validation/ConfigValidationException.java index 2ed47a03287..4438f1e77f7 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/validation/ConfigValidationException.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/validation/ConfigValidationException.java @@ -12,6 +12,7 @@ */ package org.openhab.core.config.core.validation; +import java.io.Serial; import java.text.MessageFormat; import java.util.Collection; import java.util.Collections; @@ -35,6 +36,7 @@ */ public final class ConfigValidationException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; private final Logger logger = LoggerFactory.getLogger(ConfigValidationException.class); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java index 6138ead796f..e11a78801e9 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionBuilderTest.java @@ -62,7 +62,7 @@ public void testWithOneParameter() { assertThat(configDescription.getUID(), is(CONFIG_URI)); assertThat(configDescription.getParameterGroups(), hasSize(0)); assertThat(configDescription.getParameters(), hasSize(1)); - assertThat(configDescription.getParameters().get(0), is(PARAM1)); + assertThat(configDescription.getParameters().getFirst(), is(PARAM1)); } @Test @@ -81,7 +81,7 @@ public void testWithOneParameterGroup() { ConfigDescription configDescription = builder.withParameterGroup(GROUP1).build(); assertThat(configDescription.getUID(), is(CONFIG_URI)); assertThat(configDescription.getParameterGroups(), hasSize(1)); - assertThat(configDescription.getParameterGroups().get(0), is(GROUP1)); + assertThat(configDescription.getParameterGroups().getFirst(), is(GROUP1)); assertThat(configDescription.getParameters(), hasSize(0)); } diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java index 65aad7f09cb..293678bff22 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigDescriptionRegistryTest.java @@ -121,9 +121,9 @@ public void testGetConfigDescriptions() throws Exception { assertThat(configDescriptionRegistry.getConfigDescriptions().size(), is(1)); List configDescriptions = new ArrayList<>(configDescriptionRegistry.getConfigDescriptions()); - assertThat(configDescriptions.get(0).getUID(), is(equalTo(uriDummy))); - assertThat(configDescriptions.get(0).toParametersMap().size(), is(1)); - assertThat(configDescriptions.get(0).toParametersMap().get("param1"), notNullValue()); + assertThat(configDescriptions.getFirst().getUID(), is(equalTo(uriDummy))); + assertThat(configDescriptions.getFirst().toParametersMap().size(), is(1)); + assertThat(configDescriptions.getFirst().toParametersMap().get("param1"), notNullValue()); configDescriptionRegistry.addConfigDescriptionProvider(configDescriptionProviderMock1); assertThat(configDescriptionRegistry.getConfigDescriptions().size(), is(2)); @@ -146,11 +146,11 @@ public void testGetConfigDescriptionsOptions() throws Exception { assertThat(configDescriptionRegistry.getConfigDescriptions().size(), is(1)); List configDescriptions = new ArrayList<>(configDescriptionRegistry.getConfigDescriptions()); - assertThat(configDescriptions.get(0).getUID(), is(equalTo(uriDummy))); + assertThat(configDescriptions.getFirst().getUID(), is(equalTo(uriDummy))); - assertThat(configDescriptions.get(0).getParameters().size(), is(2)); - assertThat(configDescriptions.get(0).getParameters().get(0).getName(), is(equalTo("param1"))); - assertThat(configDescriptions.get(0).getParameters().get(1).getName(), is(equalTo("param2"))); + assertThat(configDescriptions.getFirst().getParameters().size(), is(2)); + assertThat(configDescriptions.getFirst().getParameters().getFirst().getName(), is(equalTo("param1"))); + assertThat(configDescriptions.getFirst().getParameters().get(1).getName(), is(equalTo("param2"))); configDescriptionRegistry.removeConfigDescriptionProvider(configDescriptionProviderMock); assertThat(configDescriptionRegistry.getConfigDescriptions().size(), is(1)); @@ -168,8 +168,8 @@ public void testGetConfigDescriptionsAliasedOptions() throws Exception { configDescriptionRegistry.addConfigOptionProvider(configOptionsProviderMockAliased); ConfigDescription res = requireNonNull(configDescriptionRegistry.getConfigDescription(uriAliases)); - assertThat(res.getParameters().get(0).getOptions().size(), is(1)); - assertThat(res.getParameters().get(0).getOptions().get(0).getLabel(), is("Aliased")); + assertThat(res.getParameters().getFirst().getOptions().size(), is(1)); + assertThat(res.getParameters().getFirst().getOptions().getFirst().getLabel(), is("Aliased")); assertThat(res.getUID(), is(uriAliases)); configDescriptionRegistry.removeConfigDescriptionProvider(configDescriptionProviderMock); @@ -186,8 +186,8 @@ public void testGetConfigDescriptionsAliasedOptionsOriginalWins() throws Excepti configDescriptionRegistry.addConfigOptionProvider(configOptionsProviderMockAliased); ConfigDescription res = requireNonNull(configDescriptionRegistry.getConfigDescription(uriAliases)); - assertThat(res.getParameters().get(0).getOptions().size(), is(1)); - assertThat(res.getParameters().get(0).getOptions().get(0).getLabel(), is("Aliased")); + assertThat(res.getParameters().getFirst().getOptions().size(), is(1)); + assertThat(res.getParameters().getFirst().getOptions().getFirst().getLabel(), is("Aliased")); assertThat(res.getUID(), is(uriAliases)); configDescriptionRegistry.removeConfigDescriptionProvider(configDescriptionProviderMock); @@ -203,8 +203,8 @@ public void testGetConfigDescriptionsNonAliasOptions() throws Exception { configDescriptionRegistry.addConfigOptionProvider(configOptionsProviderMock); ConfigDescription res = requireNonNull(configDescriptionRegistry.getConfigDescription(uriAliases)); - assertThat(res.getParameters().get(0).getOptions().size(), is(1)); - assertThat(res.getParameters().get(0).getOptions().get(0).getLabel(), is("Original")); + assertThat(res.getParameters().getFirst().getOptions().size(), is(1)); + assertThat(res.getParameters().getFirst().getOptions().getFirst().getLabel(), is("Original")); assertThat(res.getUID(), is(uriAliases)); configDescriptionRegistry.removeConfigDescriptionProvider(configDescriptionProviderMock); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java index 9a103703b95..891dddb4f8d 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/ConfigurationTest.java @@ -119,7 +119,7 @@ public void assertConfigAllowsNullValues() { configuration.put("stringField", "someValue"); configuration.put("additionalField", ""); assertThat(props.get("stringField"), is(nullValue())); - assertThat(values.get(0), is(nullValue())); + assertThat(values.getFirst(), is(nullValue())); assertThat(values.get(1), is(nullValue())); assertThat(values.size(), is(2)); assertThat(keys.size(), is(2)); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/dto/ConfigDescriptionDTOTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/dto/ConfigDescriptionDTOTest.java index 0d6c07c5c5a..a737e3dbc2b 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/dto/ConfigDescriptionDTOTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/dto/ConfigDescriptionDTOTest.java @@ -85,7 +85,7 @@ public void testConfigDescriptionParameterDTOMappingIsBidirectional() { .map(ConfigDescriptionDTOMapper.mapParameters(subject)); assertThat(result, hasSize(1)); - ConfigDescriptionParameter parameter = result.get(0); + ConfigDescriptionParameter parameter = result.getFirst(); assertThat(parameter.getName(), is(PARAM_NAME)); assertThat(parameter.getType(), is(Type.INTEGER)); assertThat(parameter.isAdvanced(), is(true)); @@ -120,7 +120,7 @@ public void testConfigDescriptionParameterGroupDTOMappingIsBidirectional() { .mapParameterGroupsDTO(ConfigDescriptionDTOMapper.mapParameterGroups(subject)); assertThat(result, hasSize(1)); - ConfigDescriptionParameterGroup parameterGroup = result.get(0); + ConfigDescriptionParameterGroup parameterGroup = result.getFirst(); assertThat(parameterGroup.getName(), is(PARAMETER_GROUP_NAME)); assertThat(parameterGroup.isAdvanced(), is(true)); assertThat(parameterGroup.getContext(), is(PARAMETER_GROUP_CONTEXT)); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java index 31ad7f079b5..508b22efde3 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/metadata/MetadataConfigDescriptionProviderImplTest.java @@ -92,7 +92,7 @@ public void testGetConfigDescriptionsNoOptions() { assertEquals(URI_LIBERAL, desc.getUID()); assertEquals(1, desc.getParameters().size()); - ConfigDescriptionParameter param = desc.getParameters().get(0); + ConfigDescriptionParameter param = desc.getParameters().getFirst(); assertEquals("value", param.getName()); assertEquals("Liberal", param.getDescription()); assertFalse(param.getLimitToOptions()); @@ -110,11 +110,11 @@ public void testGetConfigDescriptionsWithOptions() { assertEquals(URI_RESTRICTED, desc.getUID()); assertEquals(1, desc.getParameters().size()); - ConfigDescriptionParameter param = desc.getParameters().get(0); + ConfigDescriptionParameter param = desc.getParameters().getFirst(); assertEquals("value", param.getName()); assertEquals("Restricted", param.getDescription()); assertTrue(param.getLimitToOptions()); - assertEquals("dimmer", param.getOptions().get(0).getValue()); + assertEquals("dimmer", param.getOptions().getFirst().getValue()); assertEquals("switch", param.getOptions().get(1).getValue()); } @@ -136,7 +136,7 @@ public void testGetConfigDescriptionValueDescription() { assertEquals(URI_LIBERAL, desc.getUID()); assertEquals(1, desc.getParameters().size()); - ConfigDescriptionParameter param = desc.getParameters().get(0); + ConfigDescriptionParameter param = desc.getParameters().getFirst(); assertEquals("value", param.getName()); assertEquals("Liberal", param.getDescription()); assertFalse(param.getLimitToOptions()); @@ -161,7 +161,7 @@ public void testGetConfigDescriptionPropertiesDescription() { assertEquals(URI_RESTRICTED_DIMMER, desc.getUID()); assertEquals(2, desc.getParameters().size()); - ConfigDescriptionParameter paramWidth = desc.getParameters().get(0); + ConfigDescriptionParameter paramWidth = desc.getParameters().getFirst(); assertEquals("width", paramWidth.getName()); ConfigDescriptionParameter paramHeight = desc.getParameters().get(1); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusServiceTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusServiceTest.java index 8b7e64879e0..5af90e356e7 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusServiceTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/status/ConfigStatusServiceTest.java @@ -47,8 +47,8 @@ public class ConfigStatusServiceTest extends JavaTest { private static final String ENTITY_ID1 = "entity1"; private static final String ENTITY_ID2 = "entity2"; - private static final Locale LOCALE_DE = new Locale("de"); - private static final Locale LOCALE_EN = new Locale("en"); + private static final Locale LOCALE_DE = Locale.of("de"); + private static final Locale LOCALE_EN = Locale.of("en"); private static final String PARAM1 = "param1"; private static final String PARAM2 = "param2"; @@ -108,7 +108,7 @@ public void setUp() { MessageFormat.format(MSG3_EN, ARGS), PARAM3_MSG3.statusCode)); LocaleProvider localeProvider = mock(LocaleProvider.class); - when(localeProvider.getLocale()).thenReturn(new Locale("en", "US")); + when(localeProvider.getLocale()).thenReturn(Locale.of("en", "US")); configStatusService = new ConfigStatusService(mock(EventPublisher.class), localeProvider, getTranslationProvider(), mock(BundleResolver.class)); diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/xml/util/XmlDocumentReaderTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/xml/util/XmlDocumentReaderTest.java index 9e6a8593d12..8c421ecf3f1 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/xml/util/XmlDocumentReaderTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/xml/util/XmlDocumentReaderTest.java @@ -88,17 +88,18 @@ public void defaultSecurityDisallowsDeserializingNonOHCobjects() throws Exceptio */ @Test public void defaultSecurityProtectsAgainstRemoteCodeExecution() throws Exception { - String xml = "\n" // - + " org.openhab.core.Contact\n" - + " \n" // - + " \n" // - + " \n" // - + " calc.exe\n" // - + " \n" // - + " \n" // - + " start\n" // - + " \n" // - + ""; + String xml = """ + + org.openhab.core.Contact + + + + calc.exe + + + start + + """; assertThrows(ForbiddenClassException.class, () -> readXML(xml)); } diff --git a/bundles/org.openhab.core.config.discovery.addon.upnp/src/test/java/org/openhab/core/config/discovery/addon/upnp/tests/UpnpAddonFinderTests.java b/bundles/org.openhab.core.config.discovery.addon.upnp/src/test/java/org/openhab/core/config/discovery/addon/upnp/tests/UpnpAddonFinderTests.java index 34079d518f9..ec3a15dca7c 100644 --- a/bundles/org.openhab.core.config.discovery.addon.upnp/src/test/java/org/openhab/core/config/discovery/addon/upnp/tests/UpnpAddonFinderTests.java +++ b/bundles/org.openhab.core.config.discovery.addon.upnp/src/test/java/org/openhab/core/config/discovery/addon/upnp/tests/UpnpAddonFinderTests.java @@ -114,7 +114,7 @@ private void setupMockUpnpService() { assertNotNull(upnpService); List result = new ArrayList<>(upnpService.getRegistry().getRemoteDevices()); assertEquals(1, result.size()); - RemoteDevice device = result.get(0); + RemoteDevice device = result.getFirst(); assertEquals("manufacturer", device.getDetails().getManufacturerDetails().getManufacturer()); assertEquals("serialNumber", device.getDetails().getSerialNumber()); } diff --git a/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDiscoveryService.java b/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDiscoveryService.java index 257690ef0e8..877095b1195 100644 --- a/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDiscoveryService.java +++ b/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDiscoveryService.java @@ -159,7 +159,7 @@ public Optional createSddpDevice(String data) { if (!data.isBlank()) { List lines = data.lines().toList(); if (lines.size() > 1) { - String statement = lines.get(0).strip(); + String statement = lines.getFirst().strip(); boolean offline = statement.startsWith(NOTIFY_OFFLINE_HEADER); if (offline || statement.startsWith(NOTIFY_ALIVE_HEADER) || statement.startsWith(NOTIFY_IDENTIFY_HEADER) || statement.startsWith(SEARCH_RESPONSE_HEADER)) { diff --git a/bundles/org.openhab.core.config.discovery.usbserial.linuxsysfs/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysfsUsbSerialScanner.java b/bundles/org.openhab.core.config.discovery.usbserial.linuxsysfs/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysfsUsbSerialScanner.java index 05f05947599..098138a3130 100644 --- a/bundles/org.openhab.core.config.discovery.usbserial.linuxsysfs/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysfsUsbSerialScanner.java +++ b/bundles/org.openhab.core.config.discovery.usbserial.linuxsysfs/src/main/java/org/openhab/core/config/discovery/usbserial/linuxsysfs/internal/SysfsUsbSerialScanner.java @@ -18,7 +18,6 @@ import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashSet; import java.util.Map; import java.util.Objects; @@ -127,7 +126,7 @@ public Set scan() throws IOException { @Override public boolean canPerformScans() { - return isReadable(Paths.get(sysfsTtyDevicesDirectory)) && isReadable(Paths.get(devDirectory)); + return isReadable(Path.of(sysfsTtyDevicesDirectory)) && isReadable(Path.of(devDirectory)); } /** @@ -140,10 +139,10 @@ public boolean canPerformScans() { private Set getSerialPortInfos() throws IOException { Set result = new HashSet<>(); - try (DirectoryStream sysfsTtyPaths = newDirectoryStream(Paths.get(sysfsTtyDevicesDirectory))) { + try (DirectoryStream sysfsTtyPaths = newDirectoryStream(Path.of(sysfsTtyDevicesDirectory))) { for (Path sysfsTtyPath : sysfsTtyPaths) { String serialPortName = sysfsTtyPath.getFileName().toString(); - Path devicePath = Paths.get(devDirectory).resolve(serialPortName); + Path devicePath = Path.of(devDirectory).resolve(serialPortName); Path sysfsDevicePath = getRealDevicePath(sysfsTtyPath); if (sysfsDevicePath != null && isReadable(devicePath) && isWritable(devicePath)) { result.add(new SerialPortInfo(devicePath, sysfsDevicePath)); @@ -163,7 +162,7 @@ private Set getSerialPortInfos() throws IOException { String serialPortName = devicePath.getFileName().toString(); // get the corresponding real sysinfo special dir : Path sysfsDevicePath = getRealDevicePath( - Paths.get(sysfsTtyDevicesDirectory).resolve(serialPortName)); + Path.of(sysfsTtyDevicesDirectory).resolve(serialPortName)); if (sysfsDevicePath != null && isReadable(devicePath) && isWritable(devicePath)) { result.add(new SerialPortInfo(devLinkPath, sysfsDevicePath)); } diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessor.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessor.java index 55e7dd0e295..5a3363b214d 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessor.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessor.java @@ -217,7 +217,7 @@ private void ignoreInInbox(ThingTypeUID thingtypeUID, String representationValue if (results.size() == 1) { logger.debug("Auto-ignoring the inbox entry for the representation value '{}'.", representationValue); - inbox.setFlag(results.get(0).getThingUID(), DiscoveryResultFlag.IGNORED); + inbox.setFlag(results.getFirst().getThingUID(), DiscoveryResultFlag.IGNORED); } } @@ -255,7 +255,7 @@ private void removeFromInbox(ThingTypeUID thingtypeUID, String representationVal if (results.size() == 1) { logger.debug("Removing the ignored result from the inbox for the representation value '{}'.", representationValue); - inbox.remove(results.get(0).getThingUID()); + inbox.remove(results.getFirst().getThingUID()); } } diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/PersistentInbox.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/PersistentInbox.java index 554267def98..f07181c5308 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/PersistentInbox.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/PersistentInbox.java @@ -192,7 +192,7 @@ protected void deactivate() { if (newThingId != null && newThingId.contains(AbstractUID.SEPARATOR)) { throw new IllegalArgumentException("New Thing ID " + newThingId + " must not contain multiple segments"); } - DiscoveryResult result = results.get(0); + DiscoveryResult result = results.getFirst(); final Map properties = new HashMap<>(); final Map configParams = new HashMap<>(); getPropsAndConfigParams(result, properties, configParams); diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/DiscoveryConsoleCommandExtension.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/DiscoveryConsoleCommandExtension.java index af89b6e35c7..dc9dafb5ac4 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/DiscoveryConsoleCommandExtension.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/DiscoveryConsoleCommandExtension.java @@ -102,7 +102,7 @@ public void execute(String[] args, Console console) { break; } } else { - console.println(getUsages().get(0)); + console.println(getUsages().getFirst()); } } diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/InboxPredicatesTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/InboxPredicatesTest.java index 8e869438c8e..4b4aa237a6a 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/InboxPredicatesTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/InboxPredicatesTest.java @@ -81,7 +81,7 @@ public void testForBinding() { assertThat(RESULTS.stream().filter(forBinding(BINDING_ID1)).toList().size(), is(3)); assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).toList().size(), is(1)); - assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).toList().get(0), is(equalTo(RESULTS.get(3)))); + assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).toList().getFirst(), is(equalTo(RESULTS.get(3)))); assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).filter(withFlag(DiscoveryResultFlag.NEW)).toList() .size(), is(0)); @@ -89,7 +89,7 @@ public void testForBinding() { assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).filter(withFlag(DiscoveryResultFlag.IGNORED)) .toList().size(), is(1)); assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).filter(withFlag(DiscoveryResultFlag.IGNORED)) - .toList().get(0), is(equalTo(RESULTS.get(3)))); + .toList().getFirst(), is(equalTo(RESULTS.get(3)))); } @Test @@ -97,27 +97,28 @@ public void testForThingTypeUID() { assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID11)).toList().size(), is(2)); assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID12)).toList().size(), is(1)); - assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID12)).toList().get(0), + assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID12)).toList().getFirst(), is(equalTo(RESULTS.get(2)))); } @Test public void testForThingUID() { assertThat(RESULTS.stream().filter(forThingUID(THING_UID11)).toList().size(), is(1)); - assertThat(RESULTS.stream().filter(forThingUID(THING_UID11)).toList().get(0), is(equalTo(RESULTS.get(0)))); + assertThat(RESULTS.stream().filter(forThingUID(THING_UID11)).toList().getFirst(), + is(equalTo(RESULTS.getFirst()))); assertThat(RESULTS.stream().filter(forThingUID(THING_UID12)).toList().size(), is(2)); assertThat(RESULTS.stream().filter(forThingUID(THING_UID12)).filter(forThingTypeUID(THING_TYPE_UID12)).toList() .size(), is(1)); assertThat(RESULTS.stream().filter(forThingUID(THING_UID12)).filter(forThingTypeUID(THING_TYPE_UID12)).toList() - .get(0), is(equalTo(RESULTS.get(2)))); + .getFirst(), is(equalTo(RESULTS.get(2)))); } @Test public void testWithFlag() { assertThat(RESULTS.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList().size(), is(3)); assertThat(RESULTS.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList().size(), is(1)); - assertThat(RESULTS.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList().get(0), + assertThat(RESULTS.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList().getFirst(), is(equalTo(RESULTS.get(3)))); } @@ -133,20 +134,20 @@ public void testWithProperty() { @Test public void testWithRepresentationProperty() { assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP1)).toList().size(), is(1)); - assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP1)).toList().get(0), - is(equalTo(RESULTS.get(0)))); + assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP1)).toList().getFirst(), + is(equalTo(RESULTS.getFirst()))); assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP2)).toList().size(), is(1)); - assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP2)).toList().get(0), + assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP2)).toList().getFirst(), is(equalTo(RESULTS.get(2)))); } @Test public void testWithRepresentationPropertyValue() { assertThat(RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL1)).toList().size(), is(1)); - assertThat(RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL1)).toList().get(0), - is(equalTo(RESULTS.get(0)))); + assertThat(RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL1)).toList().getFirst(), + is(equalTo(RESULTS.getFirst()))); assertThat(RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL2)).toList().size(), is(1)); - assertThat(RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL2)).toList().get(0), + assertThat(RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL2)).toList().getFirst(), is(equalTo(RESULTS.get(2)))); } } diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessorTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessorTest.java index 80dc25b2eda..8e9edb25d53 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessorTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/internal/AutomaticInboxProcessorTest.java @@ -168,7 +168,7 @@ public void testThingWithOtherBindingIDButSameRepresentationPropertyWentOnline() // Then there is a discovery result which is NEW List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID))); // Now a thing with thing type THING_TYPE_UID3 goes online, with representation property value being also the // device id @@ -181,7 +181,7 @@ public void testThingWithOtherBindingIDButSameRepresentationPropertyWentOnline() // Then there should still be the NEW discovery result, but no IGNORED discovery result results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID))); results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(0)); } @@ -203,7 +203,7 @@ public void testThingWithOtherBindingIDButSameRepresentationPropertyIsDiscovered // Then there is a discovery result which is NEW results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID3))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID3))); } @Test @@ -213,7 +213,7 @@ public void testThingWentOnline() { List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID))); when(thingRegistryMock.get(THING_UID)).thenReturn(thingMock); when(thingStatusInfoChangedEventMock.getStatusInfo()) @@ -225,7 +225,7 @@ public void testThingWentOnline() { assertThat(results.size(), is(0)); results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID))); } @Test @@ -239,7 +239,7 @@ public void testThingWhenNoRepresentationPropertySet() { inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID).build()); List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID))); when(thingMock.getProperties()).thenReturn(Map.of()); when(thingStatusInfoChangedEventMock.getStatusInfo()) @@ -266,7 +266,7 @@ public void testInboxHasBeenChanged() { assertThat(results.size(), is(0)); results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID2))); } @Test @@ -277,7 +277,7 @@ public void testThingIsBeingRemoved() { inbox.setFlag(THING_UID, DiscoveryResultFlag.IGNORED); List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID))); automaticInboxProcessor.removed(thingMock); @@ -302,7 +302,7 @@ public void testOneThingOutOfTwoWithSameRepresentationPropertyButDifferentBindin results = inbox.getAll(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID3))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID3))); } @Test @@ -312,7 +312,7 @@ public void testThingWithConfigWentOnline() { List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID2))); when(thingRegistryMock.get(THING_UID2)).thenReturn(thing2Mock); when(thingStatusInfoChangedEventMock.getStatusInfo()) @@ -324,7 +324,7 @@ public void testThingWithConfigWentOnline() { assertThat(results.size(), is(0)); results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID2))); } @Test @@ -342,7 +342,7 @@ public void testInboxWithConfigHasBeenChanged() { assertThat(results.size(), is(0)); results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID))); } @Test @@ -353,7 +353,7 @@ public void testThingWithConfigIsBeingRemoved() { inbox.setFlag(THING_UID2, DiscoveryResultFlag.IGNORED); List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); - assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); + assertThat(results.getFirst().getThingUID(), is(equalTo(THING_UID2))); automaticInboxProcessor.removed(thing2Mock); diff --git a/bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java b/bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java index 72389cde34c..876ba1ee527 100644 --- a/bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java +++ b/bundles/org.openhab.core.config.dispatch/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcher.java @@ -294,7 +294,7 @@ private void internalProcessConfigFile(File configFile) throws IOException { // configuration file contains a PID Marker List lines = Files.readAllLines(configFile.toPath(), StandardCharsets.UTF_8); - String exclusivePID = !lines.isEmpty() ? getPIDFromLine(lines.get(0)) : null; + String exclusivePID = !lines.isEmpty() ? getPIDFromLine(lines.getFirst()) : null; if (exclusivePID != null) { if (exclusivePIDMap.contains(exclusivePID)) { logger.warn( diff --git a/bundles/org.openhab.core.id/src/test/java/org/openhab/core/id/InstanceUUIDTest.java b/bundles/org.openhab.core.id/src/test/java/org/openhab/core/id/InstanceUUIDTest.java index ac033354b70..321f20820eb 100644 --- a/bundles/org.openhab.core.id/src/test/java/org/openhab/core/id/InstanceUUIDTest.java +++ b/bundles/org.openhab.core.id/src/test/java/org/openhab/core/id/InstanceUUIDTest.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.Test; @@ -41,7 +40,7 @@ public void sameUUID() { public void readFromPersistedFile() throws IOException { // we first need to remove the cached value InstanceUUID.uuid = null; - Path path = Paths.get(OpenHAB.getUserDataFolder(), InstanceUUID.UUID_FILE_NAME); + Path path = Path.of(OpenHAB.getUserDataFolder(), InstanceUUID.UUID_FILE_NAME); Files.createDirectories(path.getParent()); Files.write(path, "123".getBytes()); String uuid = InstanceUUID.get(); @@ -52,7 +51,7 @@ public void readFromPersistedFile() throws IOException { public void ignoreEmptyFile() throws IOException { // we first need to remove the cached value InstanceUUID.uuid = null; - Path path = Paths.get(OpenHAB.getUserDataFolder(), InstanceUUID.UUID_FILE_NAME); + Path path = Path.of(OpenHAB.getUserDataFolder(), InstanceUUID.UUID_FILE_NAME); Files.createDirectories(path.getParent()); Files.write(path, "".getBytes()); String uuid = InstanceUUID.get(); diff --git a/bundles/org.openhab.core.io.bin2json/src/main/java/org/openhab/core/io/bin2json/ConversionException.java b/bundles/org.openhab.core.io.bin2json/src/main/java/org/openhab/core/io/bin2json/ConversionException.java index 64ac27d80dc..ffd8e79b55d 100644 --- a/bundles/org.openhab.core.io.bin2json/src/main/java/org/openhab/core/io/bin2json/ConversionException.java +++ b/bundles/org.openhab.core.io.bin2json/src/main/java/org/openhab/core/io/bin2json/ConversionException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.bin2json; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,6 +24,7 @@ @NonNullByDefault public class ConversionException extends Exception { + @Serial private static final long serialVersionUID = 1L; public ConversionException() { diff --git a/bundles/org.openhab.core.io.console.karaf/src/test/java/org/openhab/core/io/console/karaf/internal/CompleterWrapperTest.java b/bundles/org.openhab.core.io.console.karaf/src/test/java/org/openhab/core/io/console/karaf/internal/CompleterWrapperTest.java index e5d0217fba9..119a8da557d 100644 --- a/bundles/org.openhab.core.io.console.karaf/src/test/java/org/openhab/core/io/console/karaf/internal/CompleterWrapperTest.java +++ b/bundles/org.openhab.core.io.console.karaf/src/test/java/org/openhab/core/io/console/karaf/internal/CompleterWrapperTest.java @@ -61,8 +61,8 @@ public void fillsCommandDescriptionsLocalOnly() { completerWrapper.completeCandidates(session, commandLine, candidates); assertEquals(1, candidates.size()); - assertEquals("command", candidates.get(0).value()); - assertEquals("description", candidates.get(0).descr()); + assertEquals("command", candidates.getFirst().value()); + assertEquals("description", candidates.getFirst().descr()); } @Test @@ -75,8 +75,8 @@ public void fillsCommandDescriptionsLocalAndGlobal() { completerWrapper.completeCandidates(session, commandLine, candidates); assertEquals(2, candidates.size()); - assertEquals("command", candidates.get(0).value()); - assertEquals("description", candidates.get(0).descr()); + assertEquals("command", candidates.getFirst().value()); + assertEquals("description", candidates.getFirst().descr()); assertEquals("openhab:command", candidates.get(1).value()); assertEquals("description", candidates.get(1).descr()); diff --git a/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/StringsCompleterTest.java b/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/StringsCompleterTest.java index 9074eb1be7f..2479eb6856a 100644 --- a/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/StringsCompleterTest.java +++ b/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/StringsCompleterTest.java @@ -33,7 +33,7 @@ public void completeSimple() { // positive match assertTrue(sc.complete(new String[] { "a" }, 0, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("abc ", candidates.get(0)); + assertEquals("abc ", candidates.getFirst()); candidates.clear(); // negative match @@ -43,25 +43,25 @@ public void completeSimple() { // case insensitive assertTrue(sc.complete(new String[] { "A" }, 0, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("abc ", candidates.get(0)); + assertEquals("abc ", candidates.getFirst()); candidates.clear(); // second argument assertTrue(sc.complete(new String[] { "a", "d" }, 1, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("def ", candidates.get(0)); + assertEquals("def ", candidates.getFirst()); candidates.clear(); // cursor not at end of word (truncates rest) assertTrue(sc.complete(new String[] { "a", "dg" }, 1, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("def ", candidates.get(0)); + assertEquals("def ", candidates.getFirst()); candidates.clear(); // first argument when second is present assertTrue(sc.complete(new String[] { "a", "d" }, 0, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("abc ", candidates.get(0)); + assertEquals("abc ", candidates.getFirst()); } @Test @@ -77,7 +77,7 @@ public void caseSensitive() { assertTrue(sc.complete(new String[] { "AB" }, 0, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("ABc ", candidates.get(0)); + assertEquals("ABc ", candidates.getFirst()); } @Test @@ -87,7 +87,7 @@ public void multipleCandidates() { assertTrue(sc.complete(new String[] { "abcd" }, 0, 4, candidates)); assertEquals(5, candidates.size()); - assertEquals("abcdd ", candidates.get(0)); + assertEquals("abcdd ", candidates.getFirst()); assertEquals("abcde ", candidates.get(1)); assertEquals("abcdee ", candidates.get(2)); assertEquals("abcdef ", candidates.get(3)); @@ -96,13 +96,13 @@ public void multipleCandidates() { assertTrue(sc.complete(new String[] { "abcde" }, 0, 5, candidates)); assertEquals(3, candidates.size()); - assertEquals("abcde ", candidates.get(0)); + assertEquals("abcde ", candidates.getFirst()); assertEquals("abcdee ", candidates.get(1)); assertEquals("abcdef ", candidates.get(2)); candidates.clear(); assertTrue(sc.complete(new String[] { "abcdee" }, 0, 6, candidates)); assertEquals(1, candidates.size()); - assertEquals("abcdee ", candidates.get(0)); + assertEquals("abcdee ", candidates.getFirst()); } } diff --git a/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandCompleterTest.java b/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandCompleterTest.java index 58066cd863c..0b8186be72e 100644 --- a/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandCompleterTest.java +++ b/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandCompleterTest.java @@ -63,13 +63,13 @@ public void completeItems() throws ItemNotFoundException, ItemNotUniqueException assertTrue(completer.complete(new String[] { "It" }, 0, 2, candidates)); assertEquals(2, candidates.size()); - assertEquals("Item1 ", candidates.get(0)); + assertEquals("Item1 ", candidates.getFirst()); assertEquals("Item2 ", candidates.get(1)); candidates.clear(); assertTrue(completer.complete(new String[] { "JI" }, 0, 2, candidates)); assertEquals(1, candidates.size()); - assertEquals("JItem1 ", candidates.get(0)); + assertEquals("JItem1 ", candidates.getFirst()); candidates.clear(); // case sensitive @@ -98,7 +98,7 @@ public void completeSend() throws ItemNotFoundException, ItemNotUniqueException assertTrue(completer.complete(new String[] { "Item1", "" }, 1, 0, candidates)); assertEquals(3, candidates.size()); - assertEquals("OFF ", candidates.get(0)); + assertEquals("OFF ", candidates.getFirst()); assertEquals("ON ", candidates.get(1)); assertEquals("REFRESH ", candidates.get(2)); candidates.clear(); @@ -106,7 +106,7 @@ public void completeSend() throws ItemNotFoundException, ItemNotUniqueException // case insensitive assertTrue(completer.complete(new String[] { "Item1", "o" }, 1, 1, candidates)); assertEquals(2, candidates.size()); - assertEquals("OFF ", candidates.get(0)); + assertEquals("OFF ", candidates.getFirst()); assertEquals("ON ", candidates.get(1)); } @@ -123,7 +123,7 @@ public void completeUpdate() throws ItemNotFoundException, ItemNotUniqueExceptio assertTrue(completer.complete(new String[] { "Item1", "" }, 1, 0, candidates)); assertEquals(4, candidates.size()); - assertEquals("NULL ", candidates.get(0)); + assertEquals("NULL ", candidates.getFirst()); assertEquals("OFF ", candidates.get(1)); assertEquals("ON ", candidates.get(2)); assertEquals("UNDEF ", candidates.get(3)); @@ -132,7 +132,7 @@ public void completeUpdate() throws ItemNotFoundException, ItemNotUniqueExceptio // case insensitive assertTrue(completer.complete(new String[] { "Item1", "o" }, 1, 1, candidates)); assertEquals(2, candidates.size()); - assertEquals("OFF ", candidates.get(0)); + assertEquals("OFF ", candidates.getFirst()); assertEquals("ON ", candidates.get(1)); } } diff --git a/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandExtensionTest.java b/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandExtensionTest.java index 848d7f31363..d87bdd610e4 100644 --- a/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandExtensionTest.java +++ b/bundles/org.openhab.core.io.console/src/test/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandExtensionTest.java @@ -52,7 +52,7 @@ public void completeSubcommands() { assertTrue(completer.complete(new String[] { "" }, 0, 0, candidates)); assertEquals(5, candidates.size()); - assertEquals("addTag ", candidates.get(0)); + assertEquals("addTag ", candidates.getFirst()); assertEquals("clear ", candidates.get(1)); assertEquals("list ", candidates.get(2)); assertEquals("remove ", candidates.get(3)); @@ -61,7 +61,7 @@ public void completeSubcommands() { assertTrue(completer.complete(new String[] { "A", "Item1" }, 0, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("addTag ", candidates.get(0)); + assertEquals("addTag ", candidates.getFirst()); } @Test @@ -75,17 +75,17 @@ public void completeManagedItems() { assertTrue(completer.complete(new String[] { "addTag", "I" }, 0, 6, candidates)); assertEquals(1, candidates.size()); - assertEquals("addTag ", candidates.get(0)); + assertEquals("addTag ", candidates.getFirst()); candidates.clear(); assertTrue(completer.complete(new String[] { "addTag", "I" }, 1, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("Item1 ", candidates.get(0)); + assertEquals("Item1 ", candidates.getFirst()); candidates.clear(); assertTrue(completer.complete(new String[] { "rmTag", "I" }, 1, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("Item1 ", candidates.get(0)); + assertEquals("Item1 ", candidates.getFirst()); } @Test @@ -96,12 +96,12 @@ public void completeAllItems() { assertTrue(completer.complete(new String[] { "remove", "I" }, 0, 6, candidates)); assertEquals(1, candidates.size()); - assertEquals("remove ", candidates.get(0)); + assertEquals("remove ", candidates.getFirst()); candidates.clear(); assertTrue(completer.complete(new String[] { "remove", "I" }, 1, 1, candidates)); assertEquals(1, candidates.size()); - assertEquals("Item2 ", candidates.get(0)); + assertEquals("Item2 ", candidates.getFirst()); } @Test @@ -135,6 +135,6 @@ public void completeRmTag() { assertTrue(completer.complete(new String[] { "rmTag", "Item3", "" }, 2, 0, candidates)); assertEquals(1, candidates.size()); - assertEquals("Tag1 ", candidates.get(0)); + assertEquals("Tag1 ", candidates.getFirst()); } } diff --git a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AbstractAuthPageServlet.java b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AbstractAuthPageServlet.java index bc0cadc46b8..85dfc4affbc 100644 --- a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AbstractAuthPageServlet.java +++ b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AbstractAuthPageServlet.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.Serial; import java.io.UncheckedIOException; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -51,6 +52,7 @@ @NonNullByDefault public abstract class AbstractAuthPageServlet extends HttpServlet { + @Serial private static final long serialVersionUID = 5340598701104679840L; private static final String MESSAGES_BUNDLE_NAME = "messages"; diff --git a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AuthorizePageServlet.java b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AuthorizePageServlet.java index bed3df76d25..2168ea0de95 100644 --- a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AuthorizePageServlet.java +++ b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/AuthorizePageServlet.java @@ -13,6 +13,7 @@ package org.openhab.core.io.http.auth.internal; import java.io.IOException; +import java.io.Serial; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -62,6 +63,7 @@ public class AuthorizePageServlet extends AbstractAuthPageServlet { public static final String SERVLET_PATH = "/auth"; + @Serial private static final long serialVersionUID = 5340598701104679843L; private final Logger logger = LoggerFactory.getLogger(AuthorizePageServlet.class); diff --git a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/ChangePasswordPageServlet.java b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/ChangePasswordPageServlet.java index e45e8049ea3..5cf3210f7a3 100644 --- a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/ChangePasswordPageServlet.java +++ b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/ChangePasswordPageServlet.java @@ -13,6 +13,7 @@ package org.openhab.core.io.http.auth.internal; import java.io.IOException; +import java.io.Serial; import java.util.Map; import javax.servlet.Servlet; @@ -48,6 +49,7 @@ public class ChangePasswordPageServlet extends AbstractAuthPageServlet { public static final String SERVLET_PATH = "/changePassword"; + @Serial private static final long serialVersionUID = 5340598701104679843L; @Activate diff --git a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/CreateAPITokenPageServlet.java b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/CreateAPITokenPageServlet.java index 5812889ebd5..f09145e49c6 100644 --- a/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/CreateAPITokenPageServlet.java +++ b/bundles/org.openhab.core.io.http.auth/src/main/java/org/openhab/core/io/http/auth/internal/CreateAPITokenPageServlet.java @@ -13,6 +13,7 @@ package org.openhab.core.io.http.auth.internal; import java.io.IOException; +import java.io.Serial; import java.util.Map; import javax.servlet.Servlet; @@ -46,6 +47,7 @@ @HttpWhiteboardServletPattern(CreateAPITokenPageServlet.SERVLET_PATH + "/*") public class CreateAPITokenPageServlet extends AbstractAuthPageServlet { + @Serial private static final long serialVersionUID = 5340598701104679843L; public static final String SERVLET_PATH = "/createApiToken"; diff --git a/bundles/org.openhab.core.io.monitor/src/test/java/org/openhab/core/io/monitor/internal/metrics/ThingStateMetricTest.java b/bundles/org.openhab.core.io.monitor/src/test/java/org/openhab/core/io/monitor/internal/metrics/ThingStateMetricTest.java index 7dce3023bbe..3a1a5870b20 100644 --- a/bundles/org.openhab.core.io.monitor/src/test/java/org/openhab/core/io/monitor/internal/metrics/ThingStateMetricTest.java +++ b/bundles/org.openhab.core.io.monitor/src/test/java/org/openhab/core/io/monitor/internal/metrics/ThingStateMetricTest.java @@ -69,7 +69,7 @@ public void testThingUidAlwaysUsedToCreateMeter() { List meters = meterRegistry.getMeters(); assertEquals(1, meters.size()); - assertEquals(strThingUid, meters.get(0).getId().getTag("thing")); + assertEquals(strThingUid, meters.getFirst().getId().getTag("thing")); // Still only one meter registered after receiving an event ThingStatusInfo thingStatusInfo = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null); @@ -77,7 +77,7 @@ public void testThingUidAlwaysUsedToCreateMeter() { meters = meterRegistry.getMeters(); assertEquals(1, meters.size()); - assertEquals(strThingUid, meters.get(0).getId().getTag("thing")); + assertEquals(strThingUid, meters.getFirst().getId().getTag("thing")); // Now another one is added thingStateMetric.receive(ThingEventFactory.createStatusInfoEvent(thingUid2, thingStatusInfo)); diff --git a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/HttpClientInitializationException.java b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/HttpClientInitializationException.java index adcc9b2c1b6..bd636864849 100644 --- a/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/HttpClientInitializationException.java +++ b/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/HttpClientInitializationException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.net.http; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -23,6 +25,7 @@ @NonNullByDefault public class HttpClientInitializationException extends RuntimeException { + @Serial private static final long serialVersionUID = -3187938868560212413L; public HttpClientInitializationException(String message, @Nullable Throwable cause) { diff --git a/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/JwtHelper.java b/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/JwtHelper.java index 6cb41acad28..2ada215ff09 100644 --- a/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/JwtHelper.java +++ b/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/JwtHelper.java @@ -17,7 +17,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -84,7 +84,7 @@ private RsaJsonWebKey generateNewKey() throws JoseException, IOException { } private RsaJsonWebKey loadOrGenerateKey() throws JoseException, IOException { - try (final BufferedReader reader = Files.newBufferedReader(Paths.get(KEY_FILE_PATH))) { + try (final BufferedReader reader = Files.newBufferedReader(Path.of(KEY_FILE_PATH))) { return (RsaJsonWebKey) JsonWebKey.Factory.newJwk(reader.readLine()); } catch (IOException | JoseException e) { RsaJsonWebKey key = generateNewKey(); diff --git a/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/TokenEndpointException.java b/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/TokenEndpointException.java index 34269906d4a..5a6a065539d 100644 --- a/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/TokenEndpointException.java +++ b/bundles/org.openhab.core.io.rest.auth/src/main/java/org/openhab/core/io/rest/auth/internal/TokenEndpointException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.rest.auth.internal; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.auth.AuthenticationException; @@ -26,6 +28,7 @@ */ @NonNullByDefault public class TokenEndpointException extends AuthenticationException { + @Serial private static final long serialVersionUID = 610324537843397832L; /** diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/link/ItemChannelLinkResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/link/ItemChannelLinkResource.java index 5d44b0d8d78..c6e4c45221e 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/link/ItemChannelLinkResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/link/ItemChannelLinkResource.java @@ -179,7 +179,7 @@ public Response getLink(@PathParam("itemName") @Parameter(description = "item na .toList(); if (!links.isEmpty()) { - return JSONResponse.createResponse(Status.OK, links.get(0), null); + return JSONResponse.createResponse(Status.OK, links.getFirst(), null); } return JSONResponse.createErrorResponse(Status.NOT_FOUND, "No link found for item '" + itemName + "' + and channelUID '" + channelUid + "'"); diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResource.java index af3b18bfef1..0476dad5df6 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/service/ConfigurableServiceResource.java @@ -174,7 +174,7 @@ public Response getById( + "=*))"; List services = getServicesByFilter(filter, locale); if (services.size() == 1) { - return services.get(0); + return services.getFirst(); } return null; } @@ -391,9 +391,9 @@ private String getServicePID(final String cn, final List pids) { case 0: return ""; case 1: - return pids.get(0); + return pids.getFirst(); default: // multiple entries - final String first = pids.get(0); + final String first = pids.getFirst(); boolean differences = false; for (int i = 1; i < pids.size(); ++i) { if (!first.equals(pids.get(i))) { diff --git a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionDTOMapperTest.java b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionDTOMapperTest.java index 2303fcac742..9b7c58881c2 100644 --- a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionDTOMapperTest.java +++ b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionDTOMapperTest.java @@ -49,7 +49,7 @@ public void testThatDefaultValuesAreEmptyIfMultipleIsTrue() { ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription); assertThat(cddto.parameters, hasSize(1)); - ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0); + ConfigDescriptionParameterDTO cdpdto = cddto.parameters.getFirst(); assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class)); assertThat(cdpdto.defaultValue, is(nullValue())); EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto; @@ -66,7 +66,7 @@ public void testThatDefaultValueIsNotAList() { ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription); assertThat(cddto.parameters, hasSize(1)); - ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0); + ConfigDescriptionParameterDTO cdpdto = cddto.parameters.getFirst(); assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class)); assertThat(cdpdto.defaultValue, is(CONFIG_PARAMETER_DEFAULT_VALUE)); EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto; @@ -84,7 +84,7 @@ public void testThatDefaultValuesAreAList() { ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription); assertThat(cddto.parameters, hasSize(1)); - ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0); + ConfigDescriptionParameterDTO cdpdto = cddto.parameters.getFirst(); assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class)); assertThat(cdpdto.defaultValue, is(CONFIG_PARAMETER_DEFAULT_VALUE)); EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto; diff --git a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResourceTest.java b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResourceTest.java index 5a9e1d04cfb..faa2d3404f9 100644 --- a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResourceTest.java +++ b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResourceTest.java @@ -127,7 +127,7 @@ public void testGetPersistenceItemData() { // since we added binary state type elements, all except the first have to be repeated but with the timestamp of // the following item - HistoryDataBean item0 = dto.data.get(0); + HistoryDataBean item0 = dto.data.getFirst(); HistoryDataBean item1 = dto.data.get(1); assertEquals(item0.state, item1.state); diff --git a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/thing/EnrichedThingDTOMapperTest.java b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/thing/EnrichedThingDTOMapperTest.java index b1b6ac80f43..cf119b5cef7 100644 --- a/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/thing/EnrichedThingDTOMapperTest.java +++ b/bundles/org.openhab.core.io.rest.core/src/test/java/org/openhab/core/io/rest/core/thing/EnrichedThingDTOMapperTest.java @@ -94,9 +94,9 @@ public void shouldMapEnrichedThingDTO() { private void assertChannels(EnrichedThingDTO enrichedThingDTO) { assertThat(enrichedThingDTO.channels, hasSize(2)); - assertThat(enrichedThingDTO.channels.get(0), is(instanceOf(EnrichedChannelDTO.class))); + assertThat(enrichedThingDTO.channels.getFirst(), is(instanceOf(EnrichedChannelDTO.class))); - EnrichedChannelDTO channel1 = enrichedThingDTO.channels.get(0); + EnrichedChannelDTO channel1 = enrichedThingDTO.channels.getFirst(); assertThat(channel1.linkedItems, hasSize(2)); } diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java index 04ae2d53aea..a3d221127f3 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/SitemapSubscriptionService.java @@ -299,9 +299,9 @@ public EList collectWidgets(String sitemapName, @Nullable String pageId) // subscribing to whole sitemap --> get items for all subpages as well LinkedList childrenQueue = new LinkedList<>(widgets); while (!childrenQueue.isEmpty()) { - Widget child = childrenQueue.remove(0); - if (child instanceof LinkableWidget) { - List subWidgets = itemUIRegistry.getChildren((LinkableWidget) child); + Widget child = childrenQueue.removeFirst(); + if (child instanceof LinkableWidget widget) { + List subWidgets = itemUIRegistry.getChildren(widget); widgets.addAll(subWidgets); childrenQueue.addAll(subWidgets); } diff --git a/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java b/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java index 5baa5bcd710..fe2b96e7def 100644 --- a/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java +++ b/bundles/org.openhab.core.io.rest.sitemap/src/test/java/org/openhab/core/io/rest/sitemap/internal/SitemapResourceTest.java @@ -358,18 +358,18 @@ public void whenGetPageDataShouldReturnPageBean() throws ItemNotFoundException { assertThat(pageDTO.widgets, notNullValue()); assertThat((Collection) pageDTO.widgets, hasSize(3)); - assertThat(pageDTO.widgets.get(0).widgetId, is(WIDGET1_ID)); - assertThat(pageDTO.widgets.get(0).label, is(WIDGET1_LABEL)); - assertThat(pageDTO.widgets.get(0).labelSource, is("SITEMAP_WIDGET")); - assertThat(pageDTO.widgets.get(0).labelcolor, is("GREEN")); - assertThat(pageDTO.widgets.get(0).valuecolor, is("BLUE")); - assertThat(pageDTO.widgets.get(0).iconcolor, is("ORANGE")); - assertThat(pageDTO.widgets.get(0).icon, is(WIDGET1_ICON)); - assertThat(pageDTO.widgets.get(0).staticIcon, is(true)); - assertThat(pageDTO.widgets.get(0).state, nullValue()); - assertThat(pageDTO.widgets.get(0).item, notNullValue()); - assertThat(pageDTO.widgets.get(0).item.name, is(ITEM_NAME)); - assertThat(pageDTO.widgets.get(0).item.state, is("50")); + assertThat(pageDTO.widgets.getFirst().widgetId, is(WIDGET1_ID)); + assertThat(pageDTO.widgets.getFirst().label, is(WIDGET1_LABEL)); + assertThat(pageDTO.widgets.getFirst().labelSource, is("SITEMAP_WIDGET")); + assertThat(pageDTO.widgets.getFirst().labelcolor, is("GREEN")); + assertThat(pageDTO.widgets.getFirst().valuecolor, is("BLUE")); + assertThat(pageDTO.widgets.getFirst().iconcolor, is("ORANGE")); + assertThat(pageDTO.widgets.getFirst().icon, is(WIDGET1_ICON)); + assertThat(pageDTO.widgets.getFirst().staticIcon, is(true)); + assertThat(pageDTO.widgets.getFirst().state, nullValue()); + assertThat(pageDTO.widgets.getFirst().item, notNullValue()); + assertThat(pageDTO.widgets.getFirst().item.name, is(ITEM_NAME)); + assertThat(pageDTO.widgets.getFirst().item.state, is("50")); assertThat(pageDTO.widgets.get(1).widgetId, is(WIDGET2_ID)); assertThat(pageDTO.widgets.get(1).label, is(ITEM_LABEL)); @@ -399,7 +399,7 @@ public void whenGetPageDataShouldReturnPageBean() throws ItemNotFoundException { private void configureItemUIRegistryWithSubpages(State state1, State state2, State state3) throws ItemNotFoundException { - Group group1 = (Group) widgets.get(0); + Group group1 = (Group) widgets.getFirst(); Group group2 = (Group) widgets.get(4); when(itemUIRegistryMock.getChildren(defaultSitemapMock)).thenReturn(new BasicEList<>(List.of(group1, group2))); @@ -441,7 +441,7 @@ private void configureCommonUIRegistryMockMethods() throws ItemNotFoundException private void configureWidgetStatesPage1(State state1, State state2) { EList mainpageWidgets = new BasicEList<>(widgets.subList(1, 4)); - Widget w1 = mainpageWidgets.get(0); + Widget w1 = mainpageWidgets.getFirst(); configureItemUIRegistryForWidget(w1, WIDGET1_ID, WIDGET1_ICON, WIDGET1_LABEL, WidgetLabelSource.SITEMAP_WIDGET, true, "GREEN", "BLUE", "ORANGE", state1); diff --git a/bundles/org.openhab.core.io.rest.sse/src/test/java/org/openhab/core/io/rest/sse/internal/util/SseUtilTest.java b/bundles/org.openhab.core.io.rest.sse/src/test/java/org/openhab/core/io/rest/sse/internal/util/SseUtilTest.java index c75baa49494..81da6ac56d6 100644 --- a/bundles/org.openhab.core.io.rest.sse/src/test/java/org/openhab/core/io/rest/sse/internal/util/SseUtilTest.java +++ b/bundles/org.openhab.core.io.rest.sse/src/test/java/org/openhab/core/io/rest/sse/internal/util/SseUtilTest.java @@ -62,9 +62,9 @@ public void testFilterMatchers() { List regexes = SseUtil .convertToRegex("openhab/*/test/test/test/test, openhab/test/*/test/test/test, openhab/*,qivicon/*"); - assertThat("openhab/test/test/test/test/test".matches(regexes.get(0)), is(true)); - assertThat("openhab/asdf/test/test/test/test".matches(regexes.get(0)), is(true)); - assertThat("openhab/asdf/ASDF/test/test/test".matches(regexes.get(0)), is(false)); + assertThat("openhab/test/test/test/test/test".matches(regexes.getFirst()), is(true)); + assertThat("openhab/asdf/test/test/test/test".matches(regexes.getFirst()), is(true)); + assertThat("openhab/asdf/ASDF/test/test/test".matches(regexes.getFirst()), is(false)); assertThat("openhab/test/test/test/test/test".matches(regexes.get(1)), is(true)); assertThat("openhab/asdf/test/test/test/test".matches(regexes.get(1)), is(false)); @@ -83,9 +83,9 @@ public void testFilterMatchers() { public void testMoreFilterMatchers() { List regexes = SseUtil.convertToRegex(", *, openhab/items/*/added, openhab/items/*/*"); - assertThat("openhab/test/test/test/test/test".matches(regexes.get(0)), is(true)); - assertThat("openhab/asdf/test/test/test/test".matches(regexes.get(0)), is(true)); - assertThat("openhab/asdf/ASDF/test/test/test".matches(regexes.get(0)), is(true)); + assertThat("openhab/test/test/test/test/test".matches(regexes.getFirst()), is(true)); + assertThat("openhab/asdf/test/test/test/test".matches(regexes.getFirst()), is(true)); + assertThat("openhab/asdf/ASDF/test/test/test".matches(regexes.getFirst()), is(true)); assertThat("openhab/test/test/test/test/test".matches(regexes.get(1)), is(false)); assertThat("openhab/items/anyitem/added".matches(regexes.get(1)), is(true)); @@ -101,20 +101,20 @@ public void testMoreFilterMatchers() { public void testEvenMoreFilterMatchers() { List regexes = SseUtil.convertToRegex(""); - assertThat("openhab/test/test/test/test/test".matches(regexes.get(0)), is(true)); - assertThat("openhab/asdf/test/test/test/test".matches(regexes.get(0)), is(true)); - assertThat("openhab/asdf/ASDF/test/test/test".matches(regexes.get(0)), is(true)); + assertThat("openhab/test/test/test/test/test".matches(regexes.getFirst()), is(true)); + assertThat("openhab/asdf/test/test/test/test".matches(regexes.getFirst()), is(true)); + assertThat("openhab/asdf/ASDF/test/test/test".matches(regexes.getFirst()), is(true)); regexes = SseUtil.convertToRegex("*/added"); - assertThat("openhab/items/anyitem/added".matches(regexes.get(0)), is(true)); - assertThat("openhab/items/anyitem/removed".matches(regexes.get(0)), is(false)); + assertThat("openhab/items/anyitem/added".matches(regexes.getFirst()), is(true)); + assertThat("openhab/items/anyitem/removed".matches(regexes.getFirst()), is(false)); regexes = SseUtil.convertToRegex("*added"); - assertThat("openhab/items/anyitem/added".matches(regexes.get(0)), is(true)); - assertThat("openhab/items/anyitem/removed".matches(regexes.get(0)), is(false)); + assertThat("openhab/items/anyitem/added".matches(regexes.getFirst()), is(true)); + assertThat("openhab/items/anyitem/removed".matches(regexes.getFirst()), is(false)); regexes = SseUtil.convertToRegex("openhab/items/*/state"); - assertThat("openhab/items/anyitem/state".matches(regexes.get(0)), is(true)); - assertThat("openhab/items/anyitem/statechanged".matches(regexes.get(0)), is(false)); + assertThat("openhab/items/anyitem/state".matches(regexes.getFirst()), is(true)); + assertThat("openhab/items/anyitem/statechanged".matches(regexes.getFirst()), is(false)); } } diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/LocaleServiceImpl.java b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/LocaleServiceImpl.java index b86442a01be..08e5b6a3800 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/LocaleServiceImpl.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/LocaleServiceImpl.java @@ -52,9 +52,9 @@ public Locale getLocale(@Nullable String acceptLanguageHttpHeader) { split = acceptLanguageHttpHeader.split("-"); } if (split.length == 2) { - locale = new Locale(split[0], split[1]); + locale = Locale.of(split[0], split[1]); } else { - locale = new Locale(split[0]); + locale = Locale.of(split[0]); } } return locale; diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/CorsFilter.java b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/CorsFilter.java index c5b31fd9ffd..2610c23f1b1 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/CorsFilter.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/CorsFilter.java @@ -157,7 +157,7 @@ private boolean processPreflight(ContainerRequestContext requestContext, Contain if (values == null || values.isEmpty()) { return null; } - return values.get(0); + return values.getFirst(); } /** diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java index a3245b9e1bc..e003fa00450 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/filter/ProxyFilter.java @@ -129,6 +129,6 @@ public void filter(@NonNullByDefault({}) ContainerRequestContext ctx) throws IOE return null; } - return values.get(0); + return values.getFirst(); } } diff --git a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/JSONResponseTest.java b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/JSONResponseTest.java index b41f179f32f..3861682aaaf 100644 --- a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/JSONResponseTest.java +++ b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/JSONResponseTest.java @@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -139,7 +140,7 @@ private static final class LargeEntity { private List getRandoms() { List randoms = new ArrayList<>(); for (int i = 0; i < 100000; i++) { - randoms.add(new BigDecimal(Math.random())); + randoms.add(new BigDecimal(ThreadLocalRandom.current().nextDouble())); } return randoms; diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusConnectionException.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusConnectionException.java index a89031ad945..0c0d08052e1 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusConnectionException.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusConnectionException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.modbus.exception; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.io.transport.modbus.endpoint.ModbusSlaveEndpoint; @@ -25,6 +27,7 @@ @NonNullByDefault public class ModbusConnectionException extends ModbusTransportException { + @Serial private static final long serialVersionUID = -6171226761518661925L; private ModbusSlaveEndpoint endpoint; diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusSlaveErrorResponseException.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusSlaveErrorResponseException.java index b7c3b5eefa9..1b952476452 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusSlaveErrorResponseException.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusSlaveErrorResponseException.java @@ -12,6 +12,7 @@ */ package org.openhab.core.io.transport.modbus.exception; +import java.io.Serial; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -153,6 +154,7 @@ public static Optional tryFromExceptionCode(int exceptionCod public static final int GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = KnownExceptionCode.GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND .getExceptionCode(); + @Serial private static final long serialVersionUID = -1435199498550990487L; /** diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusSlaveIOException.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusSlaveIOException.java index 2ef2511f683..958ed366714 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusSlaveIOException.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusSlaveIOException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.modbus.exception; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -23,5 +25,6 @@ @NonNullByDefault public class ModbusSlaveIOException extends ModbusTransportException { + @Serial private static final long serialVersionUID = -8568199166837844463L; } diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusTransportException.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusTransportException.java index 9c83ea56b79..dd214b39951 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusTransportException.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusTransportException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.modbus.exception; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -23,5 +25,6 @@ @NonNullByDefault public class ModbusTransportException extends Exception { + @Serial private static final long serialVersionUID = 1684767401685843339L; } diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedResponseFunctionCodeException.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedResponseFunctionCodeException.java index 3e9870bba59..1e35df1e80d 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedResponseFunctionCodeException.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedResponseFunctionCodeException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.modbus.exception; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -24,6 +26,7 @@ @NonNullByDefault public class ModbusUnexpectedResponseFunctionCodeException extends ModbusTransportException { + @Serial private static final long serialVersionUID = 1109165449703638949L; private int requestFunctionCode; private int responseFunctionCode; diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedResponseSizeException.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedResponseSizeException.java index 6a558e901ed..47e7068ce51 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedResponseSizeException.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedResponseSizeException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.modbus.exception; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -24,6 +26,7 @@ @NonNullByDefault public class ModbusUnexpectedResponseSizeException extends ModbusTransportException { + @Serial private static final long serialVersionUID = 2460907938819984483L; private int requestSize; private int responseSize; diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedTransactionIdException.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedTransactionIdException.java index 78b74461f2a..893dce6d93a 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedTransactionIdException.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/exception/ModbusUnexpectedTransactionIdException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.modbus.exception; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -24,6 +26,7 @@ @NonNullByDefault public class ModbusUnexpectedTransactionIdException extends ModbusTransportException { + @Serial private static final long serialVersionUID = -2453232634024813933L; private int requestId; private int responseId; diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusSlaveErrorResponseExceptionImpl.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusSlaveErrorResponseExceptionImpl.java index a991a03f0b3..e2109150b7e 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusSlaveErrorResponseExceptionImpl.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusSlaveErrorResponseExceptionImpl.java @@ -12,6 +12,7 @@ */ package org.openhab.core.io.transport.modbus.internal; +import java.io.Serial; import java.util.Optional; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -30,6 +31,7 @@ @NonNullByDefault public class ModbusSlaveErrorResponseExceptionImpl extends ModbusSlaveErrorResponseException { + @Serial private static final long serialVersionUID = 6334580162425192133L; private int rawCode; private Optional exceptionCode; diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusSlaveIOExceptionImpl.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusSlaveIOExceptionImpl.java index 27af9fef964..7b51f804659 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusSlaveIOExceptionImpl.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusSlaveIOExceptionImpl.java @@ -13,6 +13,7 @@ package org.openhab.core.io.transport.modbus.internal; import java.io.IOException; +import java.io.Serial; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -29,6 +30,7 @@ @NonNullByDefault public class ModbusSlaveIOExceptionImpl extends ModbusSlaveIOException { + @Serial private static final long serialVersionUID = -8910463902857643468L; private Exception error; diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/SmokeTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/SmokeTest.java index c2e10199760..88e04d950c5 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/SmokeTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/SmokeTest.java @@ -440,7 +440,7 @@ public void testOneOffWriteMultipleCoil() throws Exception { assertThat(response.getFunctionCode(), is(equalTo(15))); assertThat(modbustRequestCaptor.getAllReturnValues().size(), is(equalTo(1))); - ModbusRequest request = modbustRequestCaptor.getAllReturnValues().get(0); + ModbusRequest request = modbustRequestCaptor.getAllReturnValues().getFirst(); assertThat(request.getFunctionCode(), is(equalTo(15))); assertThat(((WriteMultipleCoilsRequest) request).getReference(), is(equalTo(3))); assertThat(((WriteMultipleCoilsRequest) request).getBitCount(), is(equalTo(bits.size()))); @@ -481,7 +481,7 @@ public void testOneOffWriteMultipleCoilError() throws Exception { assertInstanceOf(ModbusSlaveErrorResponseException.class, lastError.get(), lastError.toString()); assertThat(modbustRequestCaptor.getAllReturnValues().size(), is(equalTo(1))); - ModbusRequest request = modbustRequestCaptor.getAllReturnValues().get(0); + ModbusRequest request = modbustRequestCaptor.getAllReturnValues().getFirst(); assertThat(request.getFunctionCode(), is(equalTo(15))); assertThat(((WriteMultipleCoilsRequest) request).getReference(), is(equalTo(3))); assertThat(((WriteMultipleCoilsRequest) request).getBitCount(), is(equalTo(bits.size()))); @@ -520,7 +520,7 @@ public void testOneOffWriteSingleCoil() throws Exception { assertThat(response.getFunctionCode(), is(equalTo(5))); assertThat(modbustRequestCaptor.getAllReturnValues().size(), is(equalTo(1))); - ModbusRequest request = modbustRequestCaptor.getAllReturnValues().get(0); + ModbusRequest request = modbustRequestCaptor.getAllReturnValues().getFirst(); assertThat(request.getFunctionCode(), is(equalTo(5))); assertThat(((WriteCoilRequest) request).getReference(), is(equalTo(3))); assertThat(((WriteCoilRequest) request).getCoil(), is(equalTo(true))); @@ -558,7 +558,7 @@ public void testOneOffWriteSingleCoilError() throws Exception { assertInstanceOf(ModbusSlaveErrorResponseException.class, lastError.get(), lastError.toString()); assertThat(modbustRequestCaptor.getAllReturnValues().size(), is(equalTo(1))); - ModbusRequest request = modbustRequestCaptor.getAllReturnValues().get(0); + ModbusRequest request = modbustRequestCaptor.getAllReturnValues().getFirst(); assertThat(request.getFunctionCode(), is(equalTo(5))); assertThat(((WriteCoilRequest) request).getReference(), is(equalTo(300))); assertThat(((WriteCoilRequest) request).getCoil(), is(equalTo(true))); diff --git a/bundles/org.openhab.core.io.transport.mqtt/src/main/java/org/openhab/core/io/transport/mqtt/MqttException.java b/bundles/org.openhab.core.io.transport.mqtt/src/main/java/org/openhab/core/io/transport/mqtt/MqttException.java index 47d4c14ed18..b9d75f36e3a 100644 --- a/bundles/org.openhab.core.io.transport.mqtt/src/main/java/org/openhab/core/io/transport/mqtt/MqttException.java +++ b/bundles/org.openhab.core.io.transport.mqtt/src/main/java/org/openhab/core/io/transport/mqtt/MqttException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.mqtt; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -23,6 +25,7 @@ */ @NonNullByDefault public class MqttException extends Exception { + @Serial private static final long serialVersionUID = 301L; private Throwable cause; diff --git a/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/PortInUseException.java b/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/PortInUseException.java index e5e19dae7fe..405a3a55b92 100644 --- a/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/PortInUseException.java +++ b/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/PortInUseException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.serial; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,6 +24,7 @@ @NonNullByDefault public class PortInUseException extends Exception { + @Serial private static final long serialVersionUID = -2709480420743139383L; public PortInUseException(String message, Exception cause) { diff --git a/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/UnsupportedCommOperationException.java b/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/UnsupportedCommOperationException.java index ac05e276e23..3d72fe2e77e 100644 --- a/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/UnsupportedCommOperationException.java +++ b/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/UnsupportedCommOperationException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.transport.serial; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,6 +24,7 @@ @NonNullByDefault public class UnsupportedCommOperationException extends Exception { + @Serial private static final long serialVersionUID = 1L; public UnsupportedCommOperationException() { diff --git a/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/CommonWebSocketServlet.java b/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/CommonWebSocketServlet.java index 0a6984a4455..939109b04aa 100644 --- a/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/CommonWebSocketServlet.java +++ b/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/CommonWebSocketServlet.java @@ -13,6 +13,7 @@ package org.openhab.core.io.websocket; import java.io.IOException; +import java.io.Serial; import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -65,6 +66,7 @@ @HttpWhiteboardServletPattern(CommonWebSocketServlet.SERVLET_PATH + "/*") @Component(immediate = true, service = { Servlet.class }) public class CommonWebSocketServlet extends WebSocketServlet { + @Serial private static final long serialVersionUID = 1L; public static final String SEC_WEBSOCKET_PROTOCOL_HEADER = "Sec-WebSocket-Protocol"; diff --git a/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/event/EventProcessingException.java b/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/event/EventProcessingException.java index d3f8c82dc2b..1a85fe9033a 100644 --- a/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/event/EventProcessingException.java +++ b/bundles/org.openhab.core.io.websocket/src/main/java/org/openhab/core/io/websocket/event/EventProcessingException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.websocket.event; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -21,6 +23,7 @@ */ @NonNullByDefault public class EventProcessingException extends Exception { + @Serial private static final long serialVersionUID = 1L; public EventProcessingException(String message) { diff --git a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/FeatureInstaller.java b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/FeatureInstaller.java index fdb8cce793c..ad97ef2aea3 100644 --- a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/FeatureInstaller.java +++ b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/FeatureInstaller.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -283,7 +282,7 @@ private void changeAddonConfig(String type, String id, BiFunction Diagnostician.INSTANCE.validate(resource.getContents().get(0))); + .call(() -> Diagnostician.INSTANCE.validate(resource.getContents().getFirst())); for (org.eclipse.emf.common.util.Diagnostic d : diagnostic.getChildren()) { warnings.add(d.getMessage()); } diff --git a/bundles/org.openhab.core.model.core/src/test/java/org/openhab/core/model/core/internal/folder/FolderObserverTest.java b/bundles/org.openhab.core.model.core/src/test/java/org/openhab/core/model/core/internal/folder/FolderObserverTest.java index 65ed1667eac..359b0987453 100644 --- a/bundles/org.openhab.core.model.core/src/test/java/org/openhab/core/model/core/internal/folder/FolderObserverTest.java +++ b/bundles/org.openhab.core.model.core/src/test/java/org/openhab/core/model/core/internal/folder/FolderObserverTest.java @@ -29,7 +29,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Comparator; import java.util.Dictionary; @@ -253,7 +252,7 @@ public void testCreationNoExtensions() throws Exception { configProps.put(subdir, ""); folderObserver.activate(contextMock); - File file = new File(WATCHED_DIRECTORY, Paths.get(subdir, "MockFileInNoExtSubDir.txt").toString()); + File file = new File(WATCHED_DIRECTORY, Path.of(subdir, "MockFileInNoExtSubDir.txt").toString()); Files.writeString(file.toPath(), INITIAL_FILE_CONTENT, StandardCharsets.UTF_8, StandardOpenOption.CREATE); waitForAssert(() -> assertThat(file.exists(), is(true))); diff --git a/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/BindingConfigParseException.java b/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/BindingConfigParseException.java index 4ddc1b739c3..5b368f598d9 100644 --- a/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/BindingConfigParseException.java +++ b/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/BindingConfigParseException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.model.item; +import java.io.Serial; + /** * This exception is used by {@link BindingConfigReader} instances if parsing configurations fails * @@ -19,6 +21,7 @@ */ public class BindingConfigParseException extends Exception { + @Serial private static final long serialVersionUID = 1434607160082879845L; public BindingConfigParseException(String msg) { diff --git a/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java b/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java index b30c816c421..ed04f5d2253 100644 --- a/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java +++ b/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java @@ -354,7 +354,7 @@ private void internalDispatchBindings(@Nullable BindingConfigReader reader, Stri // Single valued lists get unwrapped to just their one value for // backwards compatibility if (value instanceof List listValue && listValue.size() == 1) { - value = listValue.get(0); + value = listValue.getFirst(); } configuration.put(p.getKey(), value); }); diff --git a/bundles/org.openhab.core.model.lsp/src/main/java/org/openhab/core/model/lsp/internal/MappingUriExtensions.java b/bundles/org.openhab.core.model.lsp/src/main/java/org/openhab/core/model/lsp/internal/MappingUriExtensions.java index a9a31df1023..17fce07058e 100644 --- a/bundles/org.openhab.core.model.lsp/src/main/java/org/openhab/core/model/lsp/internal/MappingUriExtensions.java +++ b/bundles/org.openhab.core.model.lsp/src/main/java/org/openhab/core/model/lsp/internal/MappingUriExtensions.java @@ -16,7 +16,6 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import org.eclipse.emf.common.util.URI; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -50,7 +49,7 @@ public MappingUriExtensions(String configFolder) { } protected String calcServerLocation(String configFolder) { - Path configPath = Paths.get(configFolder); + Path configPath = Path.of(configFolder); Path absoluteConfigPath = configPath.toAbsolutePath(); java.net.URI configPathURI = absoluteConfigPath.toUri(); return removeTrailingSlash(configPathURI.toString()); @@ -184,6 +183,6 @@ private String toPathAsInXtext212(java.net.URI uri) { // output new: file:///d/ // We use this method now to keep the old behavior. - return Paths.get(uri).toUri().toString(); + return Path.of(uri).toUri().toString(); } } diff --git a/bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/scoping/RulesClassCache.java b/bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/scoping/RulesClassCache.java index f7bd98c76ab..265b22aeeb5 100644 --- a/bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/scoping/RulesClassCache.java +++ b/bundles/org.openhab.core.model.rule/src/org/openhab/core/model/rule/scoping/RulesClassCache.java @@ -12,6 +12,7 @@ */ package org.openhab.core.model.rule.scoping; +import java.io.Serial; import java.util.HashMap; import org.eclipse.xtext.common.types.access.impl.Primitives; @@ -36,6 +37,7 @@ @Component public class RulesClassCache extends HashMap> { + @Serial private static final long serialVersionUID = 1L; private static RulesClassCache instance; diff --git a/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/ScriptEngineImpl.java b/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/ScriptEngineImpl.java index 9caeaa80b45..4f50f23239e 100644 --- a/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/ScriptEngineImpl.java +++ b/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/ScriptEngineImpl.java @@ -16,6 +16,7 @@ import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; @@ -143,9 +144,9 @@ private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws Sc EList contents = resource.getContents(); if (!contents.isEmpty()) { - Iterable validationErrors = getValidationErrors(contents.get(0)); + Iterable validationErrors = getValidationErrors(contents.getFirst()); if (!validationErrors.iterator().hasNext()) { - return (XExpression) contents.get(0); + return (XExpression) contents.getFirst(); } else { deleteResource(resource); throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)", @@ -162,7 +163,8 @@ protected URI computeUnusedUri(ResourceSet resourceSet) { final int MAX_TRIES = 1000; for (int i = 0; i < MAX_TRIES; i++) { // NOTE: The "filename extension" (".script") must match the file.extensions in the *.mwe2 - URI syntheticUri = URI.createURI(name + Math.random() + "." + Script.SCRIPT_FILEEXT); + URI syntheticUri = URI + .createURI(name + ThreadLocalRandom.current().nextDouble() + "." + Script.SCRIPT_FILEEXT); if (resourceSet.getResource(syntheticUri, false) == null) { return syntheticUri; } diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/TransformationException.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/TransformationException.java index 7b750755fb0..9d2ada949cf 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/TransformationException.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/TransformationException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.model.script.actions; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -24,6 +26,7 @@ @NonNullByDefault public class TransformationException extends Exception { + @Serial private static final long serialVersionUID = -1L; public TransformationException(@Nullable String message) { diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Voice.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Voice.java index 32b93831017..57a99de34c1 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Voice.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Voice.java @@ -325,9 +325,9 @@ public static void startDialog(@ParamDoc(name = "keyword spotting service") @Nul String[] split = locale.split("-"); Locale loc; if (split.length == 2) { - loc = new Locale(split[0], split[1]); + loc = Locale.of(split[0], split[1]); } else { - loc = new Locale(split[0]); + loc = Locale.of(split[0]); } dialogContextBuilder.withLocale(loc); } @@ -453,9 +453,9 @@ public static void listenAndAnswer(@ParamDoc(name = "speech-to-text service") @N Locale loc; String[] split = locale.split("-"); if (split.length == 2) { - loc = new Locale(split[0], split[1]); + loc = Locale.of(split[0], split[1]); } else { - loc = new Locale(split[0]); + loc = Locale.of(split[0]); } dialogContextBuilder.withLocale(loc); } diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptException.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptException.java index 7ec53e3aa65..abb6c352fdd 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptException.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptException.java @@ -12,6 +12,7 @@ */ package org.openhab.core.model.script.engine; +import java.io.Serial; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -22,6 +23,7 @@ * @author Kai Kreuzer - Initial contribution */ public abstract class ScriptException extends Exception { + @Serial private static final long serialVersionUID = -4155948282895039148L; private String scriptText; diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptExecutionException.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptExecutionException.java index 556015512b1..7d868a63726 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptExecutionException.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptExecutionException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.model.script.engine; +import java.io.Serial; + /** * Exception that is thrown on errors during script execution. * @@ -19,6 +21,7 @@ */ public class ScriptExecutionException extends ScriptException { + @Serial private static final long serialVersionUID = 149490362444673405L; public ScriptExecutionException(final String message, final int line, final int column, final int length) { diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptParsingException.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptParsingException.java index c1861d9b345..39d4f7abc20 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptParsingException.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/engine/ScriptParsingException.java @@ -12,6 +12,7 @@ */ package org.openhab.core.model.script.engine; +import java.io.Serial; import java.util.List; import org.eclipse.emf.ecore.resource.Resource.Diagnostic; @@ -26,6 +27,7 @@ */ public class ScriptParsingException extends ScriptException { + @Serial private static final long serialVersionUID = -3784970293118871807L; public ScriptParsingException(String message, String scriptAsString) { diff --git a/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/serializer/ThingSyntacticSequencerExtension.java b/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/serializer/ThingSyntacticSequencerExtension.java index 9ef1f8b1e3d..bc598673986 100644 --- a/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/serializer/ThingSyntacticSequencerExtension.java +++ b/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/serializer/ThingSyntacticSequencerExtension.java @@ -30,8 +30,8 @@ public class ThingSyntacticSequencerExtension extends ThingSyntacticSequencer { @Override protected void emit_ModelThing_ThingKeyword_0_q(EObject semanticObject, ISynNavigable transition, List nodes) { - ILeafNode node = nodes != null && nodes.size() == 1 && nodes.get(0) instanceof ILeafNode - ? (ILeafNode) nodes.get(0) + ILeafNode node = nodes != null && nodes.size() == 1 && nodes.getFirst() instanceof ILeafNode + ? (ILeafNode) nodes.getFirst() : null; Keyword keyword = grammarAccess.getModelThingAccess().getThingKeyword_0(); acceptUnassignedKeyword(keyword, keyword.getValue(), node); diff --git a/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java b/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java index 4b60544bbec..3c7b27467b8 100644 --- a/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java +++ b/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java @@ -157,7 +157,7 @@ public void testFileUpdated() throws IOException { assertThat(arguments, hasSize(4)); // added originally - assertThat(arguments.get(0), containsInAnyOrder(new FirstTypeDTO("First", "First original"), + assertThat(arguments.getFirst(), containsInAnyOrder(new FirstTypeDTO("First", "First original"), new FirstTypeDTO("Second", "Second original"), new FirstTypeDTO("Third", "Third original"))); // added by update assertThat(arguments.get(1), contains(new FirstTypeDTO("Fourth", "Fourth original"))); @@ -185,10 +185,10 @@ public void testFileRemoved() throws IOException { assertThat(arguments, hasSize(2)); // all are added - assertThat(arguments.get(0), containsInAnyOrder(new FirstTypeDTO("First", "First original"), + assertThat(arguments.getFirst(), containsInAnyOrder(new FirstTypeDTO("First", "First original"), new FirstTypeDTO("Second", "Second original"), new FirstTypeDTO("Third", "Third original"))); // all are removed - assertThat(arguments.get(0), containsInAnyOrder(new FirstTypeDTO("First", "First original"), + assertThat(arguments.getFirst(), containsInAnyOrder(new FirstTypeDTO("First", "First original"), new FirstTypeDTO("Second", "Second original"), new FirstTypeDTO("Third", "Third original"))); } diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java index cb3d1f8cad0..c86a28dddbe 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java @@ -2681,20 +2681,19 @@ private static void internalRemoveAllStatesBetween(Item item, @Nullable ZonedDat } // add HistoricItem at begin - if (betweenItemsList.isEmpty() || !betweenItemsList.get(0).getTimestamp().equals(begin)) { + if (betweenItemsList.isEmpty() || !betweenItemsList.getFirst().getTimestamp().equals(begin)) { HistoricItem first = beginTime.equals(now) ? historicItemOrCurrentState(item, null) : internalPersistedState(item, beginTime, serviceId); if (first != null) { first = new RetimedHistoricItem(first, beginTime); } if (first != null) { - betweenItemsList.add(0, first); + betweenItemsList.addFirst(first); } } // add HistoricItem at end - if (betweenItemsList.isEmpty() - || !betweenItemsList.get(betweenItemsList.size() - 1).getTimestamp().equals(end)) { + if (betweenItemsList.isEmpty() || !betweenItemsList.getLast().getTimestamp().equals(end)) { HistoricItem last = endTime.equals(now) ? historicItemOrCurrentState(item, null) : internalPersistedState(item, endTime, serviceId); if (last != null) { diff --git a/bundles/org.openhab.core.persistence/src/test/java/org/openhab/core/persistence/internal/PersistenceManagerTest.java b/bundles/org.openhab.core.persistence/src/test/java/org/openhab/core/persistence/internal/PersistenceManagerTest.java index f2b0cb23238..7b1ba4b9c64 100644 --- a/bundles/org.openhab.core.persistence/src/test/java/org/openhab/core/persistence/internal/PersistenceManagerTest.java +++ b/bundles/org.openhab.core.persistence/src/test/java/org/openhab/core/persistence/internal/PersistenceManagerTest.java @@ -415,7 +415,7 @@ public void storeTimeSeriesAndForecastsScheduled() { assertThat(filterCriteria.getEndDate(), is(time4.atZone(ZoneId.systemDefault()))); // verify restore future is not cancelled - verify(futures.get(0), never()).cancel(anyBoolean()); + verify(futures.getFirst(), never()).cancel(anyBoolean()); // verify new values are stored inOrder.verify(service, times(2)).store(any(Item.class), any(ZonedDateTime.class), any(State.class)); @@ -430,7 +430,7 @@ public void storeTimeSeriesAndForecastsScheduled() { manager.timeSeriesUpdated(TEST_ITEM, timeSeries3); // verify old restore future is cancelled inOrder.verify(service, times(1)).store(any(Item.class), any(ZonedDateTime.class), any(State.class)); - verify(futures.get(0)).cancel(true); + verify(futures.getFirst()).cancel(true); // verify new restore future is properly created inOrder.verify(schedulerMock).at(any(SchedulerRunnable.class), eq(time5)); @@ -452,8 +452,8 @@ public void cronStrategyIsScheduledAndCancelledAndPersistsValue() throws Excepti verify(readyServiceMock, timeout(1000)).markReady(any()); List runnables = runnableCaptor.getAllValues(); assertThat(runnables.size(), is(2)); - runnables.get(0).run(); - runnables.get(0).run(); + runnables.getFirst().run(); + runnables.getFirst().run(); runnables.get(1).run(); runnables.get(1).run(); diff --git a/bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticsMetadataProvider.java b/bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticsMetadataProvider.java index 9a2cd4b0183..35a185b9012 100644 --- a/bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticsMetadataProvider.java +++ b/bundles/org.openhab.core.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticsMetadataProvider.java @@ -164,7 +164,7 @@ private void processProperties(Item item, Map configuration) { return; } for (Entry>, String> relation : propertyRelations.entrySet()) { - Class entityClass = relation.getKey().get(0); + Class entityClass = relation.getKey().getFirst(); if (entityClass.isAssignableFrom(type)) { Class p = SemanticTags.getProperty(item); if (p != null) { @@ -211,7 +211,7 @@ private void processParent(Class type, Item parentItem, Map>, String> relation : parentRelations.entrySet()) { List> relClasses = relation.getKey(); - Class entityClass = relClasses.get(0); + Class entityClass = relClasses.getFirst(); Class parentClass = relClasses.get(1); // process relations of locations if (entityClass.isAssignableFrom(type)) { @@ -236,7 +236,7 @@ private void processMember(Class type, Item memberItem, Map>, String> relation : memberRelations.entrySet()) { List> relClasses = relation.getKey(); - Class entityClass = relClasses.get(0); + Class entityClass = relClasses.getFirst(); Class parentClass = relClasses.get(1); // process relations of locations if (entityClass.isAssignableFrom(type)) { diff --git a/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/internal/SemanticsServiceImplTest.java b/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/internal/SemanticsServiceImplTest.java index e2ed70e3234..6e6604e8e66 100644 --- a/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/internal/SemanticsServiceImplTest.java +++ b/bundles/org.openhab.core.semantics/src/test/java/org/openhab/core/semantics/internal/SemanticsServiceImplTest.java @@ -160,7 +160,7 @@ public void testGetItemsInLocationByString() throws Exception { public void testGetLabelAndSynonyms() { List result = service.getLabelAndSynonyms(bathroomTagClass, Locale.ENGLISH); assertEquals(6, result.size()); - assertEquals("bathroom", result.get(0)); + assertEquals("bathroom", result.getFirst()); assertEquals("bathrooms", result.get(1)); assertEquals("bath", result.get(2)); assertEquals("baths", result.get(3)); @@ -169,14 +169,14 @@ public void testGetLabelAndSynonyms() { result = service.getLabelAndSynonyms(cleaningRobotTagClass, Locale.FRENCH); assertEquals(4, result.size()); - assertEquals("robot de nettoyage", result.get(0)); + assertEquals("robot de nettoyage", result.getFirst()); assertEquals("robos de nettoyage", result.get(1)); assertEquals("robot aspirateur", result.get(2)); assertEquals("robots aspirateur", result.get(3)); result = service.getLabelAndSynonyms(userLocationTagClass, Locale.ENGLISH); assertEquals(4, result.size()); - assertEquals("custom label", result.get(0)); + assertEquals("custom label", result.getFirst()); assertEquals("synonym1", result.get(1)); assertEquals("synonym2", result.get(2)); assertEquals("synonym with space", result.get(3)); @@ -204,28 +204,28 @@ public void testGetByLabel() { public void testGetByLabelOrSynonym() { List> tags = service.getByLabelOrSynonym("BATHROOM", Locale.ENGLISH); assertEquals(1, tags.size()); - assertEquals(bathroomTagClass, tags.get(0)); + assertEquals(bathroomTagClass, tags.getFirst()); tags = service.getByLabelOrSynonym("POWDER Rooms", Locale.ENGLISH); assertEquals(1, tags.size()); - assertEquals(bathroomTagClass, tags.get(0)); + assertEquals(bathroomTagClass, tags.getFirst()); tags = service.getByLabelOrSynonym("other bath", Locale.ENGLISH); assertTrue(tags.isEmpty()); tags = service.getByLabelOrSynonym("ROBOT de nettoyage", Locale.FRENCH); assertEquals(1, tags.size()); - assertEquals(cleaningRobotTagClass, tags.get(0)); + assertEquals(cleaningRobotTagClass, tags.getFirst()); tags = service.getByLabelOrSynonym("ROBOTS aspirateur", Locale.FRENCH); assertEquals(1, tags.size()); - assertEquals(cleaningRobotTagClass, tags.get(0)); + assertEquals(cleaningRobotTagClass, tags.getFirst()); tags = service.getByLabelOrSynonym("Robot cuiseur", Locale.FRENCH); assertTrue(tags.isEmpty()); tags = service.getByLabelOrSynonym("CUSTOM label", Locale.ENGLISH); assertEquals(1, tags.size()); - assertEquals(userLocationTagClass, tags.get(0)); + assertEquals(userLocationTagClass, tags.getFirst()); tags = service.getByLabelOrSynonym("Synonym with space", Locale.ENGLISH); assertEquals(1, tags.size()); - assertEquals(userLocationTagClass, tags.get(0)); + assertEquals(userLocationTagClass, tags.getFirst()); tags = service.getByLabelOrSynonym("wrong label", Locale.ENGLISH); assertTrue(tags.isEmpty()); } diff --git a/bundles/org.openhab.core.storage.json/src/main/java/org/openhab/core/storage/json/internal/migration/TypeMigrationException.java b/bundles/org.openhab.core.storage.json/src/main/java/org/openhab/core/storage/json/internal/migration/TypeMigrationException.java index d845682bd1a..794ea15aafc 100644 --- a/bundles/org.openhab.core.storage.json/src/main/java/org/openhab/core/storage/json/internal/migration/TypeMigrationException.java +++ b/bundles/org.openhab.core.storage.json/src/main/java/org/openhab/core/storage/json/internal/migration/TypeMigrationException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.storage.json.internal.migration; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -21,6 +23,7 @@ */ @NonNullByDefault public class TypeMigrationException extends Exception { + @Serial private static final long serialVersionUID = 1L; public TypeMigrationException(String message) { diff --git a/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java b/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java index b1635564f59..84c2f384403 100644 --- a/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java +++ b/bundles/org.openhab.core.storage.json/src/test/java/org/openhab/core/storage/json/internal/JsonStorageTest.java @@ -132,10 +132,10 @@ public void testIntegerScaleFromDisk() { assertEquals(0, ((BigDecimal) dummy.configuration.get("testInt")).scale()); assertEquals(0, ((BigDecimal) dummy.configuration.get("testLong")).scale()); assertEquals(0, ((BigDecimal) dummy.configuration.get("testBigDecimal")).scale()); - assertEquals(0, ((List) dummy.configuration.get("multiInt")).get(0).scale()); + assertEquals(0, ((List) dummy.configuration.get("multiInt")).getFirst().scale()); assertEquals(0, ((List) dummy.configuration.get("multiInt")).get(1).scale()); assertEquals(0, ((List) dummy.configuration.get("multiInt")).get(2).scale()); - assertEquals(0, ((BigDecimal) dummy.channels.get(0).configuration.get("testChildLong")).scale()); + assertEquals(0, ((BigDecimal) dummy.channels.getFirst().configuration.get("testChildLong")).scale()); } @Test diff --git a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicChattyThingHandler.java b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicChattyThingHandler.java index 4c463cb4f20..7728dabdfde 100644 --- a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicChattyThingHandler.java +++ b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicChattyThingHandler.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -90,7 +91,7 @@ public MagicChattyThingHandler(Thing thing) { @Override public void run() { for (ChannelUID channelUID : numberChannelUIDs) { - double randomValue = Math.random() * 100; + double randomValue = ThreadLocalRandom.current().nextDouble() * 100; int intValue = (int) randomValue; State cmd; if (intValue % 2 == 0) { @@ -102,7 +103,7 @@ public void run() { } for (ChannelUID channelUID : textChannelUIDs) { - int pos = (int) (Math.random() * (RANDOM_TEXTS.size() - 1)); + int pos = (int) (ThreadLocalRandom.current().nextDouble() * (RANDOM_TEXTS.size() - 1)); String randomValue = RANDOM_TEXTS.get(pos); StringType cmd = new StringType(randomValue); diff --git a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicTimeSeriesHandler.java b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicTimeSeriesHandler.java index ef9adcfabc2..4fc86c5d02b 100644 --- a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicTimeSeriesHandler.java +++ b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicTimeSeriesHandler.java @@ -18,6 +18,7 @@ import java.time.Duration; import java.time.Instant; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -73,7 +74,7 @@ private void startScheduledJob() { double range = configuration.max - configuration.min; for (int i = 1; i <= configuration.count; i++) { double value = switch (configuration.type) { - case RND -> Math.random() * range + configuration.min; + case RND -> ThreadLocalRandom.current().nextDouble() * range + configuration.min; case ASC -> (range / configuration.count) * i + configuration.min; case DESC -> configuration.max + (range / configuration.count) * i; }; diff --git a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaOSGiTest.java b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaOSGiTest.java index de44ea76117..efe97a16e93 100644 --- a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaOSGiTest.java +++ b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaOSGiTest.java @@ -154,7 +154,7 @@ protected List getServices(Class clazz, Predicate> new MissingServiceAnalyzer(System.out, bundleContext).printMissingServiceDetails(clazz); return null; } else { - return filteredServices.get(0); + return filteredServices.getFirst(); } } @@ -317,7 +317,7 @@ protected ServiceRegistration registerService(final Object service, final Str ServiceRegistration reg = null; List> regList = registeredServices.remove(interfaceName); if (regList != null) { - reg = regList.get(0); + reg = regList.getFirst(); regList.forEach(r -> r.unregister()); } return reg; diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ChannelGroupUID.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ChannelGroupUID.java index 4b09c0ac299..54ec2c25399 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ChannelGroupUID.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ChannelGroupUID.java @@ -64,7 +64,7 @@ private static List toSegments(ThingUID thingUID, String id) { */ public String getId() { List segments = getAllSegments(); - return segments.get(segments.size() - 1); + return segments.getLast(); } @Override diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ChannelUID.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ChannelUID.java index 4cd70a09a6a..3abb87b4ca9 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ChannelUID.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ChannelUID.java @@ -94,7 +94,7 @@ private static String getChannelId(@Nullable String groupId, String id) { */ public String getId() { List segments = getAllSegments(); - return segments.get(segments.size() - 1); + return segments.getLast(); } /** diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ThingUID.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ThingUID.java index 0f3f50b50c0..5107a4fe11f 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ThingUID.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ThingUID.java @@ -156,7 +156,7 @@ public List getBridgeIds() { */ public String getId() { List segments = getAllSegments(); - return segments.get(segments.size() - 1); + return segments.getLast(); } @Override diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ThingManagerImpl.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ThingManagerImpl.java index c8fca413d9b..8eefda23e00 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ThingManagerImpl.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/ThingManagerImpl.java @@ -1093,7 +1093,7 @@ private boolean checkAndPerformUpdate(Thing thing, ThingHandlerFactory factory) ThingBuilder thingBuilder = thing instanceof Bridge bridge ? BridgeBuilder.create(bridge) : ThingBuilder.create(thing); instructions.forEach(instruction -> instruction.perform(thing, thingBuilder)); - int newThingTypeVersion = instructions.get(instructions.size() - 1).getThingTypeVersion(); + int newThingTypeVersion = instructions.getLast().getThingTypeVersion(); thingBuilder.withProperty(PROPERTY_THING_TYPE_VERSION, String.valueOf(newThingTypeVersion)); logger.info("Updating '{}' from version {} to {}", thing.getUID(), currentThingTypeVersion, newThingTypeVersion); diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingDescriptionList.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingDescriptionList.java index 96eaeb05dee..ebca0d113e0 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingDescriptionList.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingDescriptionList.java @@ -12,6 +12,7 @@ */ package org.openhab.core.thing.xml.internal; +import java.io.Serial; import java.util.ArrayList; import java.util.Collection; @@ -27,6 +28,7 @@ @NonNullByDefault public class ThingDescriptionList extends ArrayList { + @Serial private static final long serialVersionUID = -1579556977347296301L; @SuppressWarnings("unchecked") diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ThingUIDTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ThingUIDTest.java index 2b863e39e82..79e58a74c09 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ThingUIDTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/ThingUIDTest.java @@ -53,6 +53,6 @@ public void testGetBridgeIds() { assertEquals("fake:type:bridge:thing", subject.getAsString()); assertThat(subject.getBridgeIds(), hasSize(1)); - assertEquals("bridge", subject.getBridgeIds().get(0)); + assertEquals("bridge", subject.getBridgeIds().getFirst()); } } diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingBuilderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingBuilderTest.java index 50b45b475ae..93e6912f465 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingBuilderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/builder/ThingBuilderTest.java @@ -92,7 +92,7 @@ public void testWithoutChannel() { thingBuilder.withoutChannel(new ChannelUID(THING_UID, "channel1")); Thing thing = thingBuilder.build(); assertThat(thing.getChannels(), hasSize(1)); - assertThat(thing.getChannels().get(0).getUID().getId(), is(equalTo("channel2"))); + assertThat(thing.getChannels().getFirst().getUID().getId(), is(equalTo("channel2"))); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/xml/internal/ThingDescriptionReaderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/xml/internal/ThingDescriptionReaderTest.java index a361db0dbe4..63764931a1e 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/xml/internal/ThingDescriptionReaderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/xml/internal/ThingDescriptionReaderTest.java @@ -58,14 +58,14 @@ public void readFromXML() throws Exception { assertThat(thingTypeXmlResults.size(), is(1)); - ThingTypeXmlResult thingTypeXmlResult = thingTypeXmlResults.get(0); + ThingTypeXmlResult thingTypeXmlResult = thingTypeXmlResults.getFirst(); assertThat(thingTypeXmlResult.getUID().toString(), is("hue:lamp")); assertThat(thingTypeXmlResult.label, is("HUE Lamp")); assertThat(thingTypeXmlResult.description, is("My own great HUE Lamp.")); assertThat(channelGroupTypeXmlResults.size(), is(1)); - ChannelGroupTypeXmlResult channelGroupTypeXmlResult = channelGroupTypeXmlResults.get(0); + ChannelGroupTypeXmlResult channelGroupTypeXmlResult = channelGroupTypeXmlResults.getFirst(); ChannelGroupType channelGroupType = channelGroupTypeXmlResult.toChannelGroupType(); assertThat(channelGroupTypeXmlResult.getUID().toString(), is("hue:alarm_system")); assertThat(channelGroupType.getLabel(), is("Alarm System")); @@ -73,7 +73,7 @@ public void readFromXML() throws Exception { assertThat(channelTypeXmlResults.size(), is(5)); - ChannelType channelType = channelTypeXmlResults.get(0).toChannelType(); + ChannelType channelType = channelTypeXmlResults.getFirst().toChannelType(); assertThat(channelType.getUID().toString(), is("hue:color")); assertThat(channelType.getKind(), is(ChannelKind.STATE)); assertThat(channelType.isAdvanced(), is(false)); diff --git a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/AbstractFileTransformationService.java b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/AbstractFileTransformationService.java index 03a9bfd58d1..cb3592af719 100644 --- a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/AbstractFileTransformationService.java +++ b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/AbstractFileTransformationService.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.WatchEvent; import java.nio.file.WatchKey; import java.nio.file.WatchService; @@ -190,7 +189,7 @@ private synchronized WatchService getWatchService() throws TransformationExcepti private void watchSubDirectory(String subDirectory, final WatchService watchService) { if (!watchedDirectories.contains(subDirectory)) { String watchedDirectory = getSourcePath() + subDirectory; - Path transformFilePath = Paths.get(watchedDirectory); + Path transformFilePath = Path.of(watchedDirectory); try { WatchKey registrationKey = transformFilePath.register(watchService, ENTRY_DELETE, ENTRY_MODIFY); logger.debug("Watching directory {}", transformFilePath); diff --git a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/TransformationException.java b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/TransformationException.java index 660c6b828d3..4d72bcad312 100644 --- a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/TransformationException.java +++ b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/TransformationException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.transform; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -24,6 +26,7 @@ public class TransformationException extends Exception { /** generated serial Version UID */ + @Serial private static final long serialVersionUID = -535237375844795145L; public TransformationException(String message) { diff --git a/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/IconServlet.java b/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/IconServlet.java index f3a75052561..43a4c5dc6ca 100644 --- a/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/IconServlet.java +++ b/bundles/org.openhab.core.ui.icon/src/main/java/org/openhab/core/ui/icon/internal/IconServlet.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.Serial; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -52,6 +53,7 @@ @NonNullByDefault public class IconServlet extends HttpServlet { + @Serial private static final long serialVersionUID = 2880642275858634578L; private final Logger logger = LoggerFactory.getLogger(IconServlet.class); diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/ChartServlet.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/ChartServlet.java index d976af8e49f..7c3082c603f 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/ChartServlet.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/ChartServlet.java @@ -14,6 +14,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; +import java.io.Serial; import java.time.Duration; import java.time.LocalDateTime; import java.time.Period; @@ -80,6 +81,7 @@ @NonNullByDefault public class ChartServlet extends HttpServlet { + @Serial private static final long serialVersionUID = 7700873790924746422L; protected static final String CONFIG_URI = "system:chart"; diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java index f8590acc63d..68500754fdf 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java @@ -80,7 +80,7 @@ private void addData(XYSeries series, List yData) { // If the start value is below the median, then count legend position down // Otherwise count up. // We use this to decide whether to put the legend in the top or bottom corner. - if (yData.iterator().next().floatValue() > ((series.getYMax() - series.getYMin()) / 2 + series.getYMin())) { + if (yData.getFirst().floatValue() > ((series.getYMax() - series.getYMin()) / 2 + series.getYMin())) { counter++; } else { counter--; @@ -382,8 +382,8 @@ private boolean addItem(XYChart chart, QueryablePersistenceService service, Zone // If there's only 1 data point, plot it again! if (xData.size() == 1) { - xData.add(xData.iterator().next()); - yData.add(yData.iterator().next()); + xData.add(xData.getFirst()); + yData.add(yData.getFirst()); } XYSeries series = chart.addSeries(label, xData, yData); diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/AsyncProxyServlet.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/AsyncProxyServlet.java index 42cfd9ff981..083ce76fc4c 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/AsyncProxyServlet.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/AsyncProxyServlet.java @@ -12,6 +12,7 @@ */ package org.openhab.core.ui.internal.proxy; +import java.io.Serial; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -30,6 +31,7 @@ */ public class AsyncProxyServlet extends org.eclipse.jetty.proxy.AsyncProxyServlet { + @Serial private static final long serialVersionUID = -4716754591953017795L; private final ProxyServletService service; diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/BlockingProxyServlet.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/BlockingProxyServlet.java index 89a81048d7a..7ce94af58be 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/BlockingProxyServlet.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/BlockingProxyServlet.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.Serial; import java.net.URI; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -43,6 +44,7 @@ public class BlockingProxyServlet extends HttpServlet { private final Logger logger = LoggerFactory.getLogger(BlockingProxyServlet.class); + @Serial private static final long serialVersionUID = -4716754591953017794L; private final ProxyServletService service; diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java index 1c4c2646776..46e8110adee 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/proxy/ProxyServletService.java @@ -13,6 +13,7 @@ package org.openhab.core.ui.internal.proxy; import java.io.IOException; +import java.io.Serial; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -86,6 +87,7 @@ public class ProxyServletService extends HttpServlet { /** the alias for this servlet */ public static final String PROXY_ALIAS = "proxy"; + @Serial private static final long serialVersionUID = -4716754591953017793L; private static final String CONFIG_MAX_THREADS = "maxThreads"; private static final int DEFAULT_MAX_THREADS = 8; diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSException.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSException.java index 65ca2f45ed8..a409de9e98b 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSException.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/KSException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.voice; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,6 +24,7 @@ @NonNullByDefault public class KSException extends Exception { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTException.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTException.java index ae3fb49f49d..d3da8a31de2 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTException.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/STTException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.voice; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,6 +24,7 @@ @NonNullByDefault public class STTException extends Exception { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSException.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSException.java index 58020ca0cc1..f4203701795 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSException.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/TTSException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.voice; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,6 +24,7 @@ @NonNullByDefault public class TTSException extends Exception { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/text/StandardInterpreter.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/text/StandardInterpreter.java index d9838cc3389..16d012d16cb 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/text/StandardInterpreter.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/text/StandardInterpreter.java @@ -85,7 +85,7 @@ protected void deactivate() { @Override public Set getSupportedLocales() { - return Set.of(Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH, new Locale("es")); + return Set.of(Locale.ENGLISH, Locale.GERMAN, Locale.FRENCH, Locale.of("es")); } @Override @@ -306,7 +306,7 @@ public void createRules(@Nullable Locale locale) { /* ***************************** SPANISH ***************************** */ - Locale localeES = new Locale("es"); + Locale localeES = Locale.of("es"); if (locale == null || Objects.equals(locale.getLanguage(), localeES.getLanguage())) { Expression encenderApagar = alt(cmd(alt("enciende", "encender"), OnOffType.ON), cmd(alt("apaga", "apagar"), OnOffType.OFF)); diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/AbstractRuleBasedInterpreter.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/AbstractRuleBasedInterpreter.java index 4a1eeaf55a8..9909248567b 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/AbstractRuleBasedInterpreter.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/AbstractRuleBasedInterpreter.java @@ -799,7 +799,7 @@ protected String executeSingle(ResourceBundle language, String[] labelFragments, } else if (items.size() > 1) { throw new InterpretationException(language.getString(MULTIPLE_OBJECTS)); } else { - Item item = items.get(0); + Item item = items.getFirst(); Command command = commandSupplier.getItemCommand(item); if (command == null) { logger.warn("Failed resolving item command"); @@ -912,7 +912,7 @@ protected List getMatchingItems(ResourceBundle language, String[] labelFra List lowercaseLabelFragments = Arrays.stream(labelFragments) .map(lf -> lf.toLowerCase(language.getLocale())).toList(); List unmatchedFragments = new ArrayList<>(lowercaseLabelFragments); - if (itemLabelFragmentsPath.get(itemLabelFragmentsPath.size() - 1).equals(lowercaseLabelFragments)) { + if (itemLabelFragmentsPath.getLast().equals(lowercaseLabelFragments)) { exactMatch = true; exactMatchOnTarget = true; unmatchedFragments.clear(); @@ -1007,7 +1007,7 @@ private Item filterMatchedItemsByLocation(Map return null; } logger.trace("Unique match by location found in '{}', taking prevalence", locationContext); - return itemsFilteredByLocation.get(0).getKey(); + return itemsFilteredByLocation.getFirst().getKey(); } private static void insertDiscardingMembers(Map items, Item item, diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/ExpressionCardinality.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/ExpressionCardinality.java index 932f14f4760..2d5b3ffcee8 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/ExpressionCardinality.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/ExpressionCardinality.java @@ -60,7 +60,7 @@ ASTNode parse(ResourceBundle language, TokenList tokenList) { node.setChildren(nodes.toArray(new ASTNode[0])); node.setRemainingTokens(list); node.setSuccess(true); - node.setValue(atMostOne ? (values.isEmpty() ? null : values.get(0)) : values.toArray()); + node.setValue(atMostOne ? (values.isEmpty() ? null : values.getFirst()) : values.toArray()); generateValue(node); } return node; diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/InterpretationException.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/InterpretationException.java index 0329f0fed9a..fc0e7c99115 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/InterpretationException.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/InterpretationException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.voice.text; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,6 +24,7 @@ @NonNullByDefault public class InterpretationException extends Exception { + @Serial private static final long serialVersionUID = 76120119745036525L; /** diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/OpenHAB.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/OpenHAB.java index 8051a1ed3ec..2873fac0045 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/OpenHAB.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/OpenHAB.java @@ -14,7 +14,6 @@ import java.io.FileInputStream; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Properties; import java.util.regex.Pattern; @@ -84,7 +83,7 @@ public static String getVersion() { */ public static String buildString() { Properties prop = new Properties(); - Path versionFilePath = Paths.get(getUserDataFolder(), "etc", "version.properties"); + Path versionFilePath = Path.of(getUserDataFolder(), "etc", "version.properties"); try (FileInputStream fis = new FileInputStream(versionFilePath.toFile())) { prop.load(fis); String buildNo = prop.getProperty("build-no"); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/AuthenticationException.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/AuthenticationException.java index ac129db1625..e651630088a 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/AuthenticationException.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/AuthenticationException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.auth; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -23,6 +25,7 @@ @NonNullByDefault public class AuthenticationException extends SecurityException { + @Serial private static final long serialVersionUID = 8063538216812770858L; /** diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java index 8703a141126..e829272bd74 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/AccessTokenResponse.java @@ -12,6 +12,7 @@ */ package org.openhab.core.auth.client.oauth2; +import java.io.Serial; import java.io.Serializable; import java.time.Instant; import java.util.Objects; @@ -32,6 +33,7 @@ public final class AccessTokenResponse implements Serializable, Cloneable { /** * For Serializable */ + @Serial private static final long serialVersionUID = 4837164195629364014L; /** diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/OAuthException.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/OAuthException.java index 183ca7598f8..8aa6d288341 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/OAuthException.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/OAuthException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.auth.client.oauth2; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -22,6 +24,7 @@ @NonNullByDefault public class OAuthException extends Exception { + @Serial private static final long serialVersionUID = -2548612391437480321L; public OAuthException() { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/OAuthResponseException.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/OAuthResponseException.java index 730047da092..50b5dd9f316 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/OAuthResponseException.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/client/oauth2/OAuthResponseException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.auth.client.oauth2; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -34,6 +36,7 @@ @NonNullByDefault public class OAuthResponseException extends Exception { + @Serial private static final long serialVersionUID = -3268280125111194474L; /** diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/LRUMediaCache.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/LRUMediaCache.java index da7937f96b7..136809d4d08 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/LRUMediaCache.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/LRUMediaCache.java @@ -19,7 +19,6 @@ import java.nio.file.FileStore; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -155,7 +154,7 @@ private void cleanCacheDirectory() throws IOException { private long getFreeSpace() { try { - Path rootPath = Paths.get(new URI("file:///")); + Path rootPath = Path.of(new URI("file:///")); Path dirPath = rootPath.resolve(cacheFolder.getParent()); FileStore dirFileStore = Files.getFileStore(dirPath); return dirFileStore.getUsableSpace(); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/common/osgi/ResourceBundleClassLoader.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/common/osgi/ResourceBundleClassLoader.java index 2ea17dd4b8f..5b7b76395ce 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/common/osgi/ResourceBundleClassLoader.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/common/osgi/ResourceBundleClassLoader.java @@ -89,7 +89,7 @@ public URL getResource(String name) { } if (allResources.size() == 1) { - return allResources.get(0); + return allResources.getFirst(); } // handle fragment resources. return first one. diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/events/TopicGlobEventFilter.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/events/TopicGlobEventFilter.java index 00412aa4978..4d36ca9daed 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/events/TopicGlobEventFilter.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/events/TopicGlobEventFilter.java @@ -13,8 +13,8 @@ package org.openhab.core.events; import java.nio.file.FileSystems; +import java.nio.file.Path; import java.nio.file.PathMatcher; -import java.nio.file.Paths; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -46,6 +46,6 @@ public TopicGlobEventFilter(String topicGlob) { @Override public boolean apply(Event event) { - return topicMatcher.matches(Paths.get(event.getTopic())); + return topicMatcher.matches(Path.of(event.getTopic())); } } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/common/DuplicateExecutionException.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/common/DuplicateExecutionException.java index 1175db74a61..3ce83269ae5 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/common/DuplicateExecutionException.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/common/DuplicateExecutionException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.internal.common; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -21,6 +23,7 @@ */ @NonNullByDefault class DuplicateExecutionException extends RuntimeException { + @Serial private static final long serialVersionUID = 1L; private final Invocation callable; diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/GroupFunctionHelper.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/GroupFunctionHelper.java index 5da563fbc87..1b2f3c4f868 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/GroupFunctionHelper.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/GroupFunctionHelper.java @@ -111,7 +111,7 @@ private GroupFunction createDefaultGroupFunction(GroupFunctionDTO function, @Nul case "AND": args = parseStates(baseItem, function.params); if (args.size() == 2) { - return new ArithmeticGroupFunction.And(args.get(0), args.get(1)); + return new ArithmeticGroupFunction.And(args.getFirst(), args.get(1)); } else { logger.error("Group function 'AND' requires two arguments. Using Equality instead."); } @@ -119,7 +119,7 @@ private GroupFunction createDefaultGroupFunction(GroupFunctionDTO function, @Nul case "OR": args = parseStates(baseItem, function.params); if (args.size() == 2) { - return new ArithmeticGroupFunction.Or(args.get(0), args.get(1)); + return new ArithmeticGroupFunction.Or(args.getFirst(), args.get(1)); } else { logger.error("Group function 'OR' requires two arguments. Using Equality instead."); } @@ -127,7 +127,7 @@ private GroupFunction createDefaultGroupFunction(GroupFunctionDTO function, @Nul case "NAND": args = parseStates(baseItem, function.params); if (args.size() == 2) { - return new ArithmeticGroupFunction.NAnd(args.get(0), args.get(1)); + return new ArithmeticGroupFunction.NAnd(args.getFirst(), args.get(1)); } else { logger.error("Group function 'NOT AND' requires two arguments. Using Equality instead."); } @@ -135,7 +135,7 @@ private GroupFunction createDefaultGroupFunction(GroupFunctionDTO function, @Nul case "NOR": args = parseStates(baseItem, function.params); if (args.size() == 2) { - return new ArithmeticGroupFunction.NOr(args.get(0), args.get(1)); + return new ArithmeticGroupFunction.NOr(args.getFirst(), args.get(1)); } else { logger.error("Group function 'NOT OR' requires two arguments. Using Equality instead."); } @@ -143,7 +143,7 @@ private GroupFunction createDefaultGroupFunction(GroupFunctionDTO function, @Nul case "XOR": args = parseStates(baseItem, function.params); if (args.size() == 2) { - return new ArithmeticGroupFunction.Xor(args.get(0), args.get(1)); + return new ArithmeticGroupFunction.Xor(args.getFirst(), args.get(1)); } else { logger.error("Group function 'XOR' requires two arguments. Using Equality instead."); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/service/WatchServiceImpl.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/service/WatchServiceImpl.java index 3dbd1f8733b..0d80ff69ba6 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/service/WatchServiceImpl.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/service/WatchServiceImpl.java @@ -242,8 +242,8 @@ private void notifyListeners(Path path) { return; } - DirectoryChangeEvent firstElement = events.get(0); - DirectoryChangeEvent lastElement = events.get(events.size() - 1); + DirectoryChangeEvent firstElement = events.getFirst(); + DirectoryChangeEvent lastElement = events.getLast(); // determine final event if (lastElement.eventType() == DirectoryChangeEvent.EventType.DELETE) { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemLookupException.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemLookupException.java index 1c7651a2050..738be2bceb2 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemLookupException.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemLookupException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.items; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -27,5 +29,6 @@ public ItemLookupException(String string) { super(string); } + @Serial private static final long serialVersionUID = -4617708589675048859L; } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemNotFoundException.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemNotFoundException.java index f725c23a2f1..86493a2fc51 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemNotFoundException.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemNotFoundException.java @@ -12,6 +12,8 @@ */ package org.openhab.core.items; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -27,5 +29,6 @@ public ItemNotFoundException(String name) { super("Item '" + name + "' could not be found in the item registry"); } + @Serial private static final long serialVersionUID = -3720784568250902711L; } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemNotUniqueException.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemNotUniqueException.java index d3a423ff50a..bcda1f43992 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemNotUniqueException.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/ItemNotUniqueException.java @@ -12,6 +12,7 @@ */ package org.openhab.core.items; +import java.io.Serial; import java.util.Collection; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -25,6 +26,7 @@ @NonNullByDefault public class ItemNotUniqueException extends ItemLookupException { + @Serial private static final long serialVersionUID = 5154625234283910124L; private final Collection matchingItems; diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DecimalType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DecimalType.java index 4fa09f166ce..009ce974120 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DecimalType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/DecimalType.java @@ -12,6 +12,7 @@ */ package org.openhab.core.library.types; +import java.io.Serial; import java.math.BigDecimal; import java.math.BigInteger; import java.text.DecimalFormat; @@ -35,6 +36,7 @@ @NonNullByDefault public class DecimalType extends Number implements PrimitiveType, State, Command, Comparable { + @Serial private static final long serialVersionUID = 4226845847123464690L; protected static final BigDecimal BIG_DECIMAL_HUNDRED = BigDecimal.valueOf(100); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/HSBType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/HSBType.java index de3e857ac6d..f1065926889 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/HSBType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/HSBType.java @@ -12,6 +12,7 @@ */ package org.openhab.core.library.types; +import java.io.Serial; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Arrays; @@ -38,6 +39,7 @@ @NonNullByDefault public class HSBType extends PercentType implements ComplexType, State, Command { + @Serial private static final long serialVersionUID = 322902950356613226L; // constants for the constituents @@ -87,7 +89,7 @@ public HSBType(DecimalType h, PercentType s, PercentType b) { public HSBType(String value) { List constituents = Arrays.stream(value.split(",")).map(String::trim).toList(); if (constituents.size() == 3) { - this.hue = new BigDecimal(constituents.get(0)); + this.hue = new BigDecimal(constituents.getFirst()); this.saturation = new BigDecimal(constituents.get(1)); this.value = new BigDecimal(constituents.get(2)); validateValue(this.hue, this.saturation, this.value); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PercentType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PercentType.java index 40a219abffd..0435bcf82b7 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PercentType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PercentType.java @@ -12,6 +12,7 @@ */ package org.openhab.core.library.types; +import java.io.Serial; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Locale; @@ -29,6 +30,7 @@ @NonNullByDefault public class PercentType extends DecimalType { + @Serial private static final long serialVersionUID = -9066279845951780879L; public static final PercentType ZERO = new PercentType(0); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PointType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PointType.java index 19843c3f31d..c850649a466 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PointType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/PointType.java @@ -86,7 +86,7 @@ public PointType(String value) { if (!value.isEmpty()) { List elements = Arrays.stream(value.split(",")).map(String::trim).toList(); if (elements.size() >= 2) { - canonicalize(new DecimalType(elements.get(0)), new DecimalType(elements.get(1))); + canonicalize(new DecimalType(elements.getFirst()), new DecimalType(elements.get(1))); if (elements.size() == 3) { setAltitude(new DecimalType(elements.get(2))); } else if (elements.size() > 3) { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java index 878e06bb2a6..c380ca49692 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java @@ -14,6 +14,7 @@ import static org.eclipse.jdt.annotation.DefaultLocation.*; +import java.io.Serial; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -71,6 +72,7 @@ public class QuantityType> extends Number implements PrimitiveType, State, Command, Comparable> { + @Serial private static final long serialVersionUID = 8828949721938234629L; private static final BigDecimal BIG_DECIMAL_HUNDRED = BigDecimal.valueOf(100); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/CurrencyUnit.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/CurrencyUnit.java index fc579afa11c..920ab005c22 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/CurrencyUnit.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/unit/CurrencyUnit.java @@ -15,6 +15,7 @@ import static org.eclipse.jdt.annotation.DefaultLocation.*; import static org.openhab.core.library.unit.CurrencyUnits.BASE_CURRENCY; +import java.io.Serial; import java.math.BigDecimal; import java.math.MathContext; import java.util.Map; @@ -46,6 +47,7 @@ @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND }) public final class CurrencyUnit extends AbstractUnit { + @Serial private static final long serialVersionUID = -1L; private static final Dimension DIMENSION = UnitDimension.parse('$'); private String name; diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/net/NetUtil.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/net/NetUtil.java index 3bfe88ac6e3..60dd3bd471a 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/net/NetUtil.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/net/NetUtil.java @@ -309,7 +309,7 @@ public static List getAllBroadcastAddresses() { private static @Nullable String getFirstIpv4BroadcastAddress() { final List broadcastAddresses = getAllBroadcastAddresses(); if (!broadcastAddresses.isEmpty()) { - return broadcastAddresses.get(0); + return broadcastAddresses.getFirst(); } else { return null; } @@ -630,8 +630,8 @@ public static List getAddressesRangeByCidrAddress(CidrAddress iFace List addresses = getAddressesInSubnet(iFaceAddress.getAddress().getAddress(), iFaceAddress.getPrefix()); if (addresses.size() > 2) { - addresses.remove(0); // remove network address - addresses.remove(addresses.size() - 1); // remove broadcast address + addresses.removeFirst(); // remove network address + addresses.removeLast(); // remove broadcast address } return addresses.stream().map(m -> { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/scheduler/CronAdjuster.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/scheduler/CronAdjuster.java index 4bf60a8c896..b8cbcc20719 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/scheduler/CronAdjuster.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/scheduler/CronAdjuster.java @@ -540,7 +540,7 @@ public Temporal adjustInto(@Nullable final Temporal temporal) { private Checker or(final List checkers) { return checkers.size() > 1 // ? temporal -> checkers.stream().anyMatch(c -> c.matches(temporal)) - : checkers.get(0); + : checkers.getFirst(); } /** diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/lru/LRUMediaCacheEntryTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/lru/LRUMediaCacheEntryTest.java index 6e91f1b315d..dd705ed85e4 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/lru/LRUMediaCacheEntryTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/lru/LRUMediaCacheEntryTest.java @@ -205,7 +205,7 @@ public void loadTwoThreadsAtTheSameTimeFromTheSameSupplierTest() throws IOExcept if (possibleException != null) { throw possibleException; } - assertArrayEquals(randomData, bytesResultList.get(0)); + assertArrayEquals(randomData, bytesResultList.getFirst()); assertArrayEquals(randomData, bytesResultList.get(1)); actualAudioStream1.close(); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java index c8c061731cc..4aa81e005bd 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/common/osgi/ResourceBundleClassLoaderTest.java @@ -19,7 +19,6 @@ import java.io.File; import java.net.URL; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Collections; import java.util.List; @@ -37,7 +36,7 @@ public class ResourceBundleClassLoaderTest { private @TempDir @NonNullByDefault({}) Path tempDir; static URL createTmpTestPropertiesFile(Path root, String relativeFile) throws Exception { - Path filePath = Paths.get(relativeFile); + Path filePath = Path.of(relativeFile); Path dirPath = filePath.getParent(); new File(root.toFile(), dirPath.toString()).mkdirs(); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/common/SafeCallerImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/common/SafeCallerImplTest.java index 2bf70f33867..6c72c941c8e 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/common/SafeCallerImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/common/SafeCallerImplTest.java @@ -569,7 +569,7 @@ private void spawn(Runnable runnable) { */ private void joinAll() throws InterruptedException { while (!threads.isEmpty()) { - AssertingThread t = threads.remove(0); + AssertingThread t = threads.removeFirst(); t.join(); if (t.assertionError != null) { throw t.assertionError; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java index 39b3ea61767..ce8e0fbc007 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/internal/scheduler/SchedulerImplTest.java @@ -258,7 +258,7 @@ public void testScheduleException() throws InterruptedException { assertEquals(0, temporalAdjuster.getCount(), "Scheduler should have run 0 time"); assertEquals(1, listAppender.list.size()); - ILoggingEvent loggingEvent = listAppender.list.get(0); + ILoggingEvent loggingEvent = listAppender.list.getFirst(); assertEquals(Level.WARN, loggingEvent.getLevel()); assertEquals("Scheduled job 'myScheduledJob' failed and stopped", loggingEvent.getFormattedMessage()); } diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java index 3cdd62aaad4..2c70a20c50c 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java @@ -69,8 +69,8 @@ public void testItemPostsEventsCorrectly() { assertEquals(2, events.size()); // first event should be updated event - assertInstanceOf(ItemStateUpdatedEvent.class, events.get(0)); - ItemStateUpdatedEvent updated = (ItemStateUpdatedEvent) events.get(0); + assertInstanceOf(ItemStateUpdatedEvent.class, events.getFirst()); + ItemStateUpdatedEvent updated = (ItemStateUpdatedEvent) events.getFirst(); assertEquals(item.getName(), updated.getItemName()); assertEquals("openhab/items/member1/stateupdated", updated.getTopic()); assertEquals(item.getState(), updated.getItemState()); @@ -97,8 +97,8 @@ public void testItemPostsEventsCorrectly() { assertEquals(1, events.size()); // two before and one additional // event should be updated event - assertInstanceOf(ItemStateUpdatedEvent.class, events.get(0)); - updated = (ItemStateUpdatedEvent) events.get(0); + assertInstanceOf(ItemStateUpdatedEvent.class, events.getFirst()); + updated = (ItemStateUpdatedEvent) events.getFirst(); assertEquals(item.getName(), updated.getItemName()); assertEquals("openhab/items/member1/stateupdated", updated.getTopic()); assertEquals(item.getState(), updated.getItemState()); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/net/NetUtilTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/net/NetUtilTest.java index 173414a8e83..2bbf0602d2b 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/net/NetUtilTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/net/NetUtilTest.java @@ -129,7 +129,7 @@ public void checkValidRangeCountAndSort() throws UnknownHostException { .getAddressesRangeByCidrAddress(new CidrAddress(testableAddress, (short) 24), 24); assertEquals(254, addresses.size()); - assertEquals("192.168.1.1", addresses.get(0).getHostAddress()); + assertEquals("192.168.1.1", addresses.getFirst().getHostAddress()); assertEquals("192.168.1.254", addresses.get(253).getHostAddress()); } @@ -140,7 +140,7 @@ public void checkValidLargeRangeCountAndSort() throws UnknownHostException { .getAddressesRangeByCidrAddress(new CidrAddress(testableAddress, (short) 16), 16); assertEquals(65534, addresses.size()); - assertEquals("127.0.0.1", addresses.get(0).getHostAddress()); + assertEquals("127.0.0.1", addresses.getFirst().getHostAddress()); assertEquals("127.0.255.254", addresses.get(65533).getHostAddress()); } diff --git a/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoI18nTest.java b/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoI18nTest.java index 78b303298f3..23364e4f319 100644 --- a/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoI18nTest.java +++ b/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoI18nTest.java @@ -65,7 +65,7 @@ public void assertAddonInfosWereLocalizedInGerman() throws Exception { @Test public void assertAddonInfosWereLocalizedInDutch() throws Exception { addonInstaller.exec(TEST_BUNDLE_NAME, () -> { - Set bindingInfos = addonInfoRegistry.getAddonInfos(new Locale("nl")); + Set bindingInfos = addonInfoRegistry.getAddonInfos(Locale.of("nl")); AddonInfo bindingInfo = bindingInfos.iterator().next(); assertThat(bindingInfo, is(notNullValue())); diff --git a/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoTest.java b/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoTest.java index cdb5575e3d3..a8d69424bdb 100644 --- a/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoTest.java +++ b/itests/org.openhab.core.addon.tests/src/main/java/org/openhab/core/addon/xml/test/AddonInfoTest.java @@ -76,13 +76,13 @@ public void assertThatAddonInfoIsReadProperly() throws Exception { assertNotNull(discoveryMethods); assertEquals(2, discoveryMethods.size()); - AddonDiscoveryMethod discoveryMethod = discoveryMethods.get(0); + AddonDiscoveryMethod discoveryMethod = discoveryMethods.getFirst(); assertNotNull(discoveryMethod); assertEquals("mdns", discoveryMethod.getServiceType()); List parameters = discoveryMethod.getParameters(); assertNotNull(parameters); assertEquals(1, parameters.size()); - AddonParameter parameter = parameters.get(0); + AddonParameter parameter = parameters.getFirst(); assertNotNull(parameter); assertEquals(MDNS_SERVICE_TYPE, parameter.getName()); assertEquals("_hue._tcp.local.", parameter.getValue()); @@ -99,7 +99,7 @@ public void assertThatAddonInfoIsReadProperly() throws Exception { properties = discoveryMethod.getMatchProperties(); assertNotNull(properties); assertEquals(1, properties.size()); - AddonMatchProperty property = properties.get(0); + AddonMatchProperty property = properties.getFirst(); assertNotNull(property); assertEquals("modelName", property.getName()); assertEquals("Philips hue bridge", property.getRegex()); diff --git a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/HostFragmentSupportTest.java b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/HostFragmentSupportTest.java index 683a1ffc7f1..561a7edef15 100644 --- a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/HostFragmentSupportTest.java +++ b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/HostFragmentSupportTest.java @@ -46,7 +46,7 @@ @NonNullByDefault public class HostFragmentSupportTest extends JavaOSGiTest { - private static final Locale BULGARIAN = new Locale("bg"); + private static final Locale BULGARIAN = Locale.of("bg"); private static final Locale DEFAULT = Locale.ENGLISH; private static final Locale GERMAN = Locale.GERMANY; diff --git a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/BasicConditionHandlerTest.java b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/BasicConditionHandlerTest.java index f175f47d350..c3b510c3882 100644 --- a/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/BasicConditionHandlerTest.java +++ b/itests/org.openhab.core.automation.module.timer.tests/src/main/java/org/openhab/core/automation/module/timer/internal/BasicConditionHandlerTest.java @@ -200,8 +200,9 @@ public void receive(Event event) { logger.info("item state is ON"); // now make the condition fail - Rule rule2 = RuleBuilder.create(rule).withConditions(ModuleBuilder.createCondition(rule.getConditions().get(0)) - .withConfiguration(getFailingConfiguration()).build()).build(); + Rule rule2 = RuleBuilder.create(rule).withConditions(ModuleBuilder + .createCondition(rule.getConditions().getFirst()).withConfiguration(getFailingConfiguration()).build()) + .build(); ruleRegistry.update(rule2); // prepare the execution diff --git a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleEngineTest.java b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleEngineTest.java index 9141143c8b1..16418f0984a 100644 --- a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleEngineTest.java +++ b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleEngineTest.java @@ -79,13 +79,13 @@ public void setup() { public void testAutoMapRuleConnections() { RuleImpl rule = createAutoMapRule(); // check condition connections - Map conditionInputs = rule.getConditions().get(0).getInputs(); + Map conditionInputs = rule.getConditions().getFirst().getInputs(); assertEquals(1, conditionInputs.size(), "Number of user define condition inputs"); assertEquals("triggerId.triggerOutput", conditionInputs.get("conditionInput"), "Check user define condition connection"); // check action connections - Map actionInputs = rule.getActions().get(0).getInputs(); + Map actionInputs = rule.getActions().getFirst().getInputs(); assertEquals(2, actionInputs.size(), "Number of user define action inputs"); assertEquals("triggerId.triggerOutput", actionInputs.get("actionInput"), "Check user define action connections for input actionInput"); @@ -98,7 +98,7 @@ public void testAutoMapRuleConnections() { assertEquals("AutoMapRule", ruleGet.getUID(), "Returned rule with wrong UID"); // check condition connections - conditionInputs = ruleGet.getConditions().get(0).getInputs(); + conditionInputs = ruleGet.getConditions().getFirst().getInputs(); assertEquals(2, conditionInputs.size(), "Number of user define condition inputs"); assertEquals("triggerId.triggerOutput", conditionInputs.get("conditionInput"), "Check user define condition connection"); @@ -106,7 +106,7 @@ public void testAutoMapRuleConnections() { "Auto map condition input in2[tagA, tagB] to trigger output out3[tagA, tagB, tagC]"); // check action connections - actionInputs = ruleGet.getActions().get(0).getInputs(); + actionInputs = ruleGet.getActions().getFirst().getInputs(); assertEquals(4, actionInputs.size(), "Number of user define action inputs"); assertEquals("triggerId.triggerOutput", actionInputs.get("actionInput"), "Check user define action connections for input actionInput"); @@ -184,12 +184,12 @@ public void testRuleConfigValue() { assertNotNull(rule4cfgD, "RuleImpl configuration description is null"); assertEquals(1, rule4cfgD.size(), "Missing config description in rule copy"); - ConfigDescriptionParameter rule4cfgDP = rule4cfgD.iterator().next(); + ConfigDescriptionParameter rule4cfgDP = rule4cfgD.getFirst(); assertEquals("3", rule4cfgDP.getDefault(), "Wrong default value in config description"); assertEquals("context1", rule4cfgDP.getContext(), "Wrong context value in config description"); assertNotNull(rule4cfgDP.getOptions(), "Null options in config description"); - assertEquals("1", rule4cfgDP.getOptions().get(0).getValue(), "Wrong option value in config description"); - assertEquals("one", rule4cfgDP.getOptions().get(0).getLabel(), "Wrong option label in config description"); + assertEquals("1", rule4cfgDP.getOptions().getFirst().getValue(), "Wrong option value in config description"); + assertEquals("one", rule4cfgDP.getOptions().getFirst().getLabel(), "Wrong option label in config description"); } /** diff --git a/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/ConfigOptionRegistryOSGiTest.java b/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/ConfigOptionRegistryOSGiTest.java index 6e7b8e833e1..81cff386507 100644 --- a/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/ConfigOptionRegistryOSGiTest.java +++ b/itests/org.openhab.core.config.core.tests/src/main/java/org/openhab/core/config/core/ConfigOptionRegistryOSGiTest.java @@ -79,9 +79,9 @@ public void assertConfigDescriptionRegistryMergesOptions() { assertThat(configDescriptions, is(not(nullValue()))); assertThat("Config is found", configDescriptions.getUID(), is(DUMMY_URI)); assertThat("Config contains parameter", configDescriptions.getParameters(), hasSize(1)); - assertThat("Config parameter found", configDescriptions.getParameters().get(0).getName(), + assertThat("Config parameter found", configDescriptions.getParameters().getFirst().getName(), is(equalTo("Param1"))); - assertThat("Config parameter contains options", configDescriptions.getParameters().get(0).getOptions(), + assertThat("Config parameter contains options", configDescriptions.getParameters().getFirst().getOptions(), hasSize(2)); configDescriptionRegistry.removeConfigOptionProvider(configOptionsProviderMock); diff --git a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java index fdea2852136..09ffaa2b9c0 100644 --- a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java +++ b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/internal/InboxOSGiTest.java @@ -160,10 +160,10 @@ protected void startScan() { .withConfigDescriptionURI(testURI).build(); private final ConfigDescription testConfigDescription = ConfigDescriptionBuilder.create(testURI) .withParameters(List.of( - ConfigDescriptionParameterBuilder.create(discoveryResultPropertyKeys.get(0), Type.TEXT).build(), + ConfigDescriptionParameterBuilder.create(discoveryResultPropertyKeys.getFirst(), Type.TEXT).build(), ConfigDescriptionParameterBuilder.create(discoveryResultPropertyKeys.get(1), Type.INTEGER).build())) .build(); - private final String[] keysInConfigDescription = new String[] { discoveryResultPropertyKeys.get(0), + private final String[] keysInConfigDescription = new String[] { discoveryResultPropertyKeys.getFirst(), discoveryResultPropertyKeys.get(1) }; private final String[] keysNotInConfigDescription = new String[] { discoveryResultPropertyKeys.get(2), discoveryResultPropertyKeys.get(3), discoveryResultPropertyKeys.get(4) }; @@ -295,7 +295,7 @@ public void assertThatGetAllIncludesPreviouslyAddedDiscoveryResult() { allDiscoveryResults = inbox.getAll(); assertThat(allDiscoveryResults.size(), is(1)); - DiscoveryResult actualDiscoveryResult = allDiscoveryResults.get(0); + DiscoveryResult actualDiscoveryResult = allDiscoveryResults.getFirst(); assertThat(actualDiscoveryResult.getThingUID(), is(thingUID)); assertThat(actualDiscoveryResult.getThingTypeUID(), is(thingTypeUID)); assertThat(actualDiscoveryResult.getBindingId(), is("dummyBindingId")); @@ -338,7 +338,7 @@ public void assertThatGetAllIncludesPreviouslyUpdatedDiscoveryResult() { allDiscoveryResults = inbox.getAll(); assertThat(allDiscoveryResults.size(), is(1)); - DiscoveryResult actualDiscoveryResult = allDiscoveryResults.get(0); + DiscoveryResult actualDiscoveryResult = allDiscoveryResults.getFirst(); assertThat(actualDiscoveryResult.getThingUID(), is(thingUID)); assertThat(actualDiscoveryResult.getThingTypeUID(), is(thingTypeUID)); assertThat(actualDiscoveryResult.getBindingId(), is("dummyBindingId")); diff --git a/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java b/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java index 97b8737ecb6..266181ccee3 100644 --- a/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java +++ b/itests/org.openhab.core.config.dispatch.tests/src/main/java/org/openhab/core/config/dispatch/internal/ConfigDispatcherOSGiTest.java @@ -21,7 +21,6 @@ import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileTime; @@ -71,8 +70,8 @@ public static void setUpClass() { @BeforeEach public void setUp() throws IOException, InvalidSyntaxException { configBaseDirectory = tmpBaseFolder.getAbsolutePath(); - final Path source = Paths.get(CONFIGURATION_BASE_DIR); - Files.walkFileTree(source, new CopyDirectoryRecursive(source, Paths.get(configBaseDirectory))); + final Path source = Path.of(CONFIGURATION_BASE_DIR); + Files.walkFileTree(source, new CopyDirectoryRecursive(source, Path.of(configBaseDirectory))); configAdmin = getService(ConfigurationAdmin.class); assertThat(configAdmin, is(notNullValue())); diff --git a/itests/org.openhab.core.io.net.tests/src/main/java/org/openhab/core/io/net/tests/internal/TestHttpServlet.java b/itests/org.openhab.core.io.net.tests/src/main/java/org/openhab/core/io/net/tests/internal/TestHttpServlet.java index 50ab70e3711..d1cd361fc8d 100644 --- a/itests/org.openhab.core.io.net.tests/src/main/java/org/openhab/core/io/net/tests/internal/TestHttpServlet.java +++ b/itests/org.openhab.core.io.net.tests/src/main/java/org/openhab/core/io/net/tests/internal/TestHttpServlet.java @@ -13,6 +13,7 @@ package org.openhab.core.io.net.tests.internal; import java.io.IOException; +import java.io.Serial; import java.nio.charset.StandardCharsets; import javax.servlet.ServletException; @@ -31,6 +32,7 @@ */ @NonNullByDefault public class TestHttpServlet extends HttpServlet { + @Serial private static final long serialVersionUID = 1L; @Override diff --git a/itests/org.openhab.core.io.net.tests/src/main/java/org/openhab/core/io/net/tests/internal/TestWebSocketServlet.java b/itests/org.openhab.core.io.net.tests/src/main/java/org/openhab/core/io/net/tests/internal/TestWebSocketServlet.java index ebf55c4752d..93034d9b6d9 100644 --- a/itests/org.openhab.core.io.net.tests/src/main/java/org/openhab/core/io/net/tests/internal/TestWebSocketServlet.java +++ b/itests/org.openhab.core.io.net.tests/src/main/java/org/openhab/core/io/net/tests/internal/TestWebSocketServlet.java @@ -12,6 +12,8 @@ */ package org.openhab.core.io.net.tests.internal; +import java.io.Serial; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.websocket.servlet.WebSocketServlet; @@ -24,6 +26,7 @@ */ @NonNullByDefault public class TestWebSocketServlet extends WebSocketServlet { + @Serial private static final long serialVersionUID = 1L; @Override diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResourceOSGiTest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResourceOSGiTest.java index cccda5f443a..da7d3e11f5f 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResourceOSGiTest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResourceOSGiTest.java @@ -262,7 +262,7 @@ public void addMultipleItems() throws IOException { // expect 2x created assertThat(statusCodes.size(), is(2)); - assertThat(statusCodes.get(0), is("created")); + assertThat(statusCodes.getFirst(), is("created")); assertThat(statusCodes.get(1), is("created")); itemList.clear(); @@ -280,7 +280,7 @@ public void addMultipleItems() throws IOException { // expect error and updated assertThat(statusCodes.size(), is(2)); - assertThat(statusCodes.get(0), is("error")); + assertThat(statusCodes.getFirst(), is("error")); assertThat(statusCodes.get(1), is("updated")); } diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/profile/ProfileTypeResourceTest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/profile/ProfileTypeResourceTest.java index c03733bd03a..d307d0ba419 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/profile/ProfileTypeResourceTest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/internal/profile/ProfileTypeResourceTest.java @@ -138,7 +138,7 @@ public void testGetProfileTypesForOtherChannel() { // channel side assertThat(list.size(), is(1)); - ProfileTypeDTO pt = list.get(0); + ProfileTypeDTO pt = list.getFirst(); assertThat(pt.kind, is("STATE")); assertThat(pt.label, is("profile2")); assertThat(pt.uid, is(stateProfileTypeUID2.toString())); @@ -165,7 +165,7 @@ public void testGetProfileTypesForTriggerChannel2() { // should be only the second trigger profile because the first one is restricted to another channel type UID assertThat(list.size(), is(1)); - ProfileTypeDTO pt = list.get(0); + ProfileTypeDTO pt = list.getFirst(); assertThat(pt.kind, is("TRIGGER")); assertThat(pt.label, is("profile4")); assertThat(pt.uid, is(triggerProfileTypeUID2.toString())); diff --git a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperWithTransformOSGiTest.java b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperWithTransformOSGiTest.java index e40c0b2b97d..c70f497a589 100644 --- a/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperWithTransformOSGiTest.java +++ b/itests/org.openhab.core.io.rest.core.tests/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapperWithTransformOSGiTest.java @@ -67,7 +67,7 @@ public void shouldConsiderTraformationWhenPresent() { assertThat(sd.getMaximum(), is(BigDecimal.valueOf(100))); assertThat(sd.getStep(), is(BigDecimal.valueOf(10))); assertThat(sd.getPattern(), is("%d °C")); - assertThat(sd.getOptions().get(0).getValue(), is("SOUND")); - assertThat(sd.getOptions().get(0).getLabel(), is("My great sound.")); + assertThat(sd.getOptions().getFirst().getValue(), is("SOUND")); + assertThat(sd.getOptions().getFirst().getLabel(), is("My great sound.")); } } diff --git a/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java b/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java index ebb721ff4d3..98dac72f42d 100644 --- a/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java +++ b/itests/org.openhab.core.model.item.tests/src/main/java/org/openhab/core/model/item/internal/GenericItemProviderTest.java @@ -646,7 +646,7 @@ public void testMetadataPropertyTypes() { assertThat(list, instanceOf(List.class)); List values = (List) list; assertThat(values.size(), is(2)); - assertThat(values.get(0), is("string1")); + assertThat(values.getFirst(), is("string1")); assertThat(values.get(1), is("string2")); list = config.get("boolList"); @@ -654,7 +654,7 @@ public void testMetadataPropertyTypes() { assertThat(list, instanceOf(List.class)); values = (List) list; assertThat(values.size(), is(2)); - assertThat(values.get(0), is(false)); + assertThat(values.getFirst(), is(false)); assertThat(values.get(1), is(true)); } diff --git a/itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java b/itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java index 5bb41a7ce25..2d2422951dc 100644 --- a/itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java +++ b/itests/org.openhab.core.model.rule.tests/src/main/java/org/openhab/core/model/rule/runtime/DSLRuleProviderTest.java @@ -117,20 +117,20 @@ public void testSimpleRules() { assertThat(firstRule.getUID(), is("dslruletest-1")); assertThat(firstRule.getName(), is("RuleNumberOne")); - assertThat(firstRule.getTriggers().get(0).getTypeUID(), is(SystemTriggerHandler.STARTLEVEL_MODULE_TYPE_ID)); - assertThat(firstRule.getActions().get(0).getTypeUID(), is(ScriptActionHandler.TYPE_ID)); - assertThat(firstRule.getActions().get(0).getConfiguration().get(AbstractScriptModuleHandler.SCRIPT_TYPE), + assertThat(firstRule.getTriggers().getFirst().getTypeUID(), is(SystemTriggerHandler.STARTLEVEL_MODULE_TYPE_ID)); + assertThat(firstRule.getActions().getFirst().getTypeUID(), is(ScriptActionHandler.TYPE_ID)); + assertThat(firstRule.getActions().getFirst().getConfiguration().get(AbstractScriptModuleHandler.SCRIPT_TYPE), is(DSLScriptEngine.MIMETYPE_OPENHAB_DSL_RULE)); Rule secondRule = it.next(); assertThat(secondRule.getUID(), is("dslruletest-2")); assertThat(secondRule.getName(), is("Rule Number Two")); - assertThat(secondRule.getTriggers().get(0).getTypeUID(), is(ItemStateTriggerHandler.CHANGE_MODULE_TYPE_ID)); - assertThat(secondRule.getTriggers().get(0).getConfiguration().get(ItemStateTriggerHandler.CFG_ITEMNAME), + assertThat(secondRule.getTriggers().getFirst().getTypeUID(), is(ItemStateTriggerHandler.CHANGE_MODULE_TYPE_ID)); + assertThat(secondRule.getTriggers().getFirst().getConfiguration().get(ItemStateTriggerHandler.CFG_ITEMNAME), is("X")); - assertThat(secondRule.getActions().get(0).getTypeUID(), is(ScriptActionHandler.TYPE_ID)); - assertThat(secondRule.getActions().get(0).getConfiguration().get(AbstractScriptModuleHandler.SCRIPT_TYPE), + assertThat(secondRule.getActions().getFirst().getTypeUID(), is(ScriptActionHandler.TYPE_ID)); + assertThat(secondRule.getActions().getFirst().getConfiguration().get(AbstractScriptModuleHandler.SCRIPT_TYPE), is(DSLScriptEngine.MIMETYPE_OPENHAB_DSL_RULE)); } @@ -172,8 +172,8 @@ public void testAllTriggers() { assertThat(rule.getName(), is("RuleWithAllTriggers")); assertThat(rule.getTriggers().size(), is(13)); - assertThat(rule.getTriggers().get(0).getTypeUID(), is(SystemTriggerHandler.STARTLEVEL_MODULE_TYPE_ID)); - assertThat(rule.getTriggers().get(0).getConfiguration().get(SystemTriggerHandler.CFG_STARTLEVEL), + assertThat(rule.getTriggers().getFirst().getTypeUID(), is(SystemTriggerHandler.STARTLEVEL_MODULE_TYPE_ID)); + assertThat(rule.getTriggers().getFirst().getConfiguration().get(SystemTriggerHandler.CFG_STARTLEVEL), is(new BigDecimal(40))); assertThat(rule.getTriggers().get(1).getTypeUID(), is(GenericCronTriggerHandler.MODULE_TYPE_ID)); assertThat(rule.getTriggers().get(1).getConfiguration().get(GenericCronTriggerHandler.CFG_CRON_EXPRESSION), diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericItemChannelLinkProviderTest.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericItemChannelLinkProviderTest.java index 737185b1ac3..5813b157aa5 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericItemChannelLinkProviderTest.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericItemChannelLinkProviderTest.java @@ -100,7 +100,7 @@ public void testThatAnItemChannelLinkWasCreatedForAthingAndAnItem() { List actualItemChannelLinks = new ArrayList<>(itemChannelLinkRegistry.getAll()); assertThat(actualItemChannelLinks.size(), is(1)); - assertThat(actualItemChannelLinks.get(0).toString(), + assertThat(actualItemChannelLinks.getFirst().toString(), is(equalTo("Light3Color -> hue:LCT001:huebridge:bulb3:color"))); }); } @@ -133,7 +133,7 @@ public void testThatMultipleLinksAreCreated() { List actualItemChannelLinks = new ArrayList<>(itemChannelLinkRegistry.getAll()); assertThat(actualItemChannelLinks.size(), is(2)); - assertThat(actualItemChannelLinks.get(0).toString(), + assertThat(actualItemChannelLinks.getFirst().toString(), is(equalTo("Light3Color -> hue:LCT001:huebridge:bulb3:color"))); assertThat(actualItemChannelLinks.get(1).toString(), is(equalTo("Light3Color -> hue:LCT001:huebridge:bulb4:color"))); diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java index c71af12730e..dac73e72bd8 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest.java @@ -219,7 +219,7 @@ public void assertThatTheThingsInAnUpdatedThingsFileIsRegisteredInTheThingRegist assertThat(bulb2, isA(Thing.class)); // channels should be Color as defined in dsl and color_temperature from thingType assertThat(bulb2.getChannels().size(), is(2)); - Channel firstChannel = bulb2.getChannels().get(0); + Channel firstChannel = bulb2.getChannels().getFirst(); assertThat(firstChannel.getUID().toString(), is("hue:LCT001:bulb2:color")); assertThat(firstChannel.getAcceptedItemType(), is(CoreItemFactory.COLOR)); assertThat(bulb2.getBridgeUID(), is(nullValue())); @@ -523,7 +523,7 @@ public void receive(Event event) { waitForAssert(() -> { assertEquals(1, receivedEvents.size()); - Event event = receivedEvents.get(0); + Event event = receivedEvents.getFirst(); assertEquals(ThingUpdatedEvent.class, event.getClass()); ThingUpdatedEvent thingUpdatedEvent = (ThingUpdatedEvent) event; assertEquals("hue:LCT001:my1234Bridge:myKitchenBulb1", thingUpdatedEvent.getThing().UID); diff --git a/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java b/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java index 049a76810c3..a940ed45084 100644 --- a/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java +++ b/itests/org.openhab.core.storage.json.tests/src/main/java/org/openhab/core/storage/json/internal/JsonStorageServiceOSGiTest.java @@ -21,7 +21,6 @@ import java.math.BigDecimal; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Comparator; import java.util.List; import java.util.UUID; @@ -66,13 +65,13 @@ public void tearDown() throws IOException { @AfterAll public static void afterClass() throws IOException { // clean up database files ... - final Path userData = Paths.get(OpenHAB.getUserDataFolder()); + final Path userData = Path.of(OpenHAB.getUserDataFolder()); if (Files.exists(userData)) { try (Stream walk = Files.walk(userData)) { walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); } } - final Path config = Paths.get(OpenHAB.getConfigFolder()); + final Path config = Path.of(OpenHAB.getConfigFolder()); if (Files.exists(config)) { try (Stream walk = Files.walk(config)) { walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/i18n/TranslationProviderOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/i18n/TranslationProviderOSGiTest.java index 940f9b36549..5c5fc08018e 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/i18n/TranslationProviderOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/i18n/TranslationProviderOSGiTest.java @@ -113,7 +113,7 @@ public void assertThatGetTextViaBundleIsWorkingProperly() { text = translationProvider.getText(bundle, KEY_BYE, "default", null); assertTextEquals(text, "default"); - text = translationProvider.getText(bundle, KEY_BYE, "default", new Locale("de", "AT")); + text = translationProvider.getText(bundle, KEY_BYE, "default", Locale.of("de", "AT")); assertTextEquals(text, BYE_DE); text = translationProvider.getText(bundle, KEY_BYE, "default", Locale.ENGLISH); @@ -148,7 +148,7 @@ public void assertThatGetTextWithArgumentsDelegatesProperlyToGetTextWithoutArgum text = translationProvider.getText(bundle, KEY_BYE, "default", null, null, null); assertTextEquals(text, "default"); - text = translationProvider.getText(bundle, KEY_BYE, "default", new Locale("de", "AT"), (Object[]) null); + text = translationProvider.getText(bundle, KEY_BYE, "default", Locale.of("de", "AT"), (Object[]) null); assertTextEquals(text, BYE_DE); text = translationProvider.getText(bundle, KEY_BYE, "default", Locale.ENGLISH, (Object[]) null); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java index f3411aa9a20..361aaff46ee 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/GroupItemOSGiTest.java @@ -136,7 +136,7 @@ public void testItemUpdateWithItemRegistry() { List stateChanges = events.stream().filter(ItemUpdatedEvent.class::isInstance).toList(); assertThat(stateChanges.size(), is(1)); - ItemUpdatedEvent change = (ItemUpdatedEvent) stateChanges.get(0); + ItemUpdatedEvent change = (ItemUpdatedEvent) stateChanges.getFirst(); assertThat(change.getItem().label, is("secondLabel")); } @@ -440,7 +440,7 @@ public void assertThatGroupItemPostsEventsForChangesCorrectly() { List updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).toList(); assertThat(updates.size(), is(1)); - GroupStateUpdatedEvent update = (GroupStateUpdatedEvent) updates.get(0); + GroupStateUpdatedEvent update = (GroupStateUpdatedEvent) updates.getFirst(); assertThat(update.getItemName(), is(groupItem.getName())); assertThat(update.getMemberName(), is(member.getName())); assertThat(update.getTopic(), is(groupitemStateUpdatedEventTopic.replace("{memberName}", member.getName()) @@ -450,7 +450,7 @@ public void assertThatGroupItemPostsEventsForChangesCorrectly() { List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes.size(), is(1)); - GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); + GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.getFirst(); assertThat(change.getItemName(), is(groupItem.getName())); assertThat(change.getMemberName(), is(member.getName())); assertThat(change.getTopic(), is(groupitemStateChangedEventTopic.replace("{memberName}", member.getName()) @@ -463,7 +463,7 @@ public void assertThatGroupItemPostsEventsForChangesCorrectly() { // State doesn't change -> only update event is posted member.setState(member.getState()); waitForAssert(() -> assertThat(events.size(), is(1))); - assertThat(events.get(0), is(instanceOf(ItemStateUpdatedEvent.class))); + assertThat(events.getFirst(), is(instanceOf(ItemStateUpdatedEvent.class))); } @Test @@ -489,7 +489,7 @@ public void assertThatGroupItemChangesRespectGroupFunctionOR() throws Interrupte .toList(); assertThat(groupItemStateChangedEvents, hasSize(1)); - GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) groupItemStateChangedEvents.get(0); + GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) groupItemStateChangedEvents.getFirst(); assertThat(change.getItemName(), is(groupItem.getName())); // we expect that the group should now have status "ON" @@ -563,7 +563,7 @@ public void assertThatGroupItemChangesRespectGroupFunctionORWithUNDEF() throws I List updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).toList(); assertThat(updates, hasSize(1)); - GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); + GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.getFirst(); assertThat(change.getItemName(), is(groupItem.getName())); // we expect that the group should now have status "ON" @@ -615,7 +615,7 @@ public void assertThatGroupItemChangesRespectGroupFunctionAND() { List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes, hasSize(1)); - GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); + GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.getFirst(); assertThat(change.getItemName(), is(groupItem.getName())); // we expect that the group should now have status "OFF" @@ -634,7 +634,7 @@ public void assertThatGroupItemChangesRespectGroupFunctionAND() { changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes, hasSize(1)); - change = (GroupItemStateChangedEvent) changes.get(0); + change = (GroupItemStateChangedEvent) changes.getFirst(); assertThat(change.getItemName(), is(groupItem.getName())); // we expect that the group should now have status "ON" @@ -746,7 +746,7 @@ public void assertThatGroupItemwithDimmeritemAcceptsGetsPercentTypeStateIfMember waitForAssert(() -> assertThat(events.size(), is(2))); List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); - GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); + GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.getFirst(); assertThat(change.getItemName(), is(groupItem.getName())); State newEventState = change.getItemState(); @@ -766,7 +766,7 @@ public void assertThatGroupItemwithDimmeritemAcceptsGetsPercentTypeStateIfMember changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes.size(), is(1)); - change = (GroupItemStateChangedEvent) changes.get(0); + change = (GroupItemStateChangedEvent) changes.getFirst(); assertThat(change.getItemName(), is(groupItem.getName())); newEventState = change.getItemState(); diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java index 30a2e19fb39..d64e3c9403e 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/items/ItemRegistryImplTest.java @@ -118,14 +118,14 @@ public void beforeEach() { public void assertGetItemsReturnsItemFromRegisteredItemProvider() { List items = new ArrayList<>(itemRegistry.getItems()); assertThat(items.size(), is(5)); - assertThat(items.get(0).getName(), is(equalTo(ITEM_NAME))); + assertThat(items.getFirst().getName(), is(equalTo(ITEM_NAME))); } @Test public void assertGetItemsOfTypeReturnsItemFromRegisteredItemProvider() { List items = new ArrayList<>(itemRegistry.getItemsOfType(CoreItemFactory.SWITCH)); assertThat(items.size(), is(3)); - assertThat(items.get(0).getName(), is(equalTo(ITEM_NAME))); + assertThat(items.getFirst().getName(), is(equalTo(ITEM_NAME))); } @Test @@ -166,7 +166,7 @@ public void assertGetItemsByTagAndTypeReturnsItemFromRegistereItemProvider() { public void assertGetItemsByTagWithTwoTagsReturnsItemFromRegisteredItemProvider() { List items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG, SENSOR_TAG)); assertThat(items.size(), is(1)); - assertThat(items.get(0).getName(), is(equalTo(CAMERA_ITEM_NAME2))); + assertThat(items.getFirst().getName(), is(equalTo(CAMERA_ITEM_NAME2))); } @Test @@ -239,7 +239,7 @@ public void testGroupUpdateWithModificationOfLiveInstance() { Item res = itemRegistry.get("item"); assertEquals(1, res.getGroupNames().size()); - assertEquals("group", res.getGroupNames().get(0)); + assertEquals("group", res.getGroupNames().getFirst()); GroupItem group = (GroupItem) itemRegistry.get("group"); assertEquals(1, group.getMembers().size()); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingChannelsTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingChannelsTest.java index 9027829df43..8ff810bd64f 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingChannelsTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/ThingChannelsTest.java @@ -68,7 +68,7 @@ public void testThingChannelOrder() { @Test public void testAutoUpdatePolicyNotSetOnNewChannels() { - Channel channel = ChannelBuilder.create(new ChannelUID(THING_UID, CHANNEL_IDS.get(0)), null).build(); + Channel channel = ChannelBuilder.create(new ChannelUID(THING_UID, CHANNEL_IDS.getFirst()), null).build(); assertNull(channel.getAutoUpdatePolicy()); } } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ChangeThingTypeOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ChangeThingTypeOSGiTest.java index 39210af465a..58ab5224366 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ChangeThingTypeOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ChangeThingTypeOSGiTest.java @@ -272,7 +272,7 @@ public void assertChangingTheThingTypeWorks() { assertThat(thing.getConfiguration().get("parametergeneric"), is("defaultgeneric")); assertThat(thing.getConfiguration().get("providedspecific"), is(nullValue())); assertThat(thing.getChannels().size(), is(1)); - assertThat(thing.getChannels().get(0).getUID(), is(CHANNEL_GENERIC_UID)); + assertThat(thing.getChannels().getFirst().getUID(), is(CHANNEL_GENERIC_UID)); assertThat(thing.getProperties().get("universal"), is("survives")); ThingHandlerFactory handlerFactory = getService(ThingHandlerFactory.class, SampleThingHandlerFactory.class); @@ -391,7 +391,7 @@ private void assertThingWasChanged(Thing thing) { // Ensure that the new set of channels is there assertThat(thing.getChannels().size(), is(1)); - assertThat(thing.getChannels().get(0).getUID().getId(), containsString("specific")); + assertThat(thing.getChannels().getFirst().getUID().getId(), containsString("specific")); // Ensure that the old properties are still there assertThat(thing.getProperties().get("universal"), is("survives")); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ThingFactoryTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ThingFactoryTest.java index df9bb96fa82..9b25908eb4e 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ThingFactoryTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/binding/ThingFactoryTest.java @@ -152,7 +152,7 @@ public void createThingWithDefaultValues() throws Exception { assertThat(thing.getConfiguration().get("testProperty"), is(not(nullValue()))); assertThat(thing.getConfiguration().get("testProperty"), is(equalTo("default"))); assertThat(thing.getChannels().size(), is(equalTo(2))); - assertThat(thing.getChannels().get(0).getConfiguration().get("testProperty"), is(equalTo("default"))); + assertThat(thing.getChannels().getFirst().getConfiguration().get("testProperty"), is(equalTo("default"))); assertThat(thing.getChannels().get(1).getConfiguration().get("testProperty"), is(equalTo("default"))); assertThat(thing.getProperties().size(), is(0)); } @@ -214,10 +214,9 @@ public void createThingWithDifferentDefaultValueTypes() throws Exception { assertThat(thing.getConfiguration().get("p4"), is(nullValue())); assertThat(thing.getConfiguration().get("p5"), is(instanceOf(List.class))); assertThat(((List) thing.getConfiguration().get("p5")).size(), is(1)); - assertThat(((List) thing.getConfiguration().get("p5")).get(0), is(instanceOf(BigDecimal.class))); - assertThat( - ((BigDecimal) ((List) thing.getConfiguration().get("p5")).get(0)).compareTo(new BigDecimal("2.3")), - is(0)); + assertThat(((List) thing.getConfiguration().get("p5")).getFirst(), is(instanceOf(BigDecimal.class))); + assertThat(((BigDecimal) ((List) thing.getConfiguration().get("p5")).getFirst()) + .compareTo(new BigDecimal("2.3")), is(0)); assertThat(thing.getConfiguration().get("p6"), is(instanceOf(List.class))); assertThat(((List) thing.getConfiguration().get("p6")).size(), is(3)); assertThat(thing.getProperties().size(), is(0)); @@ -246,11 +245,11 @@ public void createThingWithChannels() { Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration); assertThat(thing.getChannels().size(), is(2)); - assertThat(thing.getChannels().get(0).getUID().toString(), is(equalTo("bindingId:thingType:thingId:ch1"))); - assertThat(thing.getChannels().get(0).getAcceptedItemType(), is(equalTo(CoreItemFactory.COLOR))); - assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag1"), is(true)); - assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag2"), is(true)); - assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag3"), is(false)); + assertThat(thing.getChannels().getFirst().getUID().toString(), is(equalTo("bindingId:thingType:thingId:ch1"))); + assertThat(thing.getChannels().getFirst().getAcceptedItemType(), is(equalTo(CoreItemFactory.COLOR))); + assertThat(thing.getChannels().getFirst().getDefaultTags().contains("tag1"), is(true)); + assertThat(thing.getChannels().getFirst().getDefaultTags().contains("tag2"), is(true)); + assertThat(thing.getChannels().getFirst().getDefaultTags().contains("tag3"), is(false)); assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag1"), is(false)); assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag2"), is(false)); assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag3"), is(true)); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProviderOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProviderOSGiTest.java index 864d240e861..3528395c80a 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProviderOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelCommandDescriptionProviderOSGiTest.java @@ -233,7 +233,7 @@ public void presentItemCommandDescription() throws ItemNotFoundException { List opts = command.getCommandOptions(); assertNotNull(opts); assertEquals(1, opts.size()); - final CommandOption opt0 = opts.get(0); + final CommandOption opt0 = opts.getFirst(); assertNotNull(opt0); assertEquals("SOUND", opt0.getCommand()); assertEquals("My great sound.", opt0.getLabel()); @@ -247,7 +247,7 @@ public void presentItemCommandDescription() throws ItemNotFoundException { opts = command.getCommandOptions(); assertNotNull(opts); assertEquals(1, opts.size()); - final CommandOption opt1 = opts.get(0); + final CommandOption opt1 = opts.getFirst(); assertNotNull(opt1); assertEquals("COMMAND", opt1.getCommand()); assertEquals("My command.", opt1.getLabel()); @@ -261,7 +261,7 @@ public void presentItemCommandDescription() throws ItemNotFoundException { opts = command.getCommandOptions(); assertNotNull(opts); assertEquals(1, opts.size()); - final CommandOption opt2 = opts.get(0); + final CommandOption opt2 = opts.getFirst(); assertEquals("NEW COMMAND", opt2.getCommand()); assertEquals("My new command.", opt2.getLabel()); } @@ -294,7 +294,7 @@ public void wrongItemCommandDescription() throws ItemNotFoundException { List opts = command.getCommandOptions(); assertNotNull(opts); assertEquals(1, opts.size()); - final CommandOption opt2 = opts.get(0); + final CommandOption opt2 = opts.getFirst(); assertEquals("NEW COMMAND", opt2.getCommand()); assertEquals("My new command.", opt2.getLabel()); } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java index 43617386aec..94eac6b5e19 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelLinkNotifierOSGiTest.java @@ -162,7 +162,7 @@ public List getChannelLinkEvents(ChannelUID channelUID) { public @Nullable Boolean isLinkedBasedOnEvent(ChannelUID channelUID) { List events = getChannelLinkEvents(channelUID); - return events.isEmpty() ? null : events.get(events.size() - 1); + return events.isEmpty() ? null : events.getLast(); } public void resetChannelLinkEvents() { diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java index 8a33cc4dce8..428bc7a7c82 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java @@ -276,7 +276,7 @@ public void presentItemStateDescription() throws ItemNotFoundException { assertTrue(state.isReadOnly()); List opts = state.getOptions(); assertEquals(1, opts.size()); - final StateOption opt = opts.get(0); + final StateOption opt = opts.getFirst(); assertEquals("SOUND", opt.getValue()); assertEquals("My great sound.", opt.getLabel()); @@ -341,7 +341,7 @@ public void presentItemStateDescription() throws ItemNotFoundException { opts = state.getOptions(); assertNotNull(opts); assertEquals(2, opts.size()); - final StateOption opt0 = opts.get(0); + final StateOption opt0 = opts.getFirst(); assertNotNull(opt0); assertEquals("value0", opt0.getValue()); assertEquals("label0", opt0.getLabel()); @@ -365,7 +365,7 @@ public void presentItemStateDescription() throws ItemNotFoundException { opts = state.getOptions(); assertNotNull(opts); assertEquals(1, opts.size()); - final StateOption opt2 = opts.get(0); + final StateOption opt2 = opts.getFirst(); assertEquals("NEW SOUND", opt2.getValue()); assertEquals("My great new sound.", opt2.getLabel()); } @@ -406,7 +406,7 @@ public void wrongItemStateDescription() throws ItemNotFoundException { List opts = state.getOptions(); assertNotNull(opts); assertEquals(1, opts.size()); - final StateOption opt2 = opts.get(0); + final StateOption opt2 = opts.getFirst(); assertEquals("NEW SOUND", opt2.getValue()); assertEquals("My great new sound.", opt2.getLabel()); } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java index 1bb653e616d..19d7b50ca1e 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java @@ -353,8 +353,8 @@ public void testCreateChannelGroupBuilder() throws Exception { assertNotNull(channelBuilders); assertEquals(2, channelBuilders.size()); - assertNotNull(channelBuilders.get(0)); - validateChannel(channelBuilders.get(0).build()); + assertNotNull(channelBuilders.getFirst()); + validateChannel(channelBuilders.getFirst().build()); assertNotNull(channelBuilders.get(1)); validateChannelOverridden(channelBuilders.get(1).build()); } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java index a141e1793b3..f259801034d 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiTest.java @@ -920,8 +920,8 @@ public Set getSubscribedEventTypes() { // thing manager posts the update to the event bus via EventPublisher state.callback.stateUpdated(CHANNEL_UID, new StringType("Value")); waitForAssert(() -> assertThat(receivedEvents.size(), is(1))); - assertThat(receivedEvents.get(0), is(instanceOf(ItemStateEvent.class))); - ItemStateEvent itemUpdateEvent = (ItemStateEvent) receivedEvents.get(0); + assertThat(receivedEvents.getFirst(), is(instanceOf(ItemStateEvent.class))); + ItemStateEvent itemUpdateEvent = (ItemStateEvent) receivedEvents.getFirst(); assertThat(itemUpdateEvent.getTopic(), is("openhab/items/name/state")); assertThat(itemUpdateEvent.getItemName(), is(itemName)); assertThat(itemUpdateEvent.getSource(), is(CHANNEL_UID.toString())); @@ -936,8 +936,8 @@ public Set getSubscribedEventTypes() { state.callback.stateUpdated(CHANNEL_UID, new StringType("Value")); waitForAssert(() -> assertThat(receivedEvents.size(), is(1))); - assertThat(receivedEvents.get(0), is(instanceOf(ItemStateEvent.class))); - itemUpdateEvent = (ItemStateEvent) receivedEvents.get(0); + assertThat(receivedEvents.getFirst(), is(instanceOf(ItemStateEvent.class))); + itemUpdateEvent = (ItemStateEvent) receivedEvents.getFirst(); assertThat(itemUpdateEvent.getTopic(), is("openhab/items/name/state")); assertThat(itemUpdateEvent.getItemName(), is(itemName)); assertThat(itemUpdateEvent.getSource(), is(CHANNEL_UID.toString())); @@ -1279,7 +1279,7 @@ public void receive(Event event) { managedThingProvider.add(thing); waitForAssert(() -> assertThat(receivedEvents.size(), is(2))); - assertThat(receivedEvents.get(0), is(equalTo(event))); + assertThat(receivedEvents.getFirst(), is(equalTo(event))); assertThat(receivedEvents.get(1), is(equalTo(event1))); receivedEvents.clear(); @@ -1289,7 +1289,7 @@ public void receive(Event event) { state.callback.statusUpdated(thing, onlineNone); waitForAssert(() -> assertThat(receivedEvents.size(), is(1))); - assertThat(receivedEvents.get(0), is(equalTo(event))); + assertThat(receivedEvents.getFirst(), is(equalTo(event))); receivedEvents.clear(); // set status to OFFLINE @@ -1299,7 +1299,7 @@ public void receive(Event event) { state.callback.statusUpdated(thing, offlineCommError); waitForAssert(() -> assertThat(receivedEvents.size(), is(1))); - assertThat(receivedEvents.get(0), is(equalTo(event))); + assertThat(receivedEvents.getFirst(), is(equalTo(event))); receivedEvents.clear(); // set status to UNINITIALIZED @@ -1361,10 +1361,10 @@ public void receive(Event event) { managedThingProvider.add(thing); waitForAssert(() -> assertThat(infoChangedEvents.size(), is(1))); - assertThat(infoChangedEvents.get(0).getType(), is(ThingStatusInfoChangedEvent.TYPE)); - assertThat(infoChangedEvents.get(0).getTopic(), is("openhab/things/binding:type:id/statuschanged")); - assertThat(infoChangedEvents.get(0).getStatusInfo().getStatus(), is(ThingStatus.INITIALIZING)); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getStatus(), is(ThingStatus.UNINITIALIZED)); + assertThat(infoChangedEvents.getFirst().getType(), is(ThingStatusInfoChangedEvent.TYPE)); + assertThat(infoChangedEvents.getFirst().getTopic(), is("openhab/things/binding:type:id/statuschanged")); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getStatus(), is(ThingStatus.INITIALIZING)); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getStatus(), is(ThingStatus.UNINITIALIZED)); infoChangedEvents.clear(); // set status to ONLINE (INITIALIZING -> ONLINE) @@ -1372,10 +1372,10 @@ public void receive(Event event) { state.callback.statusUpdated(thing, onlineNone); waitForAssert(() -> assertThat(infoChangedEvents.size(), is(1))); - assertThat(infoChangedEvents.get(0).getType(), is(ThingStatusInfoChangedEvent.TYPE)); - assertThat(infoChangedEvents.get(0).getTopic(), is("openhab/things/binding:type:id/statuschanged")); - assertThat(infoChangedEvents.get(0).getStatusInfo().getStatus(), is(ThingStatus.ONLINE)); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getStatus(), is(ThingStatus.INITIALIZING)); + assertThat(infoChangedEvents.getFirst().getType(), is(ThingStatusInfoChangedEvent.TYPE)); + assertThat(infoChangedEvents.getFirst().getTopic(), is("openhab/things/binding:type:id/statuschanged")); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getStatus(), is(ThingStatus.ONLINE)); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getStatus(), is(ThingStatus.INITIALIZING)); infoChangedEvents.clear(); // set status to ONLINE again @@ -1458,11 +1458,11 @@ public void receive(Event event) { assertThat(infoChangedEvents.size(), is(1)); }); - assertThat(infoEvents.get(0).getType(), is(ThingStatusInfoEvent.TYPE)); - assertThat(infoEvents.get(0).getTopic(), is("openhab/things/binding:type:id/status")); - assertThat(infoEvents.get(0).getStatusInfo().getStatus(), is(ThingStatus.UNINITIALIZED)); - assertThat(infoEvents.get(0).getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoEvents.get(0).getStatusInfo().getDescription(), is(nullValue())); + assertThat(infoEvents.getFirst().getType(), is(ThingStatusInfoEvent.TYPE)); + assertThat(infoEvents.getFirst().getTopic(), is("openhab/things/binding:type:id/status")); + assertThat(infoEvents.getFirst().getStatusInfo().getStatus(), is(ThingStatus.UNINITIALIZED)); + assertThat(infoEvents.getFirst().getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoEvents.getFirst().getStatusInfo().getDescription(), is(nullValue())); assertThat(infoEvents.get(1).getType(), is(ThingStatusInfoEvent.TYPE)); assertThat(infoEvents.get(1).getTopic(), is("openhab/things/binding:type:id/status")); @@ -1470,14 +1470,14 @@ public void receive(Event event) { assertThat(infoEvents.get(1).getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); assertThat(infoEvents.get(1).getStatusInfo().getDescription(), is(nullValue())); - assertThat(infoChangedEvents.get(0).getType(), is(ThingStatusInfoChangedEvent.TYPE)); - assertThat(infoChangedEvents.get(0).getTopic(), is("openhab/things/binding:type:id/statuschanged")); - assertThat(infoChangedEvents.get(0).getStatusInfo().getStatus(), is(ThingStatus.INITIALIZING)); - assertThat(infoChangedEvents.get(0).getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoChangedEvents.get(0).getStatusInfo().getDescription(), is(nullValue())); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getStatus(), is(ThingStatus.UNINITIALIZED)); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getDescription(), is(nullValue())); + assertThat(infoChangedEvents.getFirst().getType(), is(ThingStatusInfoChangedEvent.TYPE)); + assertThat(infoChangedEvents.getFirst().getTopic(), is("openhab/things/binding:type:id/statuschanged")); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getStatus(), is(ThingStatus.INITIALIZING)); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getDescription(), is(nullValue())); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getStatus(), is(ThingStatus.UNINITIALIZED)); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getDescription(), is(nullValue())); infoEvents.clear(); infoChangedEvents.clear(); @@ -1499,20 +1499,20 @@ public void receive(Event event) { assertThat(infoChangedEvents.size(), is(1)); }); - assertThat(infoEvents.get(0).getType(), is(ThingStatusInfoEvent.TYPE)); - assertThat(infoEvents.get(0).getTopic(), is("openhab/things/binding:type:id/status")); - assertThat(infoEvents.get(0).getStatusInfo().getStatus(), is(ThingStatus.ONLINE)); - assertThat(infoEvents.get(0).getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoEvents.get(0).getStatusInfo().getDescription(), is("Thing is online.")); - - assertThat(infoChangedEvents.get(0).getType(), is(ThingStatusInfoChangedEvent.TYPE)); - assertThat(infoChangedEvents.get(0).getTopic(), is("openhab/things/binding:type:id/statuschanged")); - assertThat(infoChangedEvents.get(0).getStatusInfo().getStatus(), is(ThingStatus.ONLINE)); - assertThat(infoChangedEvents.get(0).getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoChangedEvents.get(0).getStatusInfo().getDescription(), is("Thing is online.")); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getStatus(), is(ThingStatus.INITIALIZING)); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getDescription(), is(nullValue())); + assertThat(infoEvents.getFirst().getType(), is(ThingStatusInfoEvent.TYPE)); + assertThat(infoEvents.getFirst().getTopic(), is("openhab/things/binding:type:id/status")); + assertThat(infoEvents.getFirst().getStatusInfo().getStatus(), is(ThingStatus.ONLINE)); + assertThat(infoEvents.getFirst().getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoEvents.getFirst().getStatusInfo().getDescription(), is("Thing is online.")); + + assertThat(infoChangedEvents.getFirst().getType(), is(ThingStatusInfoChangedEvent.TYPE)); + assertThat(infoChangedEvents.getFirst().getTopic(), is("openhab/things/binding:type:id/statuschanged")); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getStatus(), is(ThingStatus.ONLINE)); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getDescription(), is("Thing is online.")); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getStatus(), is(ThingStatus.INITIALIZING)); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getDescription(), is(nullValue())); infoEvents.clear(); infoChangedEvents.clear(); @@ -1530,20 +1530,20 @@ public void receive(Event event) { assertThat(infoChangedEvents.size(), is(1)); }); - assertThat(infoEvents.get(0).getType(), is(ThingStatusInfoEvent.TYPE)); - assertThat(infoEvents.get(0).getTopic(), is("openhab/things/binding:type:id/status")); - assertThat(infoEvents.get(0).getStatusInfo().getStatus(), is(ThingStatus.OFFLINE)); - assertThat(infoEvents.get(0).getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoEvents.get(0).getStatusInfo().getDescription(), is("Thing ist offline.")); - - assertThat(infoChangedEvents.get(0).getType(), is(ThingStatusInfoChangedEvent.TYPE)); - assertThat(infoChangedEvents.get(0).getTopic(), is("openhab/things/binding:type:id/statuschanged")); - assertThat(infoChangedEvents.get(0).getStatusInfo().getStatus(), is(ThingStatus.OFFLINE)); - assertThat(infoChangedEvents.get(0).getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoChangedEvents.get(0).getStatusInfo().getDescription(), is("Thing ist offline.")); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getStatus(), is(ThingStatus.ONLINE)); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); - assertThat(infoChangedEvents.get(0).getOldStatusInfo().getDescription(), is("Thing ist online.")); + assertThat(infoEvents.getFirst().getType(), is(ThingStatusInfoEvent.TYPE)); + assertThat(infoEvents.getFirst().getTopic(), is("openhab/things/binding:type:id/status")); + assertThat(infoEvents.getFirst().getStatusInfo().getStatus(), is(ThingStatus.OFFLINE)); + assertThat(infoEvents.getFirst().getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoEvents.getFirst().getStatusInfo().getDescription(), is("Thing ist offline.")); + + assertThat(infoChangedEvents.getFirst().getType(), is(ThingStatusInfoChangedEvent.TYPE)); + assertThat(infoChangedEvents.getFirst().getTopic(), is("openhab/things/binding:type:id/statuschanged")); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getStatus(), is(ThingStatus.OFFLINE)); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoChangedEvents.getFirst().getStatusInfo().getDescription(), is("Thing ist offline.")); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getStatus(), is(ThingStatus.ONLINE)); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getStatusDetail(), is(ThingStatusDetail.NONE)); + assertThat(infoChangedEvents.getFirst().getOldStatusInfo().getDescription(), is("Thing ist online.")); new DefaultLocaleSetter(configurationAdmin).setDefaultLocale(defaultLocale); waitForAssert(() -> assertThat(localeProvider.getLocale(), is(defaultLocale))); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java index 1d5fd4b865f..c3b37013ea2 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareUpdateServiceTest.java @@ -194,7 +194,7 @@ public void testGetFirmwareStatusInfo() { // verify that the corresponding events are sent ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, times(3)).post(eventCaptor.capture()); - assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112); + assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().getFirst(), updateExecutableInfoFw112); assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo); assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(2), unknownInfo); } @@ -232,7 +232,7 @@ public void testGetFirmwareStatusInfoFirmwareProviderAddedLate() { // verify that the corresponding events are sent ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, times(2)).post(eventCaptor.capture()); - assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(0), unknownInfo); + assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().getFirst(), unknownInfo); assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(1), upToDateInfo); } @@ -246,7 +246,7 @@ public void testGetFirmwareStatusInfoEventsOnlySentOnce() { // verify that the corresponding events are sent ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, times(1)).post(eventCaptor.capture()); - assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112); + assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().getFirst(), updateExecutableInfoFw112); } @Test @@ -263,7 +263,7 @@ public void firmwareStatusPropagatedRegularly() throws Exception { waitForAssert(() -> { ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, times(3)).post(eventCaptor.capture()); - assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112); + assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().getFirst(), updateExecutableInfoFw112); assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo); assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(2), unknownInfo); @@ -288,7 +288,7 @@ public void firmwareStatusPropagatedRegularly() throws Exception { verify(eventPublisherMock, times(2)).post(eventCaptor.capture()); FirmwareStatusInfo updateExecutableInfoFw113 = createUpdateExecutableInfo(thing1.getUID(), V113); - assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw113); + assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().getFirst(), updateExecutableInfoFw113); updateExecutableInfoFw113 = createUpdateExecutableInfo(thing2.getUID(), V113); assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw113); @@ -302,7 +302,7 @@ public void firmwareStatusPropagatedRegularly() throws Exception { waitForAssert(() -> { ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, times(2)).post(eventCaptor.capture()); - assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112); + assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().getFirst(), updateExecutableInfoFw112); assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), upToDateInfo); }); } @@ -325,7 +325,7 @@ public void testUpdateFirmware() { // verify that the corresponding events are sent ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, times(2)).post(eventCaptor.capture()); - assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(0), updateExecutableInfoFw112); + assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().getFirst(), updateExecutableInfoFw112); assertFirmwareStatusInfoEvent(THING1_UID, eventCaptor.getAllValues().get(1), upToDateInfo); } @@ -468,7 +468,7 @@ public void testUpdateFirmwareDowngrade() { // verify that the corresponding events are sent ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, times(2)).post(eventCaptor.capture()); - assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(0), upToDateInfo); + assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().getFirst(), upToDateInfo); assertFirmwareStatusInfoEvent(THING2_UID, eventCaptor.getAllValues().get(1), updateExecutableInfoFw112); } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/update/ThingUpdateOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/update/ThingUpdateOSGiTest.java index 176a2493430..74c5a90ffb0 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/update/ThingUpdateOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/update/ThingUpdateOSGiTest.java @@ -285,11 +285,11 @@ public void testSingleChannelAdditionGroup() { List channels1 = updatedThing.getChannelsOfGroup("group1"); assertThat(channels1, hasSize(1)); - assertChannel(channels1.get(0), channelTypeUID, "Switch", "typeLabel", null); + assertChannel(channels1.getFirst(), channelTypeUID, "Switch", "typeLabel", null); List channels2 = updatedThing.getChannelsOfGroup("group2"); assertThat(channels2, hasSize(1)); - assertChannel(channels2.get(0), channelTypeUID, "Switch", "typeLabel", null); + assertChannel(channels2.getFirst(), channelTypeUID, "Switch", "typeLabel", null); } @Test diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesI18nTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesI18nTest.java index c1c69228406..d93ef675802 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesI18nTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ChannelTypesI18nTest.java @@ -78,7 +78,7 @@ public void channelTypesShouldTranslateCorrectly() throws Exception { assertThat(channelType1, is(not(nullValue()))); assertThat(channelType1.getLabel(), is(equalTo("Channel Label"))); assertThat(channelType1.getDescription(), is(equalTo("Channel Description"))); - assertThat(channelType1.getCommandDescription().getCommandOptions().get(0).getLabel(), + assertThat(channelType1.getCommandDescription().getCommandOptions().getFirst().getLabel(), is(equalTo("Short Alarm"))); assertThat(channelType1.getCommandDescription().getCommandOptions().get(1).getLabel(), is(equalTo("Long Alarm"))); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypeI18nTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypeI18nTest.java index 178add681d1..5fa8d7aba55 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypeI18nTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypeI18nTest.java @@ -85,7 +85,7 @@ public void channelGroupTypeShouldBeLocalized() throws Exception { assertNotNull(weatherGroupType); ChannelGroupType channelGroupType = channelGroupTypeRegistry.getChannelGroupType( - weatherGroupType.getChannelGroupDefinitions().get(0).getTypeUID(), Locale.GERMAN); + weatherGroupType.getChannelGroupDefinitions().getFirst().getTypeUID(), Locale.GERMAN); assertNotNull(channelGroupType); assertThat(channelGroupType.getLabel(), is("Wetterinformation mit Gruppe")); @@ -186,7 +186,7 @@ public void channelTypeShouldBeLocalized() throws Exception { assertThat(temperatureChannelType.getDescription(), is("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).")); assertThat(temperatureChannelType.getState().getPattern(), is("%d Grad Celsius")); - assertThat(temperatureChannelType.getState().getOptions().get(0).getLabel(), is("Mein String")); + assertThat(temperatureChannelType.getState().getOptions().getFirst().getLabel(), is("Mein String")); } } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypesTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypesTest.java index 67d385156ed..3565e97b6b0 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypesTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/ThingTypesTest.java @@ -91,7 +91,7 @@ public void thingTypesShouldLoad() throws Exception { assertThat(thingType.getLabel(), is("HUE Lamp")); assertThat(thingType.getDescription(), is("My own great HUE Lamp.")); assertThat(thingType.getSupportedBridgeTypeUIDs().size(), is(1)); - assertThat(thingType.getSupportedBridgeTypeUIDs().get(0), is("hue:bridge")); + assertThat(thingType.getSupportedBridgeTypeUIDs().getFirst(), is("hue:bridge")); assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("alarm", "brightness")); assertThat(thingType.getProperties().size(), is(2)); assertThat(thingType.getProperties().get("key1"), is("value1")); @@ -172,8 +172,8 @@ public void thingTypesShouldLoad() throws Exception { assertThat(state.getPattern(), is(equalTo("%d Peek"))); assertThat(state.isReadOnly(), is(true)); assertThat(state.getOptions().size(), is(2)); - assertThat(state.getOptions().get(0).getValue(), is(equalTo("SOUND"))); - assertThat(state.getOptions().get(0).getLabel(), is(equalTo("My great sound."))); + assertThat(state.getOptions().getFirst().getValue(), is(equalTo("SOUND"))); + assertThat(state.getOptions().getFirst().getLabel(), is(equalTo("My great sound."))); // HUE Lamp with group thingType = thingTypes.stream().filter(it -> "hue:lamp-with-group".equals(it.toString())).findFirst().get(); diff --git a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/Translations.java b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/Translations.java index 4f6ed4593de..65ff017a72c 100644 --- a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/Translations.java +++ b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/Translations.java @@ -72,7 +72,7 @@ public int compareTo(TranslationsGroup other) { return 1; } - return entries.get(0).getKey().compareTo(other.entries.get(0).getKey()); + return entries.getFirst().getKey().compareTo(other.entries.getFirst().getKey()); } public boolean hasTranslations() { diff --git a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/XmlToTranslationsConverter.java b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/XmlToTranslationsConverter.java index a638dd2a449..b5bb73d4317 100644 --- a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/XmlToTranslationsConverter.java +++ b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/XmlToTranslationsConverter.java @@ -191,8 +191,7 @@ private TranslationsSection thingTypesConfigSection(BundleInfo bundleInfo) { .map(ThingType::getConfigDescriptionURI) // .distinct() // .map(bundleInfo::getConfigDescription) // - .filter(Optional::isPresent) // - .map(Optional::get)); + .flatMap(Optional::stream)); Builder groupsBuilder = Stream.builder(); @@ -314,8 +313,7 @@ private TranslationsSection channelTypesConfigSection(BundleInfo bundleInfo) { .map(ChannelType::getConfigDescriptionURI) // .distinct() // .map(bundleInfo::getConfigDescription) // - .filter(Optional::isPresent) // - .map(Optional::get)); + .flatMap(Optional::stream)); Builder groupsBuilder = Stream.builder();