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 <github@maindrain.net>
This commit is contained in:
Wouter Born 2023-10-09 09:20:08 +02:00 committed by GitHub
parent 2794c973d3
commit 09b3160a55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
93 changed files with 294 additions and 471 deletions

View File

@ -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<String> 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);

View File

@ -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<String> installedAddons = addons.stream().map(Addon::getUid).collect(Collectors.toList());
List<String> installedAddons = addons.stream().map(Addon::getUid).toList();
if (remoteEnabled()) {
List<Addon> remoteAddons = Objects.requireNonNullElse(cachedRemoteAddons.getValue(), List.of());

View File

@ -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<DiscourseUser> users = pages.stream().flatMap(p -> Stream.of(p.users)).collect(Collectors.toList());
List<DiscourseUser> 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)))

View File

@ -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<PropertyName> 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));
}

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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<String> 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<String> 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!

View File

@ -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<ParameterOption> 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

View File

@ -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;
}

View File

@ -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<RuleExecution> 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) {

View File

@ -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<RuleTemplateDTO> result = templateRegistry.getAll(locale).stream()
.map(template -> RuleTemplateDTOMapper.map(template)).collect(Collectors.toList());
.map(template -> RuleTemplateDTOMapper.map(template)).toList();
return Response.ok(result).build();
}

View File

@ -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;

View File

@ -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 <T extends WrappedModule, U extends Module> List<T> map(final List<U> in, Function<U, T> factory,
final Collection<WrappedModule<Module, ModuleHandler>> coll) {
// explicit cast to List <? extends T> as JDK compiler complains
return Collections.unmodifiableList((List<? extends T>) 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;

View File

@ -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<Object> values = (List<Object>) List.of(defaultValue.split(DEFAULT_LIST_DELIMITER))
.stream() //
List<Object> values = (List<Object>) 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 {

View File

@ -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<TimeZone> byOffset = (t1, t2) -> t1.getRawOffset() - t2.getRawOffset();
Comparator<TimeZone> 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();
}
}

View File

@ -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<CidrAddress> 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<String> 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;
}

View File

@ -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<ConfigStatusMessage> filterConfigStatusMessages(
Collection<ConfigStatusMessage> configStatusMessages, Predicate<? super ConfigStatusMessage> predicate) {
return configStatusMessages.stream().filter(predicate).collect(Collectors.toList());
return configStatusMessages.stream().filter(predicate).toList();
}
@Override

View File

@ -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<Boolean> expectedList = Stream.of(true, false, true).collect(toList());
List<Boolean> 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)));
}
}

View File

@ -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<ThingS
private void ignoreInInbox(ThingTypeUID thingtypeUID, String representationValue) {
List<DiscoveryResult> 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<ThingS
private void removeFromInbox(ThingTypeUID thingtypeUID, String representationValue) {
List<DiscoveryResult> 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);

View File

@ -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<DiscoveryResult> results = stream().filter(forThingUID(thingUID)).collect(Collectors.toList());
List<DiscoveryResult> 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<String> 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<DiscoveryResult> getAll() {
return stream().collect(Collectors.toList());
return stream().toList();
}
@Override

View File

@ -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<DiscoveryResult> results = inbox.stream().filter(forThingUID(thingUID))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(forThingUID(thingUID))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(forThingTypeUID(thingTypeUID))
.collect(Collectors.toList());
.toList();
if (results.isEmpty()) {
console.println("No matching inbox entry could be found.");
} else {

View File

@ -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))));
}
}

View File

@ -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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
.collect(Collectors.toList());
List<DiscoveryResult> 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<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED))
.collect(Collectors.toList());
List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).toList();
assertThat(results.size(), is(1));
assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2)));

View File

@ -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<String> values = Arrays.asList(value //
//
List<String> 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<String> 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) {

View File

@ -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;
}

View File

@ -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<ParameterOption> actual = provider.getParameterOptions(URI.create("uri"), "serialPort", SERIAL_PORT,
null);
Collection<ParameterOption> expected = Arrays.stream(serialPortIdentifiers)
.map(id -> new ParameterOption(id, id)).collect(Collectors.toList());
.map(id -> new ParameterOption(id, id)).toList();
assertThat(actual, is(expected));
}

View File

@ -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<Holiday> 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

View File

@ -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<String> 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<Class<?>> enums = Stream.of(localDataTypeGetter.apply(item)).filter(Class::isEnum);
Stream<? super Enum<?>> enumConstants = enums.flatMap(
t -> Stream.of(Objects.requireNonNull(((Class<? extends Enum<?>>) 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;
}

View File

@ -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]);

View File

@ -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<List<?>> constructAlternativeNames(String... alternatives) {
Collection<List<?>> 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;

View File

@ -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);
}

View File

@ -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<String> acceptedMediaTypes = Arrays.stream(Objects.requireNonNullElse(mediaType, "").split(","))
.map(String::trim).collect(Collectors.toList());
.map(String::trim).toList();
Item item = getItem(itemname);

View File

@ -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<EnrichedItemChannelLinkDTO> 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);

View File

@ -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());

View File

@ -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<HumanLanguageInterpreterDTO> 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<VoiceDTO> dtos = voiceManager.getAllVoices().stream().map(VoiceMapper::map).collect(Collectors.toList());
List<VoiceDTO> dtos = voiceManager.getAllVoices().stream().map(VoiceMapper::map).toList();
return Response.ok(dtos).build();
}

View File

@ -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<String> fieldList = Stream.of(fields.split(",")).map(field -> field.trim()).collect(Collectors.toList());
List<String> fieldList = Stream.of(fields.split(",")).map(String::trim).toList();
return itemStream.map(dto -> {
for (Field field : dto.getClass().getFields()) {
if (!fieldList.contains(field.getName())) {

View File

@ -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]);
}
/**

View File

@ -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<Object[]> filteredTestData(ValueType type) {

View File

@ -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<Object[]> 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")

View File

@ -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<Object[]> 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<Object[]> dataWithByteVariations() {

View File

@ -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<String> MAX_REGISTERS = IntStream.range(0, MAX_REGISTERS_WRITE_COUNT).mapToObj(i -> "1")
.collect(Collectors.toList());
.toList();
private static final List<String> 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<String> MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT).mapToObj(i -> "1")
.collect(Collectors.toList());
private static final List<String> MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT).mapToObj(i -> "1").toList();
private static final List<String> OVER_MAX_COILS = IntStream.range(0, MAX_BITS_WRITE_COUNT + 1).mapToObj(i -> "1")
.collect(Collectors.toList());
.toList();
@Test
public void testEmptyArray() {

View File

@ -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<SerialPortProvider> getPortCreators() {

View File

@ -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:

View File

@ -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<String> ADDON_TYPES = AddonType.DEFAULT_TYPES.stream().map(AddonType::getId)
.collect(Collectors.toList());
public static final List<String> ADDON_TYPES = AddonType.DEFAULT_TYPES.stream().map(AddonType::getId).toList();
private final Logger logger = LoggerFactory.getLogger(FeatureInstaller.class);

View File

@ -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<String, String> 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();
}
}

View File

@ -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<UserPrincipal> 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<RolePrincipal> 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();
}

View File

@ -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();
}
}

View File

@ -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<Issue> getValidationErrors(final EObject model) {
final List<Issue> 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

View File

@ -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 <T extends State> List<String> 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 <T extends State> List<String> getAcceptedDataTypeNames(Item item) {
return item.getAcceptedDataTypes().stream().map(t -> t.getSimpleName()).collect(Collectors.toList());
return item.getAcceptedDataTypes().stream().map(Class::getSimpleName).toList();
}
/**

View File

@ -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<ItemChannel
@Override
public Collection<ItemChannelLink> getAll() {
return itemChannelLinkMap.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
return itemChannelLinkMap.values().stream().flatMap(Collection::stream).toList();
}
}

View File

@ -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<PersistenceItemConfiguration> itemConfigs = getMatchingConfigurations(strategy)
.collect(Collectors.toList());
List<PersistenceItemConfiguration> itemConfigs = getMatchingConfigurations(strategy).toList();
jobs.add(scheduler.schedule(() -> persistJob(itemConfigs), cronExpression));
logger.debug("Scheduled strategy {} with cron expression {} for service {}",

View File

@ -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;
}

View File

@ -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<ComponentDescriptionDTO> 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<Bundle> 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()]);
}

View File

@ -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<T>) 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
*/

View File

@ -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();

View File

@ -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

View File

@ -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<Firmware> result = firmwareProvider.getFirmwares(thing, loc);
if (result != null) {
List<Firmware> 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(

View File

@ -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) {

View File

@ -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<ProfileType> 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

View File

@ -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<ThingTy
return Collections.emptyList();
}
return Arrays.stream(extensible.split(",")).map(String::trim).collect(toList());
return Arrays.stream(extensible.split(",")).map(String::trim).toList();
}
protected @Nullable String readCategory(NodeIterator nodeIterator) {

View File

@ -12,7 +12,6 @@
*/
package org.openhab.core.thing.util;
import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
@ -138,10 +137,11 @@ public class ThingHelperTest {
.build();
assertThrows(IllegalArgumentException.class,
() -> ThingHelper.addChannelsToThing(thing,
() -> ThingHelper
.addChannelsToThing(thing,
Stream.of(ChannelBuilder.create(new ChannelUID(thingUID, "channel2"), "").build(),
ChannelBuilder.create(new ChannelUID(thingUID, "channel3"), "").build())
.collect(toList())));
.toList()));
}
@Test

View File

@ -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<T> implements Transforma
*/
protected List<String> 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 {

View File

@ -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<Transformation,
@Override
public Collection<Transformation> getTransformations(Collection<String> 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)

View File

@ -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() {

View File

@ -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(

View File

@ -500,7 +500,7 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider, Dia
@Override
public List<DialogContext> 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(),
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());
.toList();
}
}
return null;

View File

@ -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<String> list) {
this.list = Collections.unmodifiableList(new ArrayList<>(list));
this.list = List.copyOf(list);
this.head = 0;
this.tail = list.size() - 1;
}

View File

@ -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<K>
@Override
public Collection<E> getAll() {
return (Collection<E>) storage.getKeys().stream().map(this::getElement).filter(Objects::nonNull)
.collect(Collectors.toList());
return (Collection<E>) storage.getKeys().stream().map(this::getElement).filter(Objects::nonNull).toList();
}
@Override

View File

@ -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<Item, String, ItemProvide
// don't use #initialize and retain order of items in groups:
List<String> oldNames = oldItem.getGroupNames();
List<String> newNames = item.getGroupNames();
List<String> commonNames = oldNames.stream().filter(newNames::contains).collect(toList());
List<String> 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);
}

View File

@ -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);
}

View File

@ -116,7 +116,7 @@ public abstract class GenericItem implements ActiveItem {
@Override
public List<String> getGroupNames() {
return Collections.unmodifiableList(new ArrayList<>(groupNames));
return List.copyOf(groupNames);
}
/**

View File

@ -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<String> constituents = Arrays.stream(value.split(",")).map(String::trim).collect(Collectors.toList());
List<String> 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));

View File

@ -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<String> elements = Arrays.stream(value.split(",")).map(String::trim).collect(Collectors.toList());
List<String> 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) {

View File

@ -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) {

View File

@ -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<String> 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<CidrAddress> added = newInterfaceAddresses.stream()
.filter(newInterfaceAddr -> !lastKnownInterfaceAddresses.contains(newInterfaceAddr))
.collect(Collectors.toList());
.filter(newInterfaceAddr -> !lastKnownInterfaceAddresses.contains(newInterfaceAddr)).toList();
// Look for removed addresses to notify
List<CidrAddress> removed = lastKnownInterfaceAddresses.stream()
.filter(lastKnownInterfaceAddr -> !newInterfaceAddresses.contains(lastKnownInterfaceAddr))
.collect(Collectors.toList());
.filter(lastKnownInterfaceAddr -> !newInterfaceAddresses.contains(lastKnownInterfaceAddr)).toList();
lastKnownInterfaceAddresses = newInterfaceAddresses;
if (!added.isEmpty() || !removed.isEmpty()) {
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()));
LOGGER.debug("removed {} network interfaces: {}", removed.size(),
Arrays.deepToString(removed.toArray()));
}
notifyListeners(added, removed);
}

View File

@ -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) {

View File

@ -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<Action> actions = List.of(ModuleBuilder.createAction().withId("ItemPostCommandAction" + random)
.withTypeUID("core.ItemCommandAction").withConfiguration(actionConfig).build());

View File

@ -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<RuleExecution> executions = ruleEngine.simulateRuleExecutions(from, until).collect(Collectors.toList());
List<RuleExecution> 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.

View File

@ -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<Event> stateEvents = ruleEvents.stream().filter(e -> "openhab/rules/myRule21/state".equals(e.getTopic()))
.collect(Collectors.toList());
.toList();
assertThat(stateEvents, is(notNullValue()));
Optional<Event> runningEvent = stateEvents.stream()
.filter(e -> ((RuleStatusInfoEvent) e).getStatusInfo().getStatus() == RuleStatus.RUNNING).findFirst();

View File

@ -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<Rule> 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");
}
}

View File

@ -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));
});
}

View File

@ -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<ProfileTypeDTO> result = resource.getProfileTypes(null, null, null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> list = result.toList();
assertThat(list.size(), is(4));
}
@Test
public void testGetProfileTypesForStateChannel1() {
Stream<ProfileTypeDTO> result = resource.getProfileTypes(null, pt1ChannelType1UID.toString(), null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> 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<ProfileTypeDTO> result = resource.getProfileTypes(null, otherStateChannelTypeUID.toString(), null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> 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<ProfileTypeDTO> result = resource.getProfileTypes(null, pt3ChannelType1UID.toString(), null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> 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<ProfileTypeDTO> result = resource.getProfileTypes(null, otherTriggerChannelTypeUID.toString(), null);
List<ProfileTypeDTO> list = result.collect(Collectors.toList());
List<ProfileTypeDTO> 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));

View File

@ -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);

View File

@ -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<Event> stateChanges = events.stream().filter(ItemUpdatedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> 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<Event> updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> 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<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> 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<Event> 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<Event> itemCommandEvents = events.stream().filter(ItemCommandEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> itemCommandEvents = events.stream().filter(ItemCommandEvent.class::isInstance).toList();
assertThat(itemCommandEvents, hasSize(2));
List<Event> 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<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance).toList();
assertThat(changes, hasSize(1));
List<Event> updates = events.stream().filter(GroupStateUpdatedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> 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<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> 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<Event> changes = events.stream().filter(GroupItemStateChangedEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> 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);

View File

@ -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<Item> items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG));
assertThat(items, hasSize(4));
List<String> itemNames = items.stream().map(Item::getName).collect(toList());
List<String> 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<Item> items = new ArrayList<>(itemRegistry.getItemsByTag(CAMERA_TAG_UPPERCASE));
assertThat(items, hasSize(4));
List<String> itemNames = items.stream().map(Item::getName).collect(toList());
List<String> 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<Item> items = new ArrayList<>(itemRegistry.getItemsByTagAndType("Switch", CAMERA_TAG));
assertThat(items, hasSize(2));
List<String> itemNames = items.stream().map(Item::getName).collect(toList());
List<String> 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<SwitchItem> items = new ArrayList<>(itemRegistry.getItemsByTag(SwitchItem.class, CAMERA_TAG));
assertThat(items, hasSize(2));
List<String> itemNames = items.stream().map(GenericItem::getName).collect(toList());
List<String> itemNames = items.stream().map(GenericItem::getName).toList();
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME1));
assertThat(itemNames, hasItem(CAMERA_ITEM_NAME2));
}

View File

@ -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();
}
});

View File

@ -284,7 +284,7 @@ public class ChannelLinkNotifierOSGiTest extends JavaOSGiTest {
private Thing createThing() {
ThingUID thingUID = new ThingUID(THING_TYPE_UID, "thing" + thingCount++);
List<Channel> 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();
}

View File

@ -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);

View File

@ -702,8 +702,7 @@ public class FirmwareUpdateServiceTest extends JavaOSGiTest {
verify(eventPublisherMock, atLeast(SEQUENCE.length + 1)).post(eventCaptor.capture());
});
events.get().addAll(eventCaptor.getAllValues());
List<Event> list = events.get().stream().filter(FirmwareUpdateProgressInfoEvent.class::isInstance)
.collect(Collectors.toList());
List<Event> 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<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventPublisherMock, atLeast(expectedEventCount)).post(eventCaptor.capture());
List<Event> 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);
});

View File

@ -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));
}

View File

@ -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<ThingType> 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<ChannelGroupType> channelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes();
@ -82,17 +81,13 @@ public class SystemChannelsInChannelGroupsTest extends JavaOSGiTest {
List<ChannelDefinition> myChannel = channelDefs.stream().filter(
it -> "test".equals(it.getId()) && "system:my-channel".equals(it.getChannelTypeUID().getAsString()))
.collect(Collectors.toList());
.toList();
List<ChannelDefinition> sigStr = channelDefs.stream()
.filter(it -> "sigstr".equals(it.getId())
&& "system:signal-strength".equals(it.getChannelTypeUID().getAsString()))
.collect(Collectors.toList());
List<ChannelDefinition> sigStr = channelDefs.stream().filter(it -> "sigstr".equals(it.getId())
&& "system:signal-strength".equals(it.getChannelTypeUID().getAsString())).toList();
List<ChannelDefinition> lowBat = channelDefs.stream()
.filter(it -> "lowbat".equals(it.getId())
&& "system:low-battery".equals(it.getChannelTypeUID().getAsString()))
.collect(Collectors.toList());
List<ChannelDefinition> 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));

View File

@ -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<Path> files = Files.walk(modulePath)) {
List<JsonObject> 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<Path> files = Files.walk(template)) {
List<JsonObject> ruleTemplates = files.filter(isJsonFile).flatMap(this::readJsonElementsFromFile)
.map(JsonElement::getAsJsonObject).collect(Collectors.toList());
.map(JsonElement::getAsJsonObject).toList();
if (!ruleTemplates.isEmpty()) {
bundleInfo.setRuleTemplateJson(ruleTemplates);
}