From 09b3160a55b39e416e1c6ee3bd92eef7761fe81b Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Mon, 9 Oct 2023 09:20:08 +0200 Subject: [PATCH] Simplify code using Stream.toList (#3831) Stream.toList was introduced in Java 16 and creates an unmodifiable List so it can be used to simplify code whenever the List is not expected to be modified. Signed-off-by: Wouter Born --- .../community/CommunityKarafAddonHandler.java | 3 +- .../AbstractRemoteAddonService.java | 3 +- .../CommunityMarketplaceAddonService.java | 3 +- .../SerializedNameAnnotationIntrospector.java | 3 +- .../internal/json/JsonAddonService.java | 4 +- .../marketplace/test/TestAddonService.java | 3 +- .../core/audio/internal/AudioManagerImpl.java | 5 +- .../core/audio/internal/AudioServlet.java | 5 +- .../internal/MediaActionTypeProvider.java | 3 +- .../script/ScriptTransformationService.java | 3 +- .../rest/internal/RuleResource.java | 3 +- .../rest/internal/TemplateResource.java | 3 +- .../AbstractResourceBundleProvider.java | 3 +- .../internal/ruleengine/WrappedRule.java | 6 +- .../openhab/core/config/core/ConfigUtil.java | 10 +- .../i18n/I18nConfigOptionsProvider.java | 5 +- .../net/NetworkConfigOptionProvider.java | 7 +- .../config/core/status/ConfigStatusInfo.java | 3 +- .../normalization/NormalizerTest.java | 16 ++- .../internal/AutomaticInboxProcessor.java | 6 +- .../discovery/internal/PersistentInbox.java | 7 +- .../console/InboxConsoleCommandExtension.java | 15 +-- .../discovery/inbox/InboxPredicatesTest.java | 81 ++++++------- .../internal/AutomaticInboxProcessorTest.java | 54 ++++----- .../dispatch/internal/ConfigDispatcher.java | 11 +- .../internal/SerialConfigOptionProvider.java | 3 +- .../SerialConfigOptionProviderTest.java | 3 +- .../internal/EphemerisManagerImpl.java | 3 +- .../ItemConsoleCommandCompleter.java | 8 +- .../ItemConsoleCommandExtension.java | 5 +- .../ExtensibleTrustManagerImplTest.java | 3 +- ...EnrichedConfigDescriptionParameterDTO.java | 6 +- .../rest/core/internal/item/ItemResource.java | 2 +- .../link/ItemChannelLinkResource.java | 8 +- .../service/ConfigurableServiceResource.java | 3 +- .../io/rest/voice/internal/VoiceResource.java | 5 +- .../core/io/rest/internal/DTOMapperImpl.java | 3 +- .../modbus/internal/ModbusLibraryWrapper.java | 5 +- ...UtilitiesExtractIndividualMethodsTest.java | 3 +- ...tilitiesExtractStateFromRegistersTest.java | 6 +- .../test/BitUtilitiesExtractStringTest.java | 7 +- .../test/WriteRequestJsonUtilitiesTest.java | 10 +- .../serial/internal/SerialPortRegistry.java | 3 +- .../console/SerialCommandExtension.java | 6 +- .../core/karaf/internal/FeatureInstaller.java | 3 +- .../core/karaf/internal/LoggerBean.java | 4 +- .../jaas/ManagedUserBackingEngine.java | 5 +- .../core/internal/ModelRepositoryImpl.java | 2 +- .../internal/engine/ScriptEngineImpl.java | 3 +- .../core/model/script/actions/BusEvent.java | 5 +- .../GenericItemChannelLinkProvider.java | 3 +- .../internal/PersistenceManager.java | 4 +- .../metadata/MagicMetadataProvider.java | 9 +- .../internal/java/MissingServiceAnalyzer.java | 6 +- .../openhab/core/test/java/JavaOSGiTest.java | 9 +- .../AbstractStorageBasedTypeProvider.java | 3 +- .../AutoUpdateConfigDescriptionProvider.java | 4 +- .../firmware/FirmwareRegistryImpl.java | 5 +- ...mChannelLinkConfigDescriptionProvider.java | 4 +- .../profiles/SystemProfileFactory.java | 5 +- .../xml/internal/ThingTypeConverter.java | 4 +- .../core/thing/util/ThingHelperTest.java | 10 +- .../AbstractFileTransformationService.java | 4 +- .../internal/TransformationRegistryImpl.java | 3 +- .../core/voice/internal/DialogProcessor.java | 5 +- .../VoiceConsoleCommandExtension.java | 2 +- .../core/voice/internal/VoiceManagerImpl.java | 25 ++-- .../openhab/core/voice/text/TokenList.java | 4 +- .../registry/AbstractManagedProvider.java | 4 +- .../core/internal/items/ItemRegistryImpl.java | 8 +- ...adataStateDescriptionFragmentProvider.java | 3 +- .../org/openhab/core/items/GenericItem.java | 2 +- .../openhab/core/library/types/HSBType.java | 3 +- .../openhab/core/library/types/PointType.java | 3 +- .../core/library/types/StringListType.java | 4 +- .../java/org/openhab/core/net/NetUtil.java | 16 +-- .../cache/lru/LRUMediaCacheEntryTest.java | 3 +- .../test/AutomationIntegrationTest.java | 2 +- .../integration/test/RuleSimulationTest.java | 3 +- .../core/automation/event/RuleEventTest.java | 3 +- .../automation/internal/RuleRegistryTest.java | 112 +++++++----------- .../discovery/internal/InboxOSGiTest.java | 8 +- .../profile/ProfileTypeResourceTest.java | 11 +- .../test/hue/GenericThingProviderTest3.java | 3 +- .../openhab/core/items/GroupItemOSGiTest.java | 37 +++--- .../core/items/ItemRegistryImplTest.java | 9 +- .../core/thing/binding/ThingFactoryTest.java | 4 +- .../internal/ChannelLinkNotifierOSGiTest.java | 2 +- .../CommunicationManagerOSGiTest.java | 5 +- .../firmware/FirmwareUpdateServiceTest.java | 5 +- .../thing/link/ItemChannelLinkOSGiTest.java | 5 +- .../SystemChannelsInChannelGroupsTest.java | 17 +-- .../tools/i18n/plugin/BundleInfoReader.java | 5 +- 93 files changed, 294 insertions(+), 471 deletions(-) diff --git a/bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java b/bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java index 6dc61c0ef..04f0f490b 100644 --- a/bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java +++ b/bundles/org.openhab.core.addon.marketplace.karaf/src/main/java/org/openhab/core/addon/marketplace/karaf/internal/community/CommunityKarafAddonHandler.java @@ -25,7 +25,6 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.List; import java.util.concurrent.ScheduledExecutorService; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.karaf.kar.KarService; @@ -123,7 +122,7 @@ public class CommunityKarafAddonHandler implements MarketplaceAddonHandler { try { Path addonPath = getAddonCacheDirectory(addon.getUid()); List repositories = karService.list(); - for (Path path : karFilesStream(addonPath).collect(Collectors.toList())) { + for (Path path : karFilesStream(addonPath).toList()) { String karRepoName = pathToKarRepoName(path); if (repositories.contains(karRepoName)) { karService.uninstall(karRepoName); diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java index 95f4b79f9..4aa5f4dc7 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java @@ -23,7 +23,6 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -117,7 +116,7 @@ public abstract class AbstractRemoteAddonService implements AddonService { } // create lookup list to make sure installed addons take precedence - List installedAddons = addons.stream().map(Addon::getUid).collect(Collectors.toList()); + List installedAddons = addons.stream().map(Addon::getUid).toList(); if (remoteEnabled()) { List remoteAddons = Objects.requireNonNullElse(cachedRemoteAddons.getValue(), List.of()); diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java index 69104bec7..f1224b2d0 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java @@ -30,7 +30,6 @@ import java.util.Objects; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -188,7 +187,7 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService } } - List users = pages.stream().flatMap(p -> Stream.of(p.users)).collect(Collectors.toList()); + List users = pages.stream().flatMap(p -> Stream.of(p.users)).toList(); pages.stream().flatMap(p -> Stream.of(p.topicList.topics)) .filter(t -> showUnpublished || Arrays.asList(t.tags).contains(PUBLISHED_TAG)) .map(t -> Optional.ofNullable(convertTopicItemToAddon(t, users))) 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 5e32f55a2..fb55deabd 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 @@ -14,7 +14,6 @@ package org.openhab.core.addon.marketplace.internal.community; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -46,7 +45,7 @@ final class SerializedNameAnnotationIntrospector extends AnnotationIntrospector @NonNullByDefault({}) public List findPropertyAliases(Annotated annotated) { return Optional.ofNullable(annotated.getAnnotation(SerializedName.class)) - .map(s -> Stream.of(s.alternate()).map(PropertyName::new).collect(Collectors.toList())) + .map(s -> Stream.of(s.alternate()).map(PropertyName::new).toList()) .orElseGet(() -> super.findPropertyAliases(annotated)); } diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/json/JsonAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/json/JsonAddonService.java index f349e242a..362f5311e 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/json/JsonAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/json/JsonAddonService.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -133,8 +132,7 @@ public class JsonAddonService extends AbstractRemoteAddonService { return List.of(); } }).flatMap(List::stream).filter(Objects::nonNull).map(e -> (AddonEntryDTO) e) - .filter(e -> showUnstable || "stable".equals(e.maturity)).map(this::fromAddonEntry) - .collect(Collectors.toList()); + .filter(e -> showUnstable || "stable".equals(e.maturity)).map(this::fromAddonEntry).toList(); } @Override diff --git a/bundles/org.openhab.core.addon.marketplace/src/test/java/org/openhab/core/addon/marketplace/test/TestAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/test/java/org/openhab/core/addon/marketplace/test/TestAddonService.java index fe5bc672a..1471c6d11 100644 --- a/bundles/org.openhab.core.addon.marketplace/src/test/java/org/openhab/core/addon/marketplace/test/TestAddonService.java +++ b/bundles/org.openhab.core.addon.marketplace/src/test/java/org/openhab/core/addon/marketplace/test/TestAddonService.java @@ -16,7 +16,6 @@ import java.net.URI; import java.util.List; import java.util.Locale; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -76,7 +75,7 @@ public class TestAddonService extends AbstractRemoteAddonService { remoteCalls++; return REMOTE_ADDONS.stream().map(id -> Addon.create(SERVICE_PID + ":" + id).withType("binding") .withId(id.substring("binding-".length())).withContentType(TestAddonHandler.TEST_ADDON_CONTENT_TYPE) - .withCompatible(!id.equals(INCOMPATIBLE_VERSION)).build()).collect(Collectors.toList()); + .withCompatible(!id.equals(INCOMPATIBLE_VERSION)).build()).toList(); } @Override diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioManagerImpl.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioManagerImpl.java index eb79b9344..41a773937 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioManagerImpl.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/internal/AudioManagerImpl.java @@ -13,7 +13,6 @@ package org.openhab.core.audio.internal; import static java.util.Comparator.comparing; -import static java.util.stream.Collectors.toList; import java.io.File; import java.io.IOException; @@ -312,10 +311,10 @@ public class AudioManagerImpl implements AudioManager, ConfigOptionProvider { final Locale safeLocale = locale != null ? locale : Locale.getDefault(); if (CONFIG_DEFAULT_SOURCE.equals(param)) { return audioSources.values().stream().sorted(comparing(s -> s.getLabel(safeLocale))) - .map(s -> new ParameterOption(s.getId(), s.getLabel(safeLocale))).collect(toList()); + .map(s -> new ParameterOption(s.getId(), s.getLabel(safeLocale))).toList(); } else if (CONFIG_DEFAULT_SINK.equals(param)) { return audioSinks.values().stream().sorted(comparing(s -> s.getLabel(safeLocale))) - .map(s -> new ParameterOption(s.getId(), s.getLabel(safeLocale))).collect(toList()); + .map(s -> new ParameterOption(s.getId(), s.getLabel(safeLocale))).toList(); } } return null; 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 f36fd82d4..7238df8fb 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 @@ -31,7 +31,6 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.servlet.Servlet; @@ -172,7 +171,7 @@ public class AudioServlet extends HttpServlet implements AudioHTTPServer { final String streamId = substringBefore(substringAfterLast(requestURI, "/"), "."); List acceptedMimeTypes = Stream.of(Objects.requireNonNullElse(req.getHeader("Accept"), "").split(",")) - .map(String::trim).collect(Collectors.toList()); + .map(String::trim).toList(); StreamServed servedStream = servedStreams.get(streamId); if (servedStream == null) { @@ -219,7 +218,7 @@ public class AudioServlet extends HttpServlet implements AudioHTTPServer { long now = System.nanoTime(); final List toRemove = servedStreams.entrySet().stream() .filter(e -> e.getValue().timeout().get() < now && e.getValue().currentlyServedStream().get() <= 0) - .map(Entry::getKey).collect(Collectors.toList()); + .map(Entry::getKey).toList(); toRemove.forEach(streamId -> { // the stream has expired and no one is using it, we need to remove it! 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 7a52a6602..e9fa7cac3 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 @@ -13,7 +13,6 @@ package org.openhab.core.automation.module.media.internal; import static java.util.Comparator.comparing; -import static java.util.stream.Collectors.toList; import java.io.File; import java.math.BigDecimal; @@ -162,7 +161,7 @@ public class MediaActionTypeProvider implements ModuleTypeProvider { private List getSinkOptions(@Nullable Locale locale) { final Locale safeLocale = locale != null ? locale : Locale.getDefault(); return audioManager.getAllSinks().stream().sorted(comparing(s -> s.getLabel(safeLocale))) - .map(s -> new ParameterOption(s.getId(), s.getLabel(safeLocale))).collect(toList()); + .map(s -> new ParameterOption(s.getId(), s.getLabel(safeLocale))).toList(); } @Override diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java index c5f22eb8d..e784aa6c0 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java @@ -29,7 +29,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import javax.script.Compilable; import javax.script.CompiledScript; @@ -246,7 +245,7 @@ public class ScriptTransformationService implements TransformationService, Confi if (ScriptProfile.CONFIG_TO_HANDLER_SCRIPT.equals(param) || ScriptProfile.CONFIG_TO_ITEM_SCRIPT.equals(param)) { return transformationRegistry.getTransformations(List.of(scriptType.toLowerCase())).stream() - .map(c -> new ParameterOption(c.getUID(), c.getLabel())).collect(Collectors.toList()); + .map(c -> new ParameterOption(c.getUID(), c.getLabel())).toList(); } return null; } diff --git a/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java b/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java index cb78591b1..09b163c3f 100644 --- a/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java +++ b/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/RuleResource.java @@ -25,7 +25,6 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.security.RolesAllowed; @@ -433,7 +432,7 @@ public class RuleResource implements RESTResource { } final Stream ruleExecutions = ruleManager.simulateRuleExecutions(fromDate, untilDate); - return Response.ok(ruleExecutions.collect(Collectors.toList())).build(); + return Response.ok(ruleExecutions.toList()).build(); } private static ZonedDateTime parseTime(String sTime) { diff --git a/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/TemplateResource.java b/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/TemplateResource.java index 58979ae02..20e1d78e1 100644 --- a/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/TemplateResource.java +++ b/bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/TemplateResource.java @@ -14,7 +14,6 @@ package org.openhab.core.automation.rest.internal; import java.util.Collection; import java.util.Locale; -import java.util.stream.Collectors; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; @@ -92,7 +91,7 @@ public class TemplateResource implements RESTResource { @HeaderParam("Accept-Language") @Parameter(description = "language") @Nullable String language) { Locale locale = localeService.getLocale(language); Collection result = templateRegistry.getAll(locale).stream() - .map(template -> RuleTemplateDTOMapper.map(template)).collect(Collectors.toList()); + .map(template -> RuleTemplateDTOMapper.map(template)).toList(); return Response.ok(result).build(); } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AbstractResourceBundleProvider.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AbstractResourceBundleProvider.java index 77758f80d..c50b7431c 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AbstractResourceBundleProvider.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/provider/AbstractResourceBundleProvider.java @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -388,7 +387,7 @@ public abstract class AbstractResourceBundleProvider<@NonNull E> { URI uri = new URI(prefix + ":" + uid + ".name"); return config.stream() .map(p -> localConfigI18nService.getLocalizedConfigDescriptionParameter(bundle, uri, p, locale)) - .collect(Collectors.toList()); + .toList(); } catch (URISyntaxException e) { logger.error("Constructed invalid uri '{}:{}.name'", prefix, uid, e); return config; diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/ruleengine/WrappedRule.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/ruleengine/WrappedRule.java index a5b8f0727..db6ca936a 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/ruleengine/WrappedRule.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/ruleengine/WrappedRule.java @@ -17,7 +17,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.function.Function; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.automation.Module; @@ -37,12 +36,11 @@ public class WrappedRule { private static List map(final List in, Function factory, final Collection> coll) { - // explicit cast to List as JDK compiler complains - return Collections.unmodifiableList((List) in.stream().map(module -> { + return in.stream().map(module -> { final T impl = factory.apply(module); coll.add(impl); return impl; - }).collect(Collectors.toList())); + }).toList(); } private final Rule rule; 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 88e92affc..4cee1ae02 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 @@ -17,7 +17,6 @@ import static java.util.function.Predicate.not; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -25,7 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; -import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -118,14 +117,13 @@ public class ConfigUtil { if (defaultValue != null && configuration.get(parameter.getName()) == null) { if (parameter.isMultiple()) { if (defaultValue.contains(DEFAULT_LIST_DELIMITER)) { - List values = (List) List.of(defaultValue.split(DEFAULT_LIST_DELIMITER)) - .stream() // + List values = (List) Stream.of(defaultValue.split(DEFAULT_LIST_DELIMITER)) .map(String::trim) // .filter(not(String::isEmpty)) // .map(value -> ConfigUtil.getDefaultValueAsCorrectType(parameter.getName(), parameter.getType(), value)) // .filter(Objects::nonNull) // - .collect(Collectors.toList()); + .toList(); Integer multipleLimit = parameter.getMultipleLimit(); if (multipleLimit != null && values.size() > multipleLimit.intValue()) { LoggerFactory.getLogger(ConfigUtil.class).warn( @@ -136,7 +134,7 @@ public class ConfigUtil { } else { Object value = ConfigUtil.getDefaultValueAsCorrectType(parameter); if (value != null) { - configuration.put(parameter.getName(), Arrays.asList(value)); + configuration.put(parameter.getName(), List.of(value)); } } } else { diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/i18n/I18nConfigOptionsProvider.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/i18n/I18nConfigOptionsProvider.java index c5613ca8c..13df696aa 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/i18n/I18nConfigOptionsProvider.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/i18n/I18nConfigOptionsProvider.java @@ -21,7 +21,6 @@ import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.function.Function; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -82,7 +81,7 @@ public class I18nConfigOptionsProvider implements ConfigOptionProvider { Comparator byOffset = (t1, t2) -> t1.getRawOffset() - t2.getRawOffset(); Comparator byID = (t1, t2) -> t1.getID().compareTo(t2.getID()); return ZoneId.getAvailableZoneIds().stream().map(TimeZone::getTimeZone).sorted(byOffset.thenComparing(byID)) - .map(tz -> new ParameterOption(tz.getID(), getTimeZoneRepresentation(tz))).collect(Collectors.toList()); + .map(tz -> new ParameterOption(tz.getID(), getTimeZoneRepresentation(tz))).toList(); } private static String getTimeZoneRepresentation(TimeZone tz) { @@ -107,6 +106,6 @@ public class I18nConfigOptionsProvider implements ConfigOptionProvider { .distinct() // .filter(po -> !po.getValue().isEmpty()) // .sorted(Comparator.comparing(a -> a.getLabel())) // - .collect(Collectors.toList()); + .toList(); } } diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/net/NetworkConfigOptionProvider.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/net/NetworkConfigOptionProvider.java index ab4b9bbfb..72556d5b5 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/net/NetworkConfigOptionProvider.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/internal/net/NetworkConfigOptionProvider.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -52,13 +51,11 @@ public class NetworkConfigOptionProvider implements ConfigOptionProvider { case PARAM_PRIMARY_ADDRESS: Stream ipv4Addresses = NetUtil.getAllInterfaceAddresses().stream() .filter(a -> a.getAddress() instanceof Inet4Address); - return ipv4Addresses.map(a -> new ParameterOption(a.toString(), a.toString())) - .collect(Collectors.toList()); + return ipv4Addresses.map(a -> new ParameterOption(a.toString(), a.toString())).toList(); case PARAM_BROADCAST_ADDRESS: List broadcastAddrList = new ArrayList<>(NetUtil.getAllBroadcastAddresses()); broadcastAddrList.add("255.255.255.255"); - return broadcastAddrList.stream().distinct().map(a -> new ParameterOption(a, a)) - .collect(Collectors.toList()); + return broadcastAddrList.stream().distinct().map(a -> new ParameterOption(a, a)).toList(); default: return null; } diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/ConfigStatusInfo.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/ConfigStatusInfo.java index 386f8481b..e195d7147 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/ConfigStatusInfo.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/ConfigStatusInfo.java @@ -18,7 +18,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Objects; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -137,7 +136,7 @@ public final class ConfigStatusInfo { private static Collection filterConfigStatusMessages( Collection configStatusMessages, Predicate predicate) { - return configStatusMessages.stream().filter(predicate).collect(Collectors.toList()); + return configStatusMessages.stream().filter(predicate).toList(); } @Override diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/normalization/NormalizerTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/normalization/NormalizerTest.java index 194761201..bd0a466cf 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/normalization/NormalizerTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/normalization/NormalizerTest.java @@ -12,7 +12,6 @@ */ package org.openhab.core.config.core.internal.normalization; -import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; @@ -153,14 +152,13 @@ public class NormalizerTest { assertThat(normalizer.normalize(null), is(nullValue())); - List expectedList = Stream.of(true, false, true).collect(toList()); + List expectedList = Stream.of(true, false, true).toList(); - assertThat(normalizer.normalize(Stream.of(true, false, true).collect(toList())), is(equalTo(expectedList))); - assertThat(normalizer.normalize(Stream.of(true, false, true).collect(toList()).toArray()), - is(equalTo(expectedList))); - assertThat(normalizer.normalize(new TreeSet<>(Stream.of(false, true).collect(toList()))), - is(equalTo(Stream.of(false, true).collect(toList())))); - assertThat(normalizer.normalize(Stream.of(true, "false", true).collect(toList())), is(equalTo(expectedList))); - assertThat(normalizer.normalize(Stream.of(true, 0, "true").collect(toList())), is(equalTo(expectedList))); + assertThat(normalizer.normalize(Stream.of(true, false, true).toList()), is(equalTo(expectedList))); + assertThat(normalizer.normalize(Stream.of(true, false, true).toArray()), is(equalTo(expectedList))); + assertThat(normalizer.normalize(new TreeSet<>(Stream.of(false, true).toList())), + is(equalTo(Stream.of(false, true).toList()))); + assertThat(normalizer.normalize(Stream.of(true, "false", true).toList()), is(equalTo(expectedList))); + assertThat(normalizer.normalize(Stream.of(true, 0, "true").toList()), is(equalTo(expectedList))); } } 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 b39702e23..64a20ca37 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 @@ -20,7 +20,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -214,7 +213,7 @@ public class AutomaticInboxProcessor extends AbstractTypedEventSubscriber results = inbox.stream().filter(withRepresentationPropertyValue(representationValue)) - .filter(forThingTypeUID(thingtypeUID)).collect(Collectors.toList()); + .filter(forThingTypeUID(thingtypeUID)).toList(); if (results.size() == 1) { logger.debug("Auto-ignoring the inbox entry for the representation value '{}'.", representationValue); @@ -252,8 +251,7 @@ public class AutomaticInboxProcessor extends AbstractTypedEventSubscriber results = inbox.stream().filter(withRepresentationPropertyValue(representationValue)) - .filter(forThingTypeUID(thingtypeUID)).filter(withFlag(DiscoveryResultFlag.IGNORED)) - .collect(Collectors.toList()); + .filter(forThingTypeUID(thingtypeUID)).filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); if (results.size() == 1) { logger.debug("Removing the ignored result from the inbox for the representation value '{}'.", representationValue); 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 c56a66142..30288ef57 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 @@ -33,7 +33,6 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -189,7 +188,7 @@ public final class PersistentInbox implements Inbox, DiscoveryListener, ThingReg if (thingUID == null) { throw new IllegalArgumentException("Thing UID must not be null"); } - List results = stream().filter(forThingUID(thingUID)).collect(Collectors.toList()); + List results = stream().filter(forThingUID(thingUID)).toList(); if (results.isEmpty()) { throw new IllegalArgumentException("No Thing with UID " + thingUID.getAsString() + " in inbox"); } @@ -268,7 +267,7 @@ public final class PersistentInbox implements Inbox, DiscoveryListener, ThingReg } List configurationParameters = getConfigDescParams(thingType).stream() - .map(ConfigDescriptionParameter::getName).collect(Collectors.toList()); + .map(ConfigDescriptionParameter::getName).toList(); discoveryResult.normalizePropertiesOnConfigDescription(configurationParameters); @@ -369,7 +368,7 @@ public final class PersistentInbox implements Inbox, DiscoveryListener, ThingReg @Override public List getAll() { - return stream().collect(Collectors.toList()); + return stream().toList(); } @Override diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java index e798c6aa6..74a9ded54 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/internal/console/InboxConsoleCommandExtension.java @@ -18,7 +18,6 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.config.discovery.DiscoveryResult; @@ -73,8 +72,7 @@ public class InboxConsoleCommandExtension extends AbstractConsoleCommandExtensio } try { ThingUID thingUID = new ThingUID(args[1]); - List results = inbox.stream().filter(forThingUID(thingUID)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(forThingUID(thingUID)).toList(); if (results.isEmpty()) { console.println("No matching inbox entry could be found."); return; @@ -102,12 +100,10 @@ public class InboxConsoleCommandExtension extends AbstractConsoleCommandExtensio } break; case SUBCMD_LIST: - printInboxEntries(console, - inbox.stream().filter(withFlag((DiscoveryResultFlag.NEW))).collect(Collectors.toList())); + printInboxEntries(console, inbox.stream().filter(withFlag((DiscoveryResultFlag.NEW))).toList()); break; case SUBCMD_LIST_IGNORED: - printInboxEntries(console, inbox.stream().filter(withFlag((DiscoveryResultFlag.IGNORED))) - .collect(Collectors.toList())); + printInboxEntries(console, inbox.stream().filter(withFlag((DiscoveryResultFlag.IGNORED))).toList()); break; case SUBCMD_CLEAR: clearInboxEntries(console, inbox.getAll()); @@ -117,8 +113,7 @@ public class InboxConsoleCommandExtension extends AbstractConsoleCommandExtensio boolean validParam = true; try { ThingUID thingUID = new ThingUID(args[1]); - List results = inbox.stream().filter(forThingUID(thingUID)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(forThingUID(thingUID)).toList(); if (results.isEmpty()) { console.println("No matching inbox entry could be found."); } else { @@ -131,7 +126,7 @@ public class InboxConsoleCommandExtension extends AbstractConsoleCommandExtensio try { ThingTypeUID thingTypeUID = new ThingTypeUID(args[1]); List results = inbox.stream().filter(forThingTypeUID(thingTypeUID)) - .collect(Collectors.toList()); + .toList(); if (results.isEmpty()) { console.println("No matching inbox entry could be found."); } else { 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 a48481154..b00e5771e 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 @@ -19,7 +19,6 @@ import static org.openhab.core.config.discovery.inbox.InboxPredicates.*; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.BeforeEach; @@ -79,89 +78,75 @@ public class InboxPredicatesTest { @Test public void testForBinding() { - assertThat(RESULTS.stream().filter(forBinding(BINDING_ID1)).collect(Collectors.toList()).size(), is(3)); + assertThat(RESULTS.stream().filter(forBinding(BINDING_ID1)).toList().size(), is(3)); - assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).collect(Collectors.toList()).size(), is(1)); - assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).collect(Collectors.toList()).get(0), - is(equalTo(RESULTS.get(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)).filter(withFlag(DiscoveryResultFlag.NEW)) - .collect(Collectors.toList()).size(), is(0)); + assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).filter(withFlag(DiscoveryResultFlag.NEW)).toList() + .size(), is(0)); assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).filter(withFlag(DiscoveryResultFlag.IGNORED)) - .collect(Collectors.toList()).size(), is(1)); + .toList().size(), is(1)); assertThat(RESULTS.stream().filter(forBinding(BINDING_ID2)).filter(withFlag(DiscoveryResultFlag.IGNORED)) - .collect(Collectors.toList()).get(0), is(equalTo(RESULTS.get(3)))); + .toList().get(0), is(equalTo(RESULTS.get(3)))); } @Test public void testForThingTypeUID() { - assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID11)).collect(Collectors.toList()).size(), - is(2)); + assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID11)).toList().size(), is(2)); - assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID12)).collect(Collectors.toList()).size(), - is(1)); - assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID12)).collect(Collectors.toList()).get(0), + assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID12)).toList().size(), is(1)); + assertThat(RESULTS.stream().filter(forThingTypeUID(THING_TYPE_UID12)).toList().get(0), is(equalTo(RESULTS.get(2)))); } @Test public void testForThingUID() { - assertThat(RESULTS.stream().filter(forThingUID(THING_UID11)).collect(Collectors.toList()).size(), is(1)); - assertThat(RESULTS.stream().filter(forThingUID(THING_UID11)).collect(Collectors.toList()).get(0), - is(equalTo(RESULTS.get(0)))); + 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_UID12)).collect(Collectors.toList()).size(), is(2)); - assertThat(RESULTS.stream().filter(forThingUID(THING_UID12)).filter(forThingTypeUID(THING_TYPE_UID12)) - .collect(Collectors.toList()).size(), is(1)); - assertThat(RESULTS.stream().filter(forThingUID(THING_UID12)).filter(forThingTypeUID(THING_TYPE_UID12)) - .collect(Collectors.toList()).get(0), is(equalTo(RESULTS.get(2)))); + 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)))); } @Test public void testWithFlag() { - assertThat(RESULTS.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()).size(), - is(3)); - assertThat(RESULTS.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()).size(), - is(1)); - assertThat(RESULTS.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()).get(0), + 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), is(equalTo(RESULTS.get(3)))); } @Test public void testWithProperty() { - assertThat(RESULTS.stream().filter(withProperty(PROP1, PROP_VAL1)).collect(Collectors.toList()).size(), is(2)); - assertThat(RESULTS.stream().filter(withProperty(PROP2, PROP_VAL2)).collect(Collectors.toList()).size(), is(4)); - assertThat(RESULTS.stream().filter(withProperty(PROP1, PROP_VAL2)).collect(Collectors.toList()).size(), is(0)); - assertThat(RESULTS.stream().filter(withProperty(PROP2, PROP_VAL1)).collect(Collectors.toList()).size(), is(0)); - assertThat(RESULTS.stream().filter(withProperty(null, PROP_VAL1)).collect(Collectors.toList()).size(), is(0)); + assertThat(RESULTS.stream().filter(withProperty(PROP1, PROP_VAL1)).toList().size(), is(2)); + assertThat(RESULTS.stream().filter(withProperty(PROP2, PROP_VAL2)).toList().size(), is(4)); + assertThat(RESULTS.stream().filter(withProperty(PROP1, PROP_VAL2)).toList().size(), is(0)); + assertThat(RESULTS.stream().filter(withProperty(PROP2, PROP_VAL1)).toList().size(), is(0)); + assertThat(RESULTS.stream().filter(withProperty(null, PROP_VAL1)).toList().size(), is(0)); } @Test public void testWithRepresentationProperty() { - assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP1)).collect(Collectors.toList()).size(), - is(1)); - assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP1)).collect(Collectors.toList()).get(0), + 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(PROP2)).collect(Collectors.toList()).size(), - is(1)); - assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP2)).collect(Collectors.toList()).get(0), + assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP2)).toList().size(), is(1)); + assertThat(RESULTS.stream().filter(withRepresentationProperty(PROP2)).toList().get(0), is(equalTo(RESULTS.get(2)))); } @Test public void testWithRepresentationPropertyValue() { - assertThat( - RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL1)).collect(Collectors.toList()).size(), - is(1)); - assertThat( - RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL1)).collect(Collectors.toList()).get(0), + 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_VAL2)).collect(Collectors.toList()).size(), - is(1)); - assertThat( - RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL2)).collect(Collectors.toList()).get(0), + assertThat(RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL2)).toList().size(), is(1)); + assertThat(RESULTS.stream().filter(withRepresentationPropertyValue(PROP_VAL2)).toList().get(0), 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 9f8f2fe77..a4140bd54 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 @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -169,8 +168,7 @@ public class AutomaticInboxProcessorTest { .withRepresentationProperty(DEVICE_ID_KEY).build()); // Then there is a discovery result which is NEW - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); @@ -183,10 +181,10 @@ public class AutomaticInboxProcessorTest { automaticInboxProcessor.receive(thingStatusInfoChangedEventMock); // Then there should still be the NEW discovery result, but no IGNORED discovery result - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(0)); } @@ -201,12 +199,11 @@ public class AutomaticInboxProcessorTest { .withRepresentationProperty(DEVICE_ID_KEY).build()); // Do NOT ignore this discovery result because it has a different binding ID - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(0)); // Then there is a discovery result which is NEW - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID3))); } @@ -216,8 +213,7 @@ public class AutomaticInboxProcessorTest { inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID) .withRepresentationProperty(DEVICE_ID_KEY).build()); - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); @@ -227,25 +223,23 @@ public class AutomaticInboxProcessorTest { when(thingStatusInfoChangedEventMock.getThingUID()).thenReturn(THING_UID); automaticInboxProcessor.receive(thingStatusInfoChangedEventMock); - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(0)); - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); } @Test public void testNoDiscoveryResultIfNoRepresentationPropertySet() { - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(0)); } @Test public void testThingWhenNoRepresentationPropertySet() { inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID).build()); - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); @@ -255,7 +249,7 @@ public class AutomaticInboxProcessorTest { when(thingStatusInfoChangedEventMock.getThingUID()).thenReturn(THING_UID); automaticInboxProcessor.receive(thingStatusInfoChangedEventMock); - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(0)); } @@ -270,10 +264,9 @@ public class AutomaticInboxProcessorTest { inbox.add(DiscoveryResultBuilder.create(THING_UID2).withProperty(DEVICE_ID_KEY, DEVICE_ID) .withRepresentationProperty(DEVICE_ID_KEY).build()); - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(0)); - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); } @@ -284,8 +277,7 @@ public class AutomaticInboxProcessorTest { .withRepresentationProperty(DEVICE_ID_KEY).build()); inbox.setFlag(THING_UID, DiscoveryResultFlag.IGNORED); - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); @@ -305,8 +297,7 @@ public class AutomaticInboxProcessorTest { .withRepresentationProperty(DEVICE_ID_KEY).build()); inbox.setFlag(THING_UID3, DiscoveryResultFlag.IGNORED); - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(2)); automaticInboxProcessor.removed(thingMock); @@ -321,8 +312,7 @@ public class AutomaticInboxProcessorTest { inbox.add(DiscoveryResultBuilder.create(THING_UID2).withProperty(OTHER_KEY, OTHER_VALUE) .withRepresentationProperty(OTHER_KEY).build()); - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); @@ -332,9 +322,9 @@ public class AutomaticInboxProcessorTest { when(thingStatusInfoChangedEventMock.getThingUID()).thenReturn(THING_UID2); automaticInboxProcessor.receive(thingStatusInfoChangedEventMock); - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(0)); - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); } @@ -350,10 +340,9 @@ public class AutomaticInboxProcessorTest { inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(OTHER_KEY, OTHER_VALUE) .withRepresentationProperty(OTHER_KEY).build()); - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(); assertThat(results.size(), is(0)); - results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()); + results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); } @@ -364,8 +353,7 @@ public class AutomaticInboxProcessorTest { .withRepresentationProperty(OTHER_KEY).build()); inbox.setFlag(THING_UID2, DiscoveryResultFlag.IGNORED); - List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)) - .collect(Collectors.toList()); + List results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList(); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); 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 3246d06dc..ee1175d6a 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 @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -436,14 +435,14 @@ public class ConfigDispatcher { String value = trimmedLine.substring(property.length() + 1).trim(); if (value.startsWith(DEFAULT_LIST_STARTING_CHARACTER) && value.endsWith(DEFAULT_LIST_ENDING_CHARACTER)) { logger.debug("Found list in value '{}'", value); - List values = Arrays.asList(value // + // + List values = Arrays.stream(value // .replace(DEFAULT_LIST_STARTING_CHARACTER, "") // .replace(DEFAULT_LIST_ENDING_CHARACTER, "")// .split(DEFAULT_LIST_DELIMITER))// - .stream()// .map(v -> v.trim())// .filter(v -> !v.isEmpty())// - .collect(Collectors.toList()); + .toList(); return new ParseLineResult(pid, property.trim(), values); } else { return new ParseLineResult(pid, property.trim(), value); @@ -539,7 +538,7 @@ public class ConfigDispatcher { */ public List getOrphanPIDs() { return processedPIDMapping.entrySet().stream().filter(e -> e.getValue() == null).map(e -> e.getKey()) - .collect(Collectors.toList()); + .toList(); } /** @@ -547,7 +546,7 @@ public class ConfigDispatcher { */ public void setCurrentExclusivePIDList() { exclusivePIDs = processedPIDMapping.entrySet().stream().filter(e -> e.getValue() != null) - .map(e -> e.getKey()).collect(Collectors.toList()); + .map(e -> e.getKey()).toList(); } public boolean contains(String pid) { diff --git a/bundles/org.openhab.core.config.serial/src/main/java/org/openhab/core/config/serial/internal/SerialConfigOptionProvider.java b/bundles/org.openhab.core.config.serial/src/main/java/org/openhab/core/config/serial/internal/SerialConfigOptionProvider.java index 1cb89ed04..db2f556aa 100644 --- a/bundles/org.openhab.core.config.serial/src/main/java/org/openhab/core/config/serial/internal/SerialConfigOptionProvider.java +++ b/bundles/org.openhab.core.config.serial/src/main/java/org/openhab/core/config/serial/internal/SerialConfigOptionProvider.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.Locale; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -87,7 +86,7 @@ public class SerialConfigOptionProvider implements ConfigOptionProvider, UsbSeri previouslyDiscovered.stream().map(UsbSerialDeviceInformation::getSerialPort)) .distinct() // .map(serialPortName -> new ParameterOption(serialPortName, serialPortName)) // - .collect(Collectors.toList()); + .toList(); } return null; } diff --git a/bundles/org.openhab.core.config.serial/src/test/java/org/openhab/core/config/serial/internal/SerialConfigOptionProviderTest.java b/bundles/org.openhab.core.config.serial/src/test/java/org/openhab/core/config/serial/internal/SerialConfigOptionProviderTest.java index 1e8668f06..204997a4b 100644 --- a/bundles/org.openhab.core.config.serial/src/test/java/org/openhab/core/config/serial/internal/SerialConfigOptionProviderTest.java +++ b/bundles/org.openhab.core.config.serial/src/test/java/org/openhab/core/config/serial/internal/SerialConfigOptionProviderTest.java @@ -20,7 +20,6 @@ import static org.openhab.core.config.serial.internal.SerialConfigOptionProvider import java.net.URI; import java.util.Arrays; import java.util.Collection; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -83,7 +82,7 @@ public class SerialConfigOptionProviderTest { Collection actual = provider.getParameterOptions(URI.create("uri"), "serialPort", SERIAL_PORT, null); Collection expected = Arrays.stream(serialPortIdentifiers) - .map(id -> new ParameterOption(id, id)).collect(Collectors.toList()); + .map(id -> new ParameterOption(id, id)).toList(); assertThat(actual, is(expected)); } diff --git a/bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java b/bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java index 65b9b8bf9..a1a35fa20 100644 --- a/bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java +++ b/bundles/org.openhab.core.ephemeris/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImpl.java @@ -36,7 +36,6 @@ import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -259,7 +258,7 @@ public class EphemerisManagerImpl implements EphemerisManager, ConfigOptionProvi LocalDate toDate = from.plusDays(span).toLocalDate(); Set days = holidayManager.getHolidays(fromDate, toDate, countryParameters.toArray(new String[0])); - return days.stream().sorted(Comparator.comparing(Holiday::getDate)).collect(Collectors.toList()); + return days.stream().sorted(Comparator.comparing(Holiday::getDate)).toList(); } @Override diff --git a/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandCompleter.java b/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandCompleter.java index b80c788ed..a3981197b 100644 --- a/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandCompleter.java +++ b/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandCompleter.java @@ -15,7 +15,6 @@ package org.openhab.core.io.console.internal.extension; import java.util.List; import java.util.Objects; import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -51,8 +50,7 @@ public class ItemConsoleCommandCompleter implements ConsoleCommandCompleter { @SuppressWarnings("unchecked") public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List candidates) { if (cursorArgumentIndex <= 0) { - return new StringsCompleter( - itemRegistry.getAll().stream().map(i -> i.getName()).collect(Collectors.toList()), true) + return new StringsCompleter(itemRegistry.getAll().stream().map(i -> i.getName()).toList(), true) .complete(args, cursorArgumentIndex, cursorPosition, candidates); } var localDataTypeGetter = dataTypeGetter; @@ -62,8 +60,8 @@ public class ItemConsoleCommandCompleter implements ConsoleCommandCompleter { Stream> enums = Stream.of(localDataTypeGetter.apply(item)).filter(Class::isEnum); Stream> enumConstants = enums.flatMap( t -> Stream.of(Objects.requireNonNull(((Class>) t).getEnumConstants()))); - return new StringsCompleter(enumConstants.map(Object::toString).collect(Collectors.toList()), false) - .complete(args, cursorArgumentIndex, cursorPosition, candidates); + return new StringsCompleter(enumConstants.map(Object::toString).toList(), false).complete(args, + cursorArgumentIndex, cursorPosition, candidates); } catch (ItemNotFoundException | ItemNotUniqueException e) { return false; } diff --git a/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandExtension.java b/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandExtension.java index 4cd4d45dc..3ec465451 100644 --- a/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandExtension.java +++ b/bundles/org.openhab.core.io.console/src/main/java/org/openhab/core/io/console/internal/extension/ItemConsoleCommandExtension.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.List; import java.util.Set; import java.util.function.Consumer; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -74,8 +73,8 @@ public class ItemConsoleCommandExtension extends AbstractConsoleCommandExtension default: return false; } - return new StringsCompleter(items.stream().map(i -> i.getName()).collect(Collectors.toList()), true) - .complete(args, cursorArgumentIndex, cursorPosition, candidates); + return new StringsCompleter(items.stream().map(i -> i.getName()).toList(), true).complete(args, + cursorArgumentIndex, cursorPosition, candidates); } if (cursorArgumentIndex == 2 && args[0].equals(SUBCMD_RMTAG)) { Item item = managedItemProvider.get(args[1]); diff --git a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/ExtensibleTrustManagerImplTest.java b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/ExtensibleTrustManagerImplTest.java index 63060c62e..9f5f651eb 100644 --- a/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/ExtensibleTrustManagerImplTest.java +++ b/bundles/org.openhab.core.io.net/src/test/java/org/openhab/core/io/net/http/internal/ExtensibleTrustManagerImplTest.java @@ -22,7 +22,6 @@ import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.net.ssl.SSLEngine; @@ -174,7 +173,7 @@ public class ExtensibleTrustManagerImplTest { private Collection> constructAlternativeNames(String... alternatives) { Collection> alternativeNames = new ArrayList<>(); for (String alternative : alternatives) { - alternativeNames.add(Stream.of(0, alternative).collect(Collectors.toList())); + alternativeNames.add(Stream.of(0, alternative).toList()); } return alternativeNames; diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionParameterDTO.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionParameterDTO.java index d736cb11f..754aa5739 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionParameterDTO.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/config/EnrichedConfigDescriptionParameterDTO.java @@ -16,7 +16,7 @@ import java.math.BigDecimal; import java.util.Collection; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -49,8 +49,8 @@ public class EnrichedConfigDescriptionParameterDTO extends ConfigDescriptionPara if (multiple && defaultValue != null) { if (defaultValue.contains(DEFAULT_LIST_DELIMITER)) { - defaultValues = List.of(defaultValue.split(DEFAULT_LIST_DELIMITER)).stream().map(v -> v.trim()) - .filter(v -> !v.isEmpty()).collect(Collectors.toList()); + defaultValues = Stream.of(defaultValue.split(DEFAULT_LIST_DELIMITER)).map(String::trim) + .filter(v -> !v.isEmpty()).toList(); } else { defaultValues = Set.of(defaultValue); } diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java index 570eb0ed7..ccc7936c1 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java @@ -386,7 +386,7 @@ public class ItemResource implements RESTResource { public Response getBinaryItemState(@HeaderParam("Accept") @Nullable String mediaType, @PathParam("itemname") @Parameter(description = "item name") String itemname) { List acceptedMediaTypes = Arrays.stream(Objects.requireNonNullElse(mediaType, "").split(",")) - .map(String::trim).collect(Collectors.toList()); + .map(String::trim).toList(); Item item = getItem(itemname); 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 abb25863e..ab158eb23 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 @@ -14,7 +14,6 @@ package org.openhab.core.io.rest.core.internal.link; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.security.RolesAllowed; @@ -172,10 +171,9 @@ public class ItemChannelLinkResource implements RESTResource { @PathParam("channelUID") @Parameter(description = "channel UID") String channelUid) { List links = itemChannelLinkRegistry.stream() .filter(link -> channelUid.equals(link.getLinkedUID().getAsString())) - .filter(link -> itemName.equals(link.getItemName())) - .map(link -> EnrichedItemChannelLinkDTOMapper.map(link, - isEditable(AbstractLink.getIDFor(link.getItemName(), link.getLinkedUID())))) - .collect(Collectors.toList()); + .filter(link -> itemName.equals(link.getItemName())).map(link -> EnrichedItemChannelLinkDTOMapper + .map(link, isEditable(AbstractLink.getIDFor(link.getItemName(), link.getLinkedUID())))) + .toList(); if (!links.isEmpty()) { return JSONResponse.createResponse(Status.OK, links.get(0), null); 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 1b5f5490c..dacf9f305 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 @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.stream.Collectors; import javax.annotation.security.RolesAllowed; import javax.ws.rs.Consumes; @@ -369,7 +368,7 @@ public class ConfigurableServiceResource implements RESTResource { } else if (pid instanceof String[] pids) { serviceId = getServicePID(cn, Arrays.asList(pids)); } else if (pid instanceof Collection pids) { - serviceId = getServicePID(cn, pids.stream().map(entry -> entry.toString()).collect(Collectors.toList())); + serviceId = getServicePID(cn, pids.stream().map(Object::toString).toList()); } else { logger.warn("The component \"{}\" is using an unhandled service PID type ({}). Use component name.", cn, pid.getClass()); diff --git a/bundles/org.openhab.core.io.rest.voice/src/main/java/org/openhab/core/io/rest/voice/internal/VoiceResource.java b/bundles/org.openhab.core.io.rest.voice/src/main/java/org/openhab/core/io/rest/voice/internal/VoiceResource.java index dc6f0a703..c0c84ebe9 100644 --- a/bundles/org.openhab.core.io.rest.voice/src/main/java/org/openhab/core/io/rest/voice/internal/VoiceResource.java +++ b/bundles/org.openhab.core.io.rest.voice/src/main/java/org/openhab/core/io/rest/voice/internal/VoiceResource.java @@ -15,7 +15,6 @@ package org.openhab.core.io.rest.voice.internal; import java.util.List; import java.util.Locale; import java.util.Objects; -import java.util.stream.Collectors; import javax.annotation.security.RolesAllowed; import javax.ws.rs.Consumes; @@ -114,7 +113,7 @@ public class VoiceResource implements RESTResource { @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) { final Locale locale = localeService.getLocale(language); List dtos = voiceManager.getHLIs().stream().map(hli -> HLIMapper.map(hli, locale)) - .collect(Collectors.toList()); + .toList(); return Response.ok(dtos).build(); } @@ -203,7 +202,7 @@ public class VoiceResource implements RESTResource { @Operation(operationId = "getVoices", summary = "Get the list of all voices.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = VoiceDTO.class)))) }) public Response getVoices() { - List dtos = voiceManager.getAllVoices().stream().map(VoiceMapper::map).collect(Collectors.toList()); + List dtos = voiceManager.getAllVoices().stream().map(VoiceMapper::map).toList(); return Response.ok(dtos).build(); } diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/DTOMapperImpl.java b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/DTOMapperImpl.java index 764bbe8c0..4ce2559d5 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/DTOMapperImpl.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/openhab/core/io/rest/internal/DTOMapperImpl.java @@ -14,7 +14,6 @@ package org.openhab.core.io.rest.internal; import java.lang.reflect.Field; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNull; @@ -42,7 +41,7 @@ public class DTOMapperImpl implements DTOMapper { if (fields == null || fields.trim().isEmpty()) { return itemStream; } - List fieldList = Stream.of(fields.split(",")).map(field -> field.trim()).collect(Collectors.toList()); + List fieldList = Stream.of(fields.split(",")).map(String::trim).toList(); return itemStream.map(dto -> { for (Field field : dto.getClass().getFields()) { if (!fieldList.contains(field.getName())) { diff --git a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusLibraryWrapper.java b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusLibraryWrapper.java index b0a9a56cb..b8a155042 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusLibraryWrapper.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/main/java/org/openhab/core/io/transport/modbus/internal/ModbusLibraryWrapper.java @@ -14,7 +14,6 @@ package org.openhab.core.io.transport.modbus.internal; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; import java.util.stream.IntStream; import org.eclipse.jdt.annotation.NonNull; @@ -269,8 +268,8 @@ public class ModbusLibraryWrapper { * @return */ public static Register[] convertRegisters(ModbusRegisterArray arr) { - return IntStream.range(0, arr.size()).mapToObj(i -> new SimpleInputRegister(arr.getRegister(i))) - .collect(Collectors.toList()).toArray(new Register[0]); + return IntStream.range(0, arr.size()).mapToObj(i -> new SimpleInputRegister(arr.getRegister(i))).toList() + .toArray(new Register[0]); } /** diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractIndividualMethodsTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractIndividualMethodsTest.java index 710294134..e191fbbbf 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractIndividualMethodsTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractIndividualMethodsTest.java @@ -19,7 +19,6 @@ import java.util.Collection; import java.util.Optional; import java.util.function.Function; import java.util.function.Supplier; -import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.Stream.Builder; @@ -51,7 +50,7 @@ public class BitUtilitiesExtractIndividualMethodsTest { ModbusRegisterArray registers = (ModbusRegisterArray) values[2]; int index = (int) values[3]; return registerVariations(expectedResult, type, registers, index); - }).collect(Collectors.toList()); + }).toList(); } public static Stream filteredTestData(ValueType type) { diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractStateFromRegistersTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractStateFromRegistersTest.java index acaf4768a..2676a841a 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractStateFromRegistersTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractStateFromRegistersTest.java @@ -17,9 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Collection; -import java.util.Collections; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -41,7 +39,7 @@ public class BitUtilitiesExtractStateFromRegistersTest { } public static Collection data() { - return Collections.unmodifiableList(Stream.of( + return Stream.of( // // BIT // @@ -351,7 +349,7 @@ public class BitUtilitiesExtractStateFromRegistersTest { // out of bounds of unsigned 64bit new DecimalType("16124500437522872585"), ValueType.UINT64_SWAP, shortArrayToRegisterArray(0x7909, 0x772E, 0xBBB7, 0xDFC5), 0 }) - .collect(Collectors.toList())); + .toList(); } @SuppressWarnings("unchecked") diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractStringTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractStringTest.java index 0338c9daa..e68592bd1 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractStringTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/BitUtilitiesExtractStringTest.java @@ -17,8 +17,6 @@ import static org.junit.jupiter.api.Assertions.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Collection; -import java.util.Collections; -import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.Stream.Builder; @@ -39,8 +37,7 @@ public class BitUtilitiesExtractStringTest { } public static Collection data() { - return Collections.unmodifiableList(Stream.of( - new Object[] { "", shortArrayToRegisterArray(0), 0, 0, StandardCharsets.UTF_8 }, + return Stream.of(new Object[] { "", shortArrayToRegisterArray(0), 0, 0, StandardCharsets.UTF_8 }, new Object[] { "hello", shortArrayToRegisterArray(0x6865, 0x6c6c, 0x6f00), 0, 5, StandardCharsets.UTF_8 }, new Object[] { "he", shortArrayToRegisterArray(0x6865, 0x6c6c, 0x6f00), 0, 2, StandardCharsets.UTF_8 }, // limited @@ -77,7 +74,7 @@ public class BitUtilitiesExtractStringTest { // out of bounds new Object[] { IllegalArgumentException.class, shortArrayToRegisterArray(0, 0), 0, 5, StandardCharsets.UTF_8 }) - .collect(Collectors.toList())); + .toList(); } public static Stream dataWithByteVariations() { diff --git a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/WriteRequestJsonUtilitiesTest.java b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/WriteRequestJsonUtilitiesTest.java index 260d0e3cf..7090b96c8 100644 --- a/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/WriteRequestJsonUtilitiesTest.java +++ b/bundles/org.openhab.core.io.transport.modbus/src/test/java/org/openhab/core/io/transport/modbus/test/WriteRequestJsonUtilitiesTest.java @@ -20,7 +20,6 @@ import static org.openhab.core.io.transport.modbus.ModbusConstants.*; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.IntStream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -37,14 +36,13 @@ import org.openhab.core.io.transport.modbus.json.WriteRequestJsonUtilities; public class WriteRequestJsonUtilitiesTest { private static final List MAX_REGISTERS = IntStream.range(0, MAX_REGISTERS_WRITE_COUNT).mapToObj(i -> "1") - .collect(Collectors.toList()); + .toList(); private static final List OVER_MAX_REGISTERS = IntStream.range(0, MAX_REGISTERS_WRITE_COUNT + 1) - .mapToObj(i -> "1").collect(Collectors.toList()); + .mapToObj(i -> "1").toList(); - private static final List MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT).mapToObj(i -> "1") - .collect(Collectors.toList()); + private static final List MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT).mapToObj(i -> "1").toList(); private static final List OVER_MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT + 1).mapToObj(i -> "1") - .collect(Collectors.toList()); + .toList(); @Test public void testEmptyArray() { diff --git a/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/internal/SerialPortRegistry.java b/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/internal/SerialPortRegistry.java index 2e46df1e9..17c9f5707 100644 --- a/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/internal/SerialPortRegistry.java +++ b/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/internal/SerialPortRegistry.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.io.transport.serial.ProtocolType.PathType; @@ -79,7 +78,7 @@ public class SerialPortRegistry { .count() > 0; } - return portCreators.stream().filter(filter).collect(Collectors.toList()); + return portCreators.stream().filter(filter).toList(); } public Collection getPortCreators() { diff --git a/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/internal/console/SerialCommandExtension.java b/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/internal/console/SerialCommandExtension.java index 521f1693f..a643b8e73 100644 --- a/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/internal/console/SerialCommandExtension.java +++ b/bundles/org.openhab.core.io.transport.serial/src/main/java/org/openhab/core/io/transport/serial/internal/console/SerialCommandExtension.java @@ -16,7 +16,6 @@ import java.util.Arrays; import java.util.Deque; import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.io.console.Console; @@ -79,9 +78,8 @@ public class SerialCommandExtension extends AbstractConsoleCommandExtension { case SUBCMD_PORT_CREATORS: serialPortRegistry.getPortCreators().forEach(provider -> { console.printf("%s, accepted protocols: %s, port identifiers: %s%n", provider.getClass(), - provider.getAcceptedProtocols().collect(Collectors.toList()), - provider.getSerialPortIdentifiers().map(SerialCommandExtension::str) - .collect(Collectors.toList())); + provider.getAcceptedProtocols().toList(), + provider.getSerialPortIdentifiers().map(SerialCommandExtension::str).toList()); }); return; default: 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 5f49fa5f7..0d22594c6 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 @@ -89,8 +89,7 @@ public class FeatureInstaller implements ConfigurationListener { private static final String ADDONS_PID = "org.openhab.addons"; private static final String PROPERTY_MVN_REPOS = "org.ops4j.pax.url.mvn.repositories"; - public static final List ADDON_TYPES = AddonType.DEFAULT_TYPES.stream().map(AddonType::getId) - .collect(Collectors.toList()); + public static final List ADDON_TYPES = AddonType.DEFAULT_TYPES.stream().map(AddonType::getId).toList(); private final Logger logger = LoggerFactory.getLogger(FeatureInstaller.class); diff --git a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/LoggerBean.java b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/LoggerBean.java index 50a6369cf..4b29642fa 100644 --- a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/LoggerBean.java +++ b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/LoggerBean.java @@ -14,7 +14,6 @@ package org.openhab.core.karaf.internal; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -39,7 +38,6 @@ public class LoggerBean { } public LoggerBean(Map logLevels) { - loggers = logLevels.entrySet().stream().map(l -> new LoggerInfo(l.getKey(), l.getValue())) - .collect(Collectors.toList()); + loggers = logLevels.entrySet().stream().map(l -> new LoggerInfo(l.getKey(), l.getValue())).toList(); } } diff --git a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/jaas/ManagedUserBackingEngine.java b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/jaas/ManagedUserBackingEngine.java index 4215712d1..20eaa287a 100644 --- a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/jaas/ManagedUserBackingEngine.java +++ b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/jaas/ManagedUserBackingEngine.java @@ -18,7 +18,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import org.apache.karaf.jaas.boot.principal.GroupPrincipal; import org.apache.karaf.jaas.boot.principal.RolePrincipal; @@ -54,7 +53,7 @@ public class ManagedUserBackingEngine implements BackingEngine { @Override public List listUsers() { - return userRegistry.getAll().stream().map(u -> new UserPrincipal(u.getName())).collect(Collectors.toList()); + return userRegistry.getAll().stream().map(u -> new UserPrincipal(u.getName())).toList(); } @Override @@ -95,7 +94,7 @@ public class ManagedUserBackingEngine implements BackingEngine { public List listRoles(Principal principal) { User user = userRegistry.get(principal.getName()); if (user != null) { - return user.getRoles().stream().map(r -> new RolePrincipal(r)).collect(Collectors.toList()); + return user.getRoles().stream().map(r -> new RolePrincipal(r)).toList(); } return Collections.emptyList(); } diff --git a/bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java b/bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java index 4b016f4d3..5a6eb1426 100644 --- a/bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java +++ b/bundles/org.openhab.core.model.core/src/main/java/org/openhab/core/model/core/internal/ModelRepositoryImpl.java @@ -173,7 +173,7 @@ public class ModelRepositoryImpl implements ModelRepository { return resourceListCopy.stream() .filter(input -> input.getURI().lastSegment().contains(".") && input.isLoaded() && modelType.equalsIgnoreCase(input.getURI().fileExtension())) - .map(from -> from.getURI().path()).collect(Collectors.toList()); + .map(from -> from.getURI().path()).toList(); } } 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 faaa97a6f..0fadd736e 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,7 +16,6 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; @@ -179,7 +178,7 @@ public class ScriptEngineImpl implements ScriptEngine, ModelParser { protected Iterable getValidationErrors(final EObject model) { final List validate = validate(model); - return validate.stream().filter(input -> Severity.ERROR == input.getSeverity()).collect(Collectors.toList()); + return validate.stream().filter(input -> Severity.ERROR == input.getSeverity()).toList(); } @Override diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/BusEvent.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/BusEvent.java index c2cf8e1a3..15ccd3bb1 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/BusEvent.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/BusEvent.java @@ -16,7 +16,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.stream.Collectors; import org.openhab.core.events.EventPublisher; import org.openhab.core.items.GroupItem; @@ -98,7 +97,7 @@ public class BusEvent { } private static List getAcceptedCommandNames(Item item) { - return item.getAcceptedCommandTypes().stream().map(t -> t.getSimpleName()).collect(Collectors.toList()); + return item.getAcceptedCommandTypes().stream().map(Class::getSimpleName).toList(); } /** @@ -171,7 +170,7 @@ public class BusEvent { } private static List getAcceptedDataTypeNames(Item item) { - return item.getAcceptedDataTypes().stream().map(t -> t.getSimpleName()).collect(Collectors.toList()); + return item.getAcceptedDataTypes().stream().map(Class::getSimpleName).toList(); } /** diff --git a/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/GenericItemChannelLinkProvider.java b/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/GenericItemChannelLinkProvider.java index a98595405..06c05c88a 100644 --- a/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/GenericItemChannelLinkProvider.java +++ b/bundles/org.openhab.core.model.thing/src/org/openhab/core/model/thing/internal/GenericItemChannelLinkProvider.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -142,6 +141,6 @@ public class GenericItemChannelLinkProvider extends AbstractProvider getAll() { - return itemChannelLinkMap.values().stream().flatMap(Collection::stream).collect(Collectors.toList()); + return itemChannelLinkMap.values().stream().flatMap(Collection::stream).toList(); } } diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManager.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManager.java index 26144f920..040be8811 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManager.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManager.java @@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -446,8 +445,7 @@ public class PersistenceManager implements ItemRegistryChangeListener, StateChan .forEach(strategy -> { PersistenceCronStrategy cronStrategy = (PersistenceCronStrategy) strategy; String cronExpression = cronStrategy.getCronExpression(); - List itemConfigs = getMatchingConfigurations(strategy) - .collect(Collectors.toList()); + List itemConfigs = getMatchingConfigurations(strategy).toList(); jobs.add(scheduler.schedule(() -> persistJob(itemConfigs), cronExpression)); logger.debug("Scheduled strategy {} with cron expression {} for service {}", diff --git a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/internal/metadata/MagicMetadataProvider.java b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/internal/metadata/MagicMetadataProvider.java index 3052de47c..990fa604d 100644 --- a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/internal/metadata/MagicMetadataProvider.java +++ b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/internal/metadata/MagicMetadataProvider.java @@ -12,7 +12,6 @@ */ package org.openhab.core.magic.internal.metadata; -import static java.util.stream.Collectors.toList; import static org.openhab.core.config.core.ConfigDescriptionParameterBuilder.create; import java.util.List; @@ -51,7 +50,7 @@ public class MagicMetadataProvider implements MetadataConfigDescriptionProvider return Stream.of( // new ParameterOption("just", "Just Magic"), // new ParameterOption("pure", "Pure Magic") // - ).collect(toList()); + ).toList(); } @Override @@ -60,7 +59,7 @@ public class MagicMetadataProvider implements MetadataConfigDescriptionProvider case "just": return Stream.of( // create("electric", Type.BOOLEAN).withLabel("Use Electricity").build() // - ).collect(toList()); + ).toList(); case "pure": return Stream.of( // create("spell", Type.TEXT).withLabel("Spell").withDescription("The exact spell to use").build(), // @@ -72,8 +71,8 @@ public class MagicMetadataProvider implements MetadataConfigDescriptionProvider new ParameterOption("1", "Incredible"), // new ParameterOption("2", "Insane"), // new ParameterOption("3", "Ludicrous") // - ).collect(toList())).build() // - ).collect(toList()); + ).toList()).build() // + ).toList(); } return null; } diff --git a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/internal/java/MissingServiceAnalyzer.java b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/internal/java/MissingServiceAnalyzer.java index 64441bc56..48bd23e50 100644 --- a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/internal/java/MissingServiceAnalyzer.java +++ b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/internal/java/MissingServiceAnalyzer.java @@ -91,19 +91,19 @@ public class MissingServiceAnalyzer { .collect(toSet()); return Stream.of(description.references) // .filter(ref -> unsatisfiedRefNames.contains(ref.name)) // - .collect(toList()); + .toList(); } private List getComponentDescriptions(ServiceComponentRuntime scr, String interfaceName, Bundle[] allBundlesArrays) { return scr.getComponentDescriptionDTOs(allBundlesArrays).stream() .filter(description -> Stream.of(description.serviceInterfaces).anyMatch(s -> s.equals(interfaceName))) - .collect(toList()); + .toList(); } private Bundle[] getAllBundles() { List allBundles = Arrays.stream(bundleContext.getBundles()) - .filter(b -> b.getHeaders().get(Constants.FRAGMENT_HOST) == null).collect(toList()); + .filter(b -> b.getHeaders().get(Constants.FRAGMENT_HOST) == null).toList(); return allBundles.toArray(new Bundle[allBundles.size()]); } 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 4f944c548..73c09d85e 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 @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -118,11 +117,11 @@ public class JavaOSGiTest extends JavaTest { return Collections.emptyList(); } - return Arrays // + return (List) Arrays // .stream(serviceReferences) // .filter(filter) // apply the predicate .map(this::unrefService) // get the actual services from the references - .collect(Collectors.toList()); // get the result as List + .toList(); // get the result as List } /** @@ -204,7 +203,7 @@ public class JavaOSGiTest extends JavaTest { .map(this::unrefService) // get the actual services from the references .filter(implementationClass::isInstance) // check that are of implementationClass .map(implementationClass::cast) // cast instances to implementationClass - .collect(Collectors.toList()) // get the result as List + .toList() // get the result as List ; } @@ -281,7 +280,7 @@ public class JavaOSGiTest extends JavaTest { * The given interface names are used as OSGi service interface name. * * @param service service to be registered - * @param interfaceName interface name of the OSGi service + * @param interfaceNames interface names of the OSGi service * @param properties OSGi service properties * @return service registration object */ diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/AbstractStorageBasedTypeProvider.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/AbstractStorageBasedTypeProvider.java index 1a646a538..b6f474011 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/AbstractStorageBasedTypeProvider.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/binding/AbstractStorageBasedTypeProvider.java @@ -20,7 +20,6 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -199,7 +198,7 @@ public abstract class AbstractStorageBasedTypeProvider entity.configDescriptionUri = thingType.getConfigDescriptionURI(); entity.category = thingType.getCategory(); entity.channelGroupDefinitions = thingType.getChannelGroupDefinitions().stream() - .map(AbstractStorageBasedTypeProvider::mapToEntity).collect(Collectors.toList()); + .map(AbstractStorageBasedTypeProvider::mapToEntity).toList(); entity.channelDefinitions = thingType.getChannelDefinitions().stream() .map(AbstractStorageBasedTypeProvider::mapToEntity).toList(); entity.representationProperty = thingType.getRepresentationProperty(); diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/AutoUpdateConfigDescriptionProvider.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/AutoUpdateConfigDescriptionProvider.java index b8c45a9be..ea1c3b93d 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/AutoUpdateConfigDescriptionProvider.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/AutoUpdateConfigDescriptionProvider.java @@ -12,8 +12,6 @@ */ package org.openhab.core.thing.internal; -import static java.util.stream.Collectors.toList; - import java.util.List; import java.util.Locale; import java.util.stream.Stream; @@ -49,7 +47,7 @@ public class AutoUpdateConfigDescriptionProvider implements MetadataConfigDescri return Stream.of( // new ParameterOption("true", "Enforce an auto update"), // new ParameterOption("false", "Veto an auto update") // - ).collect(toList()); + ).toList(); } @Override diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareRegistryImpl.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareRegistryImpl.java index fb3b05f58..d7d5bbb12 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareRegistryImpl.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/firmware/FirmwareRegistryImpl.java @@ -20,7 +20,6 @@ import java.util.Optional; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -121,9 +120,7 @@ public final class FirmwareRegistryImpl implements FirmwareRegistry { try { Collection result = firmwareProvider.getFirmwares(thing, loc); if (result != null) { - List suitableFirmwares = result.stream().filter(firmware -> firmware.isSuitableFor(thing)) - .collect(Collectors.toList()); - firmwares.addAll(suitableFirmwares); + result.stream().filter(firmware -> firmware.isSuitableFor(thing)).forEach(firmwares::add); } } catch (Exception e) { logger.warn( diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/link/ItemChannelLinkConfigDescriptionProvider.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/link/ItemChannelLinkConfigDescriptionProvider.java index 4261f2155..00694f6c6 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/link/ItemChannelLinkConfigDescriptionProvider.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/link/ItemChannelLinkConfigDescriptionProvider.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.List; import java.util.Locale; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -116,8 +115,7 @@ public class ItemChannelLinkConfigDescriptionProvider implements ConfigDescripti default: throw new IllegalArgumentException("Unknown channel kind: " + channel.getKind()); } - }).map(profileType -> new ParameterOption(profileType.getUID().toString(), profileType.getLabel())) - .collect(Collectors.toList()); + }).map(profileType -> new ParameterOption(profileType.getUID().toString(), profileType.getLabel())).toList(); } private boolean isSupportedItemType(ProfileType profileType, Item item) { diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactory.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactory.java index 3fc73152d..c5ffdc4b6 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactory.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemProfileFactory.java @@ -15,12 +15,10 @@ package org.openhab.core.thing.internal.profiles; import static org.openhab.core.thing.profiles.SystemProfiles.*; import java.util.Collection; -import java.util.Collections; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -219,8 +217,7 @@ public class SystemProfileFactory implements ProfileFactory, ProfileAdvisor, Pro @Override public Collection getProfileTypes(@Nullable Locale locale) { - return Collections.unmodifiableList(SUPPORTED_PROFILE_TYPES.stream() - .map(p -> createLocalizedProfileType(p, locale)).collect(Collectors.toList())); + return SUPPORTED_PROFILE_TYPES.stream().map(p -> createLocalizedProfileType(p, locale)).toList(); } @Override diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java index 1f17c8843..6164f20dd 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/xml/internal/ThingTypeConverter.java @@ -12,8 +12,6 @@ */ package org.openhab.core.thing.xml.internal; -import static java.util.stream.Collectors.toList; - import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -116,7 +114,7 @@ public class ThingTypeConverter extends AbstractDescriptionTypeConverter ThingHelper.addChannelsToThing(thing, - Stream.of(ChannelBuilder.create(new ChannelUID(thingUID, "channel2"), "").build(), - ChannelBuilder.create(new ChannelUID(thingUID, "channel3"), "").build()) - .collect(toList()))); + () -> ThingHelper + .addChannelsToThing(thing, + Stream.of(ChannelBuilder.create(new ChannelUID(thingUID, "channel2"), "").build(), + ChannelBuilder.create(new ChannelUID(thingUID, "channel3"), "").build()) + .toList())); } @Test 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 0de4a6838..91e35fc93 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 @@ -29,7 +29,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -296,8 +295,7 @@ public abstract class AbstractFileTransformationService implements Transforma */ protected List getFilenames(String[] validExtensions) { File path = new File(getSourcePath()); - return Arrays.asList(path.listFiles(new FileExtensionsFilter(validExtensions))).stream().map(f -> f.getName()) - .collect(Collectors.toList()); + return Arrays.stream(path.listFiles(new FileExtensionsFilter(validExtensions))).map(File::getName).toList(); } protected class FileExtensionsFilter implements FilenameFilter { diff --git a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/internal/TransformationRegistryImpl.java b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/internal/TransformationRegistryImpl.java index bb18679fb..f6b4b0aba 100644 --- a/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/internal/TransformationRegistryImpl.java +++ b/bundles/org.openhab.core.transform/src/main/java/org/openhab/core/transform/internal/TransformationRegistryImpl.java @@ -17,7 +17,6 @@ import java.util.Locale; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -82,7 +81,7 @@ public class TransformationRegistryImpl extends AbstractRegistry getTransformations(Collection types) { - return getAll().stream().filter(e -> types.contains(e.getType())).collect(Collectors.toList()); + return getAll().stream().filter(e -> types.contains(e.getType())).toList(); } @Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC) diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/DialogProcessor.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/DialogProcessor.java index d171d989c..2df6b01c7 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/DialogProcessor.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/DialogProcessor.java @@ -18,7 +18,6 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.WeakHashMap; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -426,12 +425,12 @@ public class DialogProcessor implements KSListener, STTListener { private void playStartSound() { playNotes(Stream.of(ToneSynthesizer.Note.G, ToneSynthesizer.Note.A, ToneSynthesizer.Note.B) - .map(note -> ToneSynthesizer.noteTone(note, 100L)).collect(Collectors.toList())); + .map(note -> ToneSynthesizer.noteTone(note, 100L)).toList()); } private void playStopSound() { playNotes(Stream.of(ToneSynthesizer.Note.B, ToneSynthesizer.Note.A, ToneSynthesizer.Note.G) - .map(note -> ToneSynthesizer.noteTone(note, 100L)).collect(Collectors.toList())); + .map(note -> ToneSynthesizer.noteTone(note, 100L)).toList()); } private void playOnListeningSound() { diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceConsoleCommandExtension.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceConsoleCommandExtension.java index 7817952d3..08f942700 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceConsoleCommandExtension.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceConsoleCommandExtension.java @@ -492,7 +492,7 @@ public class VoiceConsoleCommandExtension extends AbstractConsoleCommandExtensio String hliIds = parameters.remove("hlis"); if (hliIds != null) { - dr.hliIds = Arrays.stream(hliIds.split(",")).map(String::trim).collect(Collectors.toList()); + dr.hliIds = Arrays.stream(hliIds.split(",")).map(String::trim).toList(); } if (!parameters.isEmpty()) { throw new IllegalStateException( diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java index 6b5c52850..070bf0824 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/internal/VoiceManagerImpl.java @@ -500,7 +500,7 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider, Dia @Override public List getDialogsContexts() { - return dialogProcessors.values().stream().map(DialogProcessor::getContext).collect(Collectors.toList()); + return dialogProcessors.values().stream().map(DialogProcessor::getContext).toList(); } @Override @@ -900,30 +900,27 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider, Dia case CONFIG_DEFAULT_HLI: return humanLanguageInterpreters.values().stream() .sorted((hli1, hli2) -> hli1.getLabel(locale).compareToIgnoreCase(hli2.getLabel(locale))) - .map(hli -> new ParameterOption(hli.getId(), hli.getLabel(locale))) - .collect(Collectors.toList()); + .map(hli -> new ParameterOption(hli.getId(), hli.getLabel(locale))).toList(); case CONFIG_DEFAULT_KS: return ksServices.values().stream() .sorted((ks1, ks2) -> ks1.getLabel(locale).compareToIgnoreCase(ks2.getLabel(locale))) - .map(ks -> new ParameterOption(ks.getId(), ks.getLabel(locale))) - .collect(Collectors.toList()); + .map(ks -> new ParameterOption(ks.getId(), ks.getLabel(locale))).toList(); case CONFIG_DEFAULT_STT: return sttServices.values().stream() .sorted((stt1, stt2) -> stt1.getLabel(locale).compareToIgnoreCase(stt2.getLabel(locale))) - .map(stt -> new ParameterOption(stt.getId(), stt.getLabel(locale))) - .collect(Collectors.toList()); + .map(stt -> new ParameterOption(stt.getId(), stt.getLabel(locale))).toList(); case CONFIG_DEFAULT_TTS: return ttsServices.values().stream() .sorted((tts1, tts2) -> tts1.getLabel(locale).compareToIgnoreCase(tts2.getLabel(locale))) - .map(tts -> new ParameterOption(tts.getId(), tts.getLabel(locale))) - .collect(Collectors.toList()); + .map(tts -> new ParameterOption(tts.getId(), tts.getLabel(locale))).toList(); case CONFIG_DEFAULT_VOICE: Locale nullSafeLocale = locale != null ? locale : localeProvider.getLocale(); - return getAllVoicesSorted(nullSafeLocale).stream().filter(v -> getTTS(v) != null) - .map(v -> new ParameterOption(v.getUID(), - String.format("%s - %s - %s", getTTS(v).getLabel(nullSafeLocale), - v.getLocale().getDisplayName(nullSafeLocale), v.getLabel()))) - .collect(Collectors.toList()); + return getAllVoicesSorted(nullSafeLocale) + .stream().filter(v -> getTTS(v) != null).map( + v -> new ParameterOption(v.getUID(), + String.format("%s - %s - %s", getTTS(v).getLabel(nullSafeLocale), + v.getLocale().getDisplayName(nullSafeLocale), v.getLabel()))) + .toList(); } } return null; diff --git a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/TokenList.java b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/TokenList.java index f69485090..3155b5b52 100644 --- a/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/TokenList.java +++ b/bundles/org.openhab.core.voice/src/main/java/org/openhab/core/voice/text/TokenList.java @@ -12,8 +12,6 @@ */ package org.openhab.core.voice.text; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -34,7 +32,7 @@ public class TokenList { * @param list of the initial tokens */ public TokenList(List list) { - this.list = Collections.unmodifiableList(new ArrayList<>(list)); + this.list = List.copyOf(list); this.head = 0; this.tail = list.size() - 1; } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/common/registry/AbstractManagedProvider.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/common/registry/AbstractManagedProvider.java index 0a1e183cb..de3679885 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/common/registry/AbstractManagedProvider.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/common/registry/AbstractManagedProvider.java @@ -14,7 +14,6 @@ package org.openhab.core.common.registry; import java.util.Collection; import java.util.Objects; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -70,8 +69,7 @@ public abstract class AbstractManagedProvider<@NonNull E extends Identifiable @Override public Collection getAll() { - return (Collection) storage.getKeys().stream().map(this::getElement).filter(Objects::nonNull) - .collect(Collectors.toList()); + return (Collection) storage.getKeys().stream().map(this::getElement).filter(Objects::nonNull).toList(); } @Override diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemRegistryImpl.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemRegistryImpl.java index daeba98f4..0d1698821 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemRegistryImpl.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/ItemRegistryImpl.java @@ -12,8 +12,6 @@ */ package org.openhab.core.internal.items; -import static java.util.stream.Collectors.toList; - import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -262,11 +260,11 @@ public class ItemRegistryImpl extends AbstractRegistry oldNames = oldItem.getGroupNames(); List newNames = item.getGroupNames(); - List commonNames = oldNames.stream().filter(newNames::contains).collect(toList()); + List commonNames = oldNames.stream().filter(newNames::contains).toList(); - removeFromGroupItems(oldItem, oldNames.stream().filter(name -> !commonNames.contains(name)).collect(toList())); + removeFromGroupItems(oldItem, oldNames.stream().filter(name -> !commonNames.contains(name)).toList()); replaceInGroupItems(oldItem, item, commonNames); - addToGroupItems(item, newNames.stream().filter(name -> !commonNames.contains(name)).collect(toList())); + addToGroupItems(item, newNames.stream().filter(name -> !commonNames.contains(name)).toList()); if (item instanceof GroupItem groupItem) { addMembersToGroupItem(groupItem); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java index a61bd846e..04a50dd25 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java @@ -19,7 +19,6 @@ import java.math.BigInteger; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -111,7 +110,7 @@ public class MetadataStateDescriptionFragmentProvider implements StateDescriptio } else { return new StateOption(o.trim(), null); } - }).collect(Collectors.toList()); + }).toList(); builder.withOptions(stateOptions); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java index f7ab33b03..f72c5d0b2 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java @@ -116,7 +116,7 @@ public abstract class GenericItem implements ActiveItem { @Override public List getGroupNames() { - return Collections.unmodifiableList(new ArrayList<>(groupNames)); + return List.copyOf(groupNames); } /** 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 5744ae67b..676420a35 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 @@ -18,7 +18,6 @@ import java.util.Arrays; import java.util.List; import java.util.SortedMap; import java.util.TreeMap; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -86,7 +85,7 @@ public class HSBType extends PercentType implements ComplexType, State, Command * @param value a stringified HSBType value in the format "hue,saturation,brightness" */ public HSBType(String value) { - List constituents = Arrays.stream(value.split(",")).map(String::trim).collect(Collectors.toList()); + List constituents = Arrays.stream(value.split(",")).map(String::trim).toList(); if (constituents.size() == 3) { this.hue = new BigDecimal(constituents.get(0)); this.saturation = new BigDecimal(constituents.get(1)); 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 40db3682d..216c45ca9 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 @@ -18,7 +18,6 @@ import java.util.Formatter; import java.util.List; import java.util.SortedMap; import java.util.TreeMap; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -85,7 +84,7 @@ public class PointType implements ComplexType, Command, State { public PointType(String value) { if (!value.isEmpty()) { - List elements = Arrays.stream(value.split(",")).map(String::trim).collect(Collectors.toList()); + 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))); if (elements.size() == 3) { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/StringListType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/StringListType.java index c2edc1b4e..416134f0d 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/StringListType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/StringListType.java @@ -49,7 +49,7 @@ public class StringListType implements Command, State { } public StringListType(StringType... rows) { - typeDetails = Arrays.stream(rows).map(StringType::toString).collect(Collectors.toList()); + typeDetails = Arrays.stream(rows).map(StringType::toString).toList(); } public StringListType(String... rows) { @@ -61,7 +61,7 @@ public class StringListType implements Command, State { */ public StringListType(String serialized) { typeDetails = Arrays.stream(serialized.split(REGEX_SPLITTER, -1)) - .map(s -> s.replace(ESCAPED_DELIMITER, DELIMITER)).collect(Collectors.toList()); + .map(s -> s.replace(ESCAPED_DELIMITER, DELIMITER)).toList(); } public String getValue(final int index) { 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 b213d6718..d20f624a7 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 @@ -34,7 +34,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -319,7 +318,7 @@ public class NetUtil implements NetworkAddressService { * * Example to get a list of only IPv4 addresses in string representation: * List l = getAllInterfaceAddresses().stream().filter(a->a.getAddress() instanceof - * Inet4Address).map(a->a.getAddress().getHostAddress()).collect(Collectors.toList()); + * Inet4Address).map(a->a.getAddress().getHostAddress()).toList(); * * down, or loopback interfaces are skipped. * @@ -531,19 +530,20 @@ public class NetUtil implements NetworkAddressService { // Look for added addresses to notify List added = newInterfaceAddresses.stream() - .filter(newInterfaceAddr -> !lastKnownInterfaceAddresses.contains(newInterfaceAddr)) - .collect(Collectors.toList()); + .filter(newInterfaceAddr -> !lastKnownInterfaceAddresses.contains(newInterfaceAddr)).toList(); // Look for removed addresses to notify List removed = lastKnownInterfaceAddresses.stream() - .filter(lastKnownInterfaceAddr -> !newInterfaceAddresses.contains(lastKnownInterfaceAddr)) - .collect(Collectors.toList()); + .filter(lastKnownInterfaceAddr -> !newInterfaceAddresses.contains(lastKnownInterfaceAddr)).toList(); lastKnownInterfaceAddresses = newInterfaceAddresses; if (!added.isEmpty() || !removed.isEmpty()) { - LOGGER.debug("added {} network interfaces: {}", added.size(), Arrays.deepToString(added.toArray())); - LOGGER.debug("removed {} network interfaces: {}", removed.size(), Arrays.deepToString(removed.toArray())); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("added {} network interfaces: {}", added.size(), Arrays.deepToString(added.toArray())); + LOGGER.debug("removed {} network interfaces: {}", removed.size(), + Arrays.deepToString(removed.toArray())); + } notifyListeners(added, removed); } 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 619ee0c09..ffdc89ecc 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 @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.function.Supplier; -import java.util.stream.Collectors; import org.apache.commons.lang3.mutable.Mutable; import org.apache.commons.lang3.mutable.MutableObject; @@ -202,7 +201,7 @@ public class LRUMediaCacheEntryTest { exceptionCatched.setValue(e); return new byte[0]; } - }).collect(Collectors.toList()); + }).toList(); IOException possibleException = exceptionCatched.getValue(); if (possibleException != null) { diff --git a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java index 167371f7c..62d2c321b 100644 --- a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java +++ b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/AutomationIntegrationTest.java @@ -919,7 +919,7 @@ public class AutomationIntegrationTest extends JavaOSGiTest { ModuleBuilder.createCondition().withId("ItemStateCondition" + (random + 1)) .withTypeUID("core.GenericCompareCondition").withConfiguration(condition2Config) .withInputs(Map.of("input", triggerId + ".event")).build()) - .collect(toList()); + .toList(); List actions = List.of(ModuleBuilder.createAction().withId("ItemPostCommandAction" + random) .withTypeUID("core.ItemCommandAction").withConfiguration(actionConfig).build()); diff --git a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/RuleSimulationTest.java b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/RuleSimulationTest.java index 3852e61c2..66b3dc2dc 100644 --- a/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/RuleSimulationTest.java +++ b/itests/org.openhab.core.automation.integration.tests/src/main/java/org/openhab/core/automation/integration/test/RuleSimulationTest.java @@ -31,7 +31,6 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -147,7 +146,7 @@ public class RuleSimulationTest extends JavaOSGiTest { final ZonedDateTime from = ZonedDateTime.of(2021, 1, 4, 0, 0, 0, 0, ZoneId.systemDefault()); final ZonedDateTime until = ZonedDateTime.of(2021, 1, 17, 23, 59, 59, 0, ZoneId.systemDefault()); - List executions = ruleEngine.simulateRuleExecutions(from, until).collect(Collectors.toList()); + List executions = ruleEngine.simulateRuleExecutions(from, until).toList(); // Every rule fires twice a week. We simulate for two weeks so we expect 12 executions // TODO: must be 12, but Ephemeris Condition is not yet evaluated in test, because dayset is not configured. diff --git a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java index 78ef39f22..ca1205606 100644 --- a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java +++ b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -199,7 +198,7 @@ public class RuleEventTest extends JavaOSGiTest { assertThat(ruleEvents.stream().filter(e -> "openhab/rules/myRule21/state".equals(e.getTopic())).findFirst() .isPresent(), is(true)); List stateEvents = ruleEvents.stream().filter(e -> "openhab/rules/myRule21/state".equals(e.getTopic())) - .collect(Collectors.toList()); + .toList(); assertThat(stateEvents, is(notNullValue())); Optional runningEvent = stateEvents.stream() .filter(e -> ((RuleStatusInfoEvent) e).getStatusInfo().getStatus() == RuleStatus.RUNNING).findFirst(); diff --git a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleRegistryTest.java b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleRegistryTest.java index 25439da07..0189761df 100644 --- a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleRegistryTest.java +++ b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/internal/RuleRegistryTest.java @@ -19,7 +19,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.BeforeEach; @@ -82,13 +81,12 @@ public class RuleRegistryTest extends JavaOSGiTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking that results from stream() have the same size as getAll() above //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - assertEquals(1, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().toList().size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking predicates //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(), - "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).toList().size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking rule with 1 tag @@ -112,7 +110,7 @@ public class RuleRegistryTest extends JavaOSGiTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking that results from stream() have the same size as getAll() above //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - assertEquals(2, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().toList().size(), "RuleImpl list size"); Collection rulesWithTag1 = ruleRegistry.getByTags(tag1); assertEquals(1, rulesWithTag1.size(), "RuleImpl list size"); @@ -120,18 +118,13 @@ public class RuleRegistryTest extends JavaOSGiTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking predicates //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(), - "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).toList().size(), "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(), - "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tags)).toList().size(), "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).toList().size(), "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(), - "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).toList().size(), "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1)).toList().size(), "RuleImpl list size"); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking rule with 2 tags @@ -156,7 +149,7 @@ public class RuleRegistryTest extends JavaOSGiTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking that results from stream() have the same size as getAll() above //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - assertEquals(3, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size"); + assertEquals(3, ruleRegistry.stream().toList().size(), "RuleImpl list size"); rulesWithTag1 = ruleRegistry.getByTags(tag1); assertEquals(2, rulesWithTag1.size(), "RuleImpl list size"); @@ -170,35 +163,26 @@ public class RuleRegistryTest extends JavaOSGiTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking predicates //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(), + assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).toList().size(), "RuleImpl list size"); + + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tags)).toList().size(), "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).toList().size(), "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).toList().size(), "RuleImpl list size"); + + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).toList().size(), "RuleImpl list size"); + + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))).toList().size(), "RuleImpl list size"); - assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).collect(Collectors.toList()).size(), - "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1)).toList().size(), "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).collect(Collectors.toList()).size(), - "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).toList().size(), "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).toList().size(), "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag2)).toList().size(), "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))) - .collect(Collectors.toList()).size(), "RuleImpl list size"); - - assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(), + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1).and(hasAllTags(tag2))).toList().size(), "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag2)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - - assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1).and(hasAllTags(tag2))) - .collect(Collectors.toList()).size(), "RuleImpl list size"); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking rule with 3 tags //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -223,7 +207,7 @@ public class RuleRegistryTest extends JavaOSGiTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking that results from stream() have the same size as getAll() above //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - assertEquals(4, ruleRegistry.stream().collect(Collectors.toList()).size(), "RuleImpl list size"); + assertEquals(4, ruleRegistry.stream().toList().size(), "RuleImpl list size"); rulesWithTag1 = ruleRegistry.getByTags(tag1); assertEquals(3, rulesWithTag1.size(), "RuleImpl list size"); @@ -246,46 +230,34 @@ public class RuleRegistryTest extends JavaOSGiTest { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // checking predicates //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).collect(Collectors.toList()).size(), + assertEquals(1, ruleRegistry.stream().filter(hasNoTags()).toList().size(), "RuleImpl list size"); + + assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tags)).toList().size(), "RuleImpl list size"); + assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).toList().size(), "RuleImpl list size"); + assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).toList().size(), "RuleImpl list size"); + assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2, tag3)).toList().size(), "RuleImpl list size"); - assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tags)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(3, ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(3, - ruleRegistry.stream().filter(hasAnyOfTags(tag1, tag2, tag3)).collect(Collectors.toList()).size(), + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).toList().size(), "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2, tag3)).toList().size(), "RuleImpl list size"); + + assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))).toList().size(), "RuleImpl list size"); - assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2)).collect(Collectors.toList()).size(), + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag3))).toList().size(), "RuleImpl list size"); - assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag2, tag3)).collect(Collectors.toList()).size(), + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2).and(hasAnyOfTags(tag3))).toList().size(), "RuleImpl list size"); - assertEquals(2, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag2))) - .collect(Collectors.toList()).size(), "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag3)).toList().size(), "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag1).and(hasAnyOfTags(tag3))) - .collect(Collectors.toList()).size(), "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag2).and(hasAnyOfTags(tag3))) - .collect(Collectors.toList()).size(), "RuleImpl list size"); + assertEquals(3, ruleRegistry.stream().filter(hasAllTags(tag1)).toList().size(), "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAnyOfTags(tag3)).collect(Collectors.toList()).size(), - "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag2)).toList().size(), "RuleImpl list size"); + assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).toList().size(), "RuleImpl list size"); - assertEquals(3, ruleRegistry.stream().filter(hasAllTags(tag1)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - - assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag2)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(2, ruleRegistry.stream().filter(hasAllTags(tag1, tag2)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - - assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).collect(Collectors.toList()).size(), - "RuleImpl list size"); - assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2, tag3)).collect(Collectors.toList()).size(), + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tags)).toList().size(), "RuleImpl list size"); + assertEquals(1, ruleRegistry.stream().filter(hasAllTags(tag1, tag2, tag3)).toList().size(), "RuleImpl list size"); } } 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 5646ab426..f22abe47d 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 @@ -808,7 +808,7 @@ public class InboxOSGiTest extends JavaOSGiTest { .anyMatch(forThingUID(THING1_WITH_BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW)))); assertFalse(inbox.stream() .anyMatch(forThingUID(THING2_WITH_BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW)))); - assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()), + assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(), hasItems(THING_WITHOUT_BRIDGE, THING_WITH_OTHER_BRIDGE)); waitForAssert(() -> { assertThat(receivedEvents.size(), is(3)); @@ -845,7 +845,7 @@ public class InboxOSGiTest extends JavaOSGiTest { registry.add(BridgeBuilder.create(BRIDGE_THING_TYPE_UID, BRIDGE_THING_UID).build()); assertFalse(inbox.stream().anyMatch(forThingUID(BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW)))); - assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()), + assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(), hasItems(THING1_WITH_BRIDGE, THING2_WITH_BRIDGE, THING_WITHOUT_BRIDGE)); waitForAssert(() -> { assertThat(receivedEvents.size(), is(1)); @@ -879,7 +879,7 @@ public class InboxOSGiTest extends JavaOSGiTest { inbox.add(THING2_WITH_BRIDGE); inbox.add(THING_WITHOUT_BRIDGE); inbox.add(THING_WITH_OTHER_BRIDGE); - assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()), + assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(), hasItems(THING1_WITH_BRIDGE, THING2_WITH_BRIDGE, THING_WITHOUT_BRIDGE, THING_WITH_OTHER_BRIDGE)); registry.forceRemove(BRIDGE.getThingUID()); @@ -889,7 +889,7 @@ public class InboxOSGiTest extends JavaOSGiTest { .anyMatch(forThingUID(THING1_WITH_BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW)))); assertFalse(inbox.stream() .anyMatch(forThingUID(THING2_WITH_BRIDGE.getThingUID()).and(withFlag(DiscoveryResultFlag.NEW)))); - assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()), + assertThat(inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).toList(), hasItems(THING_WITHOUT_BRIDGE, THING_WITH_OTHER_BRIDGE)); }); } 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 487aff02b..e8b5071a4 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 @@ -19,7 +19,6 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -113,14 +112,14 @@ public class ProfileTypeResourceTest extends JavaTest { public void testGetAll() { Stream result = resource.getProfileTypes(null, null, null); - List list = result.collect(Collectors.toList()); + List list = result.toList(); assertThat(list.size(), is(4)); } @Test public void testGetProfileTypesForStateChannel1() { Stream result = resource.getProfileTypes(null, pt1ChannelType1UID.toString(), null); - List list = result.collect(Collectors.toList()); + List list = result.toList(); // should be both state profiles because the second state profile supports ALL item types on the channel side assertThat(list.size(), is(2)); @@ -133,7 +132,7 @@ public class ProfileTypeResourceTest extends JavaTest { @Test public void testGetProfileTypesForOtherChannel() { Stream result = resource.getProfileTypes(null, otherStateChannelTypeUID.toString(), null); - List list = result.collect(Collectors.toList()); + List list = result.toList(); // should be only the second state profile because the first one is restricted to another item type on the // channel side @@ -148,7 +147,7 @@ public class ProfileTypeResourceTest extends JavaTest { @Test public void testGetProfileTypesForTriggerChannel1() { Stream result = resource.getProfileTypes(null, pt3ChannelType1UID.toString(), null); - List list = result.collect(Collectors.toList()); + List list = result.toList(); // should be both trigger profiles because the second trigger profile supports ALL channel types assertThat(list.size(), is(2)); @@ -161,7 +160,7 @@ public class ProfileTypeResourceTest extends JavaTest { @Test public void testGetProfileTypesForTriggerChannel2() { Stream result = resource.getProfileTypes(null, otherTriggerChannelTypeUID.toString(), null); - List list = result.collect(Collectors.toList()); + List list = result.toList(); // should be only the second trigger profile because the first one is restricted to another channel type UID assertThat(list.size(), is(1)); diff --git a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest3.java b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest3.java index 7d5559156..13afd35b4 100644 --- a/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest3.java +++ b/itests/org.openhab.core.model.thing.tests/src/main/java/org/openhab/core/model/thing/test/hue/GenericThingProviderTest3.java @@ -12,7 +12,6 @@ */ package org.openhab.core.model.thing.test.hue; -import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -97,7 +96,7 @@ public class GenericThingProviderTest3 extends JavaOSGiTest { .withRequired(false).withDefault("hello world").build(), ConfigDescriptionParameterBuilder.create("testConf", ConfigDescriptionParameter.Type.TEXT) .withRequired(false).withDefault("bar").build()) - .collect(toList())) + .toList()) .build(); ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class); 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 f398598de..4f4a404f5 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 @@ -23,7 +23,6 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import javax.measure.Quantity; import javax.measure.quantity.Dimensionless; @@ -137,8 +136,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { itemRegistry.update(updatedItem); waitForAssert(() -> assertThat(events.size(), is(1))); - List stateChanges = events.stream().filter(ItemUpdatedEvent.class::isInstance) - .collect(Collectors.toList()); + List stateChanges = events.stream().filter(ItemUpdatedEvent.class::isInstance).toList(); assertThat(stateChanges.size(), is(1)); ItemUpdatedEvent change = (ItemUpdatedEvent) stateChanges.get(0); @@ -442,8 +440,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events.size(), is(2))); - List updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance) - .collect(Collectors.toList()); + List updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).toList(); assertThat(updates.size(), is(1)); GroupStateUpdatedEvent update = (GroupStateUpdatedEvent) updates.get(0); @@ -453,8 +450,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { .replace("{itemName}", groupItem.getName()))); assertThat(update.getItemState(), is(groupItem.getState())); - List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) - .collect(Collectors.toList()); + List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes.size(), is(1)); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); @@ -493,7 +489,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); List groupItemStateChangedEvents = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) - .collect(Collectors.toList()); + .toList(); assertThat(groupItemStateChangedEvents, hasSize(1)); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) groupItemStateChangedEvents.get(0); @@ -535,12 +531,11 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - List itemCommandEvents = events.stream().filter(ItemCommandEvent.class::isInstance) - .collect(Collectors.toList()); + List itemCommandEvents = events.stream().filter(ItemCommandEvent.class::isInstance).toList(); assertThat(itemCommandEvents, hasSize(2)); List groupItemStateChangedEvents = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) - .collect(Collectors.toList()); + .toList(); assertThat(groupItemStateChangedEvents, hasSize(0)); assertThat(groupItem.getState(), is(UnDefType.NULL)); @@ -565,12 +560,10 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) - .collect(Collectors.toList()); + List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes, hasSize(1)); - List updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance) - .collect(Collectors.toList()); + List updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).toList(); assertThat(updates, hasSize(1)); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); @@ -594,10 +587,10 @@ public class GroupItemOSGiTest extends JavaOSGiTest { assertThat(events, hasSize(2)); - changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList()); + changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes, hasSize(0)); - updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).collect(Collectors.toList()); + updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance).toList(); assertThat(updates, hasSize(2)); assertThat(groupItem.getState(), is(OnOffType.ON)); @@ -622,8 +615,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) - .collect(Collectors.toList()); + List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes, hasSize(1)); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); @@ -642,7 +634,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events, hasSize(2))); - changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList()); + changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes, hasSize(1)); change = (GroupItemStateChangedEvent) changes.get(0); @@ -756,8 +748,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events.size(), is(2))); - List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance) - .collect(Collectors.toList()); + List changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0); assertThat(change.getItemName(), is(groupItem.getName())); @@ -775,7 +766,7 @@ public class GroupItemOSGiTest extends JavaOSGiTest { waitForAssert(() -> assertThat(events.size(), is(2))); - changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).collect(Collectors.toList()); + changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList(); assertThat(changes.size(), is(1)); change = (GroupItemStateChangedEvent) changes.get(0); 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 f435ce58c..a07a05522 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 @@ -12,7 +12,6 @@ */ package org.openhab.core.items; -import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; @@ -132,7 +131,7 @@ public class ItemRegistryImplTest extends JavaTest { List items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG)); assertThat(items, hasSize(4)); - List itemNames = items.stream().map(Item::getName).collect(toList()); + List itemNames = items.stream().map(Item::getName).toList(); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME3)); @@ -144,7 +143,7 @@ public class ItemRegistryImplTest extends JavaTest { List items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG_UPPERCASE)); assertThat(items, hasSize(4)); - List itemNames = items.stream().map(Item::getName).collect(toList()); + List itemNames = items.stream().map(Item::getName).toList(); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME3)); @@ -156,7 +155,7 @@ public class ItemRegistryImplTest extends JavaTest { List items = new ArrayList<>(itemRegistry.getItemsByTagAndType("Switch", CAMERA_TAG)); assertThat(items, hasSize(2)); - List itemNames = items.stream().map(Item::getName).collect(toList()); + List itemNames = items.stream().map(Item::getName).toList(); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2)); } @@ -178,7 +177,7 @@ public class ItemRegistryImplTest extends JavaTest { List items = new ArrayList<>(itemRegistry.getItemsByTag(SwitchItem.class, CAMERA_TAG)); assertThat(items, hasSize(2)); - List itemNames = items.stream().map(GenericItem::getName).collect(toList()); + List itemNames = items.stream().map(GenericItem::getName).toList(); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1)); assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2)); } 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 c9e063191..05a9323a0 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 @@ -126,7 +126,7 @@ public class ThingFactoryTest extends JavaOSGiTest { ChannelDefinition cd1 = new ChannelDefinitionBuilder("channel1", channelType1.getUID()).build(); ChannelDefinition cd2 = new ChannelDefinitionBuilder("channel2", channelType2.getUID()).build(); - return Stream.of(cd1, cd2).collect(toList()); + return Stream.of(cd1, cd2).toList(); } @Test @@ -204,7 +204,7 @@ public class ThingFactoryTest extends JavaOSGiTest { .withMultiple(true).withLimitToOptions(true).build(); return ConfigDescriptionBuilder.create(uri) - .withParameters(Stream.of(p1, p2, p3, p4, p5, p6).collect(toList())).build(); + .withParameters(Stream.of(p1, p2, p3, p4, p5, p6).toList()).build(); } }); 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 f6e741584..d496e07c2 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 @@ -284,7 +284,7 @@ public class ChannelLinkNotifierOSGiTest extends JavaOSGiTest { private Thing createThing() { ThingUID thingUID = new ThingUID(THING_TYPE_UID, "thing" + thingCount++); List channels = IntStream.range(0, CHANNEL_COUNT).mapToObj(index -> createChannel(thingUID, index)) - .collect(Collectors.toList()); + .toList(); return ThingBuilder.create(THING_TYPE_UID, thingUID).withChannels(channels).build(); } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java index cd351a7c2..777d4a228 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/CommunicationManagerOSGiTest.java @@ -18,7 +18,6 @@ import static org.mockito.Mockito.*; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.measure.quantity.Temperature; @@ -196,8 +195,8 @@ public class CommunicationManagerOSGiTest extends JavaOSGiTest { }).when(profileFactoryMock).createProfile(isA(ProfileTypeUID.class), isA(ProfileCallback.class), isA(ProfileContext.class)); - when(profileFactoryMock.getSupportedProfileTypeUIDs()).thenReturn(Stream - .of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).collect(Collectors.toList())); + when(profileFactoryMock.getSupportedProfileTypeUIDs()) + .thenReturn(Stream.of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).toList()); manager.addProfileFactory(profileFactoryMock); manager.addProfileAdvisor(profileAdvisorMock); 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 b76c45ed8..0f678c972 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 @@ -702,8 +702,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { verify(eventPublisherMock, atLeast(SEQUENCE.length + 1)).post(eventCaptor.capture()); }); events.get().addAll(eventCaptor.getAllValues()); - List list = events.get().stream().filter(FirmwareUpdateProgressInfoEvent.class::isInstance) - .collect(Collectors.toList()); + List list = events.get().stream().filter(FirmwareUpdateProgressInfoEvent.class::isInstance).toList(); assertTrue(list.size() >= SEQUENCE.length); for (int i = 0; i < SEQUENCE.length; i++) { FirmwareUpdateProgressInfoEvent event = (FirmwareUpdateProgressInfoEvent) list.get(i); @@ -903,7 +902,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest { ArgumentCaptor eventCaptor = ArgumentCaptor.forClass(Event.class); verify(eventPublisherMock, atLeast(expectedEventCount)).post(eventCaptor.capture()); List allValues = eventCaptor.getAllValues().stream() - .filter(FirmwareUpdateResultInfoEvent.class::isInstance).collect(Collectors.toList()); + .filter(FirmwareUpdateResultInfoEvent.class::isInstance).toList(); assertEquals(expectedEventCount, allValues.size()); assertFailedFirmwareUpdate(THING1_UID, allValues.get(expectedEventCount - 1), text); }); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java index 9d5f044f0..c55b19fee 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkOSGiTest.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.AfterEach; @@ -154,7 +153,7 @@ public class ItemChannelLinkOSGiTest extends JavaOSGiTest { int removed = itemChannelLinkRegistry.removeLinksForItem(itemToRemove); assertThat(removed, is(1)); - assertThat(itemChannelLinkRegistry.stream().map(ItemChannelLink::getItemName).collect(Collectors.toList()), + assertThat(itemChannelLinkRegistry.stream().map(ItemChannelLink::getItemName).toList(), not(hasItem(itemToRemove))); assertThat(itemChannelLinkRegistry.getAll(), hasSize(BULK_ITEM_COUNT * BULK_THING_COUNT * BULK_CHANNEL_COUNT - 1)); @@ -169,7 +168,7 @@ public class ItemChannelLinkOSGiTest extends JavaOSGiTest { assertThat(removed, is(BULK_CHANNEL_COUNT)); assertThat(itemChannelLinkRegistry.stream().map(ItemChannelLink::getLinkedUID).map(ChannelUID::getThingUID) - .collect(Collectors.toList()), not(hasItem(thingToRemove))); + .toList(), not(hasItem(thingToRemove))); assertThat(itemChannelLinkRegistry.getAll(), hasSize((BULK_ITEM_COUNT * BULK_THING_COUNT - 1) * BULK_CHANNEL_COUNT)); } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/SystemChannelsInChannelGroupsTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/SystemChannelsInChannelGroupsTest.java index 84bb53a2c..f7064f080 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/SystemChannelsInChannelGroupsTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/xml/test/SystemChannelsInChannelGroupsTest.java @@ -16,7 +16,6 @@ import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; -import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.jupiter.api.BeforeEach; @@ -68,7 +67,7 @@ public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest { public void thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions() throws Exception { try (final AutoCloseable unused = loadedTestBundle()) { List thingTypes = thingTypeProvider.getThingTypes(null).stream() - .filter(it -> "wireless-router".equals(it.getUID().getId())).collect(Collectors.toList()); + .filter(it -> "wireless-router".equals(it.getUID().getId())).toList(); assertThat(thingTypes.size(), is(1)); List channelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes(); @@ -82,17 +81,13 @@ public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest { List myChannel = channelDefs.stream().filter( it -> "test".equals(it.getId()) && "system:my-channel".equals(it.getChannelTypeUID().getAsString())) - .collect(Collectors.toList()); + .toList(); - List sigStr = channelDefs.stream() - .filter(it -> "sigstr".equals(it.getId()) - && "system:signal-strength".equals(it.getChannelTypeUID().getAsString())) - .collect(Collectors.toList()); + List sigStr = channelDefs.stream().filter(it -> "sigstr".equals(it.getId()) + && "system:signal-strength".equals(it.getChannelTypeUID().getAsString())).toList(); - List lowBat = channelDefs.stream() - .filter(it -> "lowbat".equals(it.getId()) - && "system:low-battery".equals(it.getChannelTypeUID().getAsString())) - .collect(Collectors.toList()); + List lowBat = channelDefs.stream().filter(it -> "lowbat".equals(it.getId()) + && "system:low-battery".equals(it.getChannelTypeUID().getAsString())).toList(); assertThat(myChannel.size(), is(1)); assertThat(sigStr.size(), is(1)); diff --git a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfoReader.java b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfoReader.java index 0462066d2..4f1c88459 100644 --- a/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfoReader.java +++ b/tools/i18n-plugin/src/main/java/org/openhab/core/tools/i18n/plugin/BundleInfoReader.java @@ -19,7 +19,6 @@ import java.nio.file.Path; import java.util.List; import java.util.Map; import java.util.function.Predicate; -import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -144,7 +143,7 @@ public class BundleInfoReader { if (Files.exists(modulePath)) { try (Stream files = Files.walk(modulePath)) { List moduleTypes = files.filter(isJsonFile).flatMap(this::readJsonElementsFromFile) - .map(JsonElement::getAsJsonObject).collect(Collectors.toList()); + .map(JsonElement::getAsJsonObject).toList(); if (!moduleTypes.isEmpty()) { bundleInfo.setModuleTypesJson(moduleTypes); } @@ -157,7 +156,7 @@ public class BundleInfoReader { if (Files.exists(template)) { try (Stream files = Files.walk(template)) { List ruleTemplates = files.filter(isJsonFile).flatMap(this::readJsonElementsFromFile) - .map(JsonElement::getAsJsonObject).collect(Collectors.toList()); + .map(JsonElement::getAsJsonObject).toList(); if (!ruleTemplates.isEmpty()) { bundleInfo.setRuleTemplateJson(ruleTemplates); }