mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Use String.join instead of Collectors.joining (#3973)
* Use String.join instead of Collectors.joining String.join results in less code when joining an Iterable or Array. Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
+1
-2
@@ -16,7 +16,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
@@ -122,7 +121,7 @@ public class AutomationCommandsPluggable extends AutomationCommands implements C
|
|||||||
@Override
|
@Override
|
||||||
public void execute(String[] args, Console console) {
|
public void execute(String[] args, Console console) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
console.println(getUsages().stream().collect(Collectors.joining("\n")));
|
console.println(String.join("\n", getUsages()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -65,7 +65,7 @@ public class MetadataSelectorMatcher {
|
|||||||
.distinct() //
|
.distinct() //
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
String namespacePattern = originalNamespaces.stream().collect(Collectors.joining("|"));
|
String namespacePattern = String.join("|", originalNamespaces);
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("(" + namespacePattern + ")$");
|
Pattern pattern = Pattern.compile("(" + namespacePattern + ")$");
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -15,7 +15,6 @@ package org.openhab.core.io.rest.internal.filter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.ws.rs.container.ContainerRequestContext;
|
import javax.ws.rs.container.ContainerRequestContext;
|
||||||
import javax.ws.rs.container.ContainerResponseContext;
|
import javax.ws.rs.container.ContainerResponseContext;
|
||||||
@@ -77,8 +76,7 @@ public class CorsFilter implements ContainerResponseFilter {
|
|||||||
static final List<String> ACCEPTED_HTTP_METHODS_LIST = List.of(HTTP_GET_METHOD, HTTP_POST_METHOD, HTTP_PUT_METHOD,
|
static final List<String> ACCEPTED_HTTP_METHODS_LIST = List.of(HTTP_GET_METHOD, HTTP_POST_METHOD, HTTP_PUT_METHOD,
|
||||||
HTTP_DELETE_METHOD, HTTP_HEAD_METHOD, HTTP_OPTIONS_METHOD);
|
HTTP_DELETE_METHOD, HTTP_HEAD_METHOD, HTTP_OPTIONS_METHOD);
|
||||||
|
|
||||||
static final String ACCEPTED_HTTP_METHODS = ACCEPTED_HTTP_METHODS_LIST.stream()
|
static final String ACCEPTED_HTTP_METHODS = String.join(HEADERS_SEPARATOR, ACCEPTED_HTTP_METHODS_LIST);
|
||||||
.collect(Collectors.joining(HEADERS_SEPARATOR));
|
|
||||||
|
|
||||||
private final transient Logger logger = LoggerFactory.getLogger(CorsFilter.class);
|
private final transient Logger logger = LoggerFactory.getLogger(CorsFilter.class);
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -114,8 +114,7 @@ public class SerialPortUtil {
|
|||||||
serialPorts = new HashSet<>();
|
serialPorts = new HashSet<>();
|
||||||
}
|
}
|
||||||
if (serialPorts.add(port)) {
|
if (serialPorts.add(port)) {
|
||||||
return serialPorts.stream().collect(Collectors.joining(pathSeparator)); // see
|
return String.join(pathSeparator, serialPorts); // see RXTXCommDriver#addSpecifiedPorts
|
||||||
// RXTXCommDriver#addSpecifiedPorts
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -24,7 +24,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.eclipse.emf.common.util.URI;
|
import org.eclipse.emf.common.util.URI;
|
||||||
import org.eclipse.emf.ecore.EObject;
|
import org.eclipse.emf.ecore.EObject;
|
||||||
@@ -281,7 +280,7 @@ public class ModelRepositoryImpl implements ModelRepository {
|
|||||||
}
|
}
|
||||||
if (!warnings.isEmpty()) {
|
if (!warnings.isEmpty()) {
|
||||||
logger.info("Validation issues found in configuration model '{}', using it anyway:\n{}", name,
|
logger.info("Validation issues found in configuration model '{}', using it anyway:\n{}", name,
|
||||||
warnings.stream().collect(Collectors.joining("\n")));
|
String.join("\n", warnings));
|
||||||
}
|
}
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
// see https://github.com/eclipse/smarthome/issues/3335
|
// see https://github.com/eclipse/smarthome/issues/3335
|
||||||
|
|||||||
+5
-8
@@ -12,9 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.core.model.thing.valueconverter;
|
package org.openhab.core.model.thing.valueconverter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.eclipse.xtext.conversion.IValueConverter;
|
import org.eclipse.xtext.conversion.IValueConverter;
|
||||||
import org.eclipse.xtext.conversion.ValueConverterException;
|
import org.eclipse.xtext.conversion.ValueConverterException;
|
||||||
import org.eclipse.xtext.nodemodel.INode;
|
import org.eclipse.xtext.nodemodel.INode;
|
||||||
@@ -30,14 +27,14 @@ import org.openhab.core.thing.UID;
|
|||||||
*/
|
*/
|
||||||
public class UIDtoStringConverter implements IValueConverter<String> {
|
public class UIDtoStringConverter implements IValueConverter<String> {
|
||||||
|
|
||||||
private static final String SEPERATOR = ":";
|
private static final String SEPARATOR = ":";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toValue(final String string, INode node) throws ValueConverterException {
|
public String toValue(final String string, INode node) throws ValueConverterException {
|
||||||
if (string == null) {
|
if (string == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String[] ids = string.split(SEPERATOR);
|
String[] ids = string.split(SEPARATOR);
|
||||||
for (int i = 0; i < ids.length; i++) {
|
for (int i = 0; i < ids.length; i++) {
|
||||||
String id = ids[i];
|
String id = ids[i];
|
||||||
if (id != null && id.startsWith("\"") && id.endsWith("\"")) {
|
if (id != null && id.startsWith("\"") && id.endsWith("\"")) {
|
||||||
@@ -48,7 +45,7 @@ public class UIDtoStringConverter implements IValueConverter<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Arrays.stream(ids).collect(Collectors.joining(SEPERATOR));
|
return String.join(SEPARATOR, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,7 +53,7 @@ public class UIDtoStringConverter implements IValueConverter<String> {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new ValueConverterException("Value may not be null.", null, null);
|
throw new ValueConverterException("Value may not be null.", null, null);
|
||||||
}
|
}
|
||||||
String[] ids = value.split(SEPERATOR);
|
String[] ids = value.split(SEPARATOR);
|
||||||
for (int i = 0; i < ids.length; i++) {
|
for (int i = 0; i < ids.length; i++) {
|
||||||
String id = ids[i];
|
String id = ids[i];
|
||||||
if (id != null && !id.matches("[A-Za-z0-9_]*")) {
|
if (id != null && !id.matches("[A-Za-z0-9_]*")) {
|
||||||
@@ -65,7 +62,7 @@ public class UIDtoStringConverter implements IValueConverter<String> {
|
|||||||
ids[i] = toEscapedString(id);
|
ids[i] = toEscapedString(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Arrays.stream(ids).collect(Collectors.joining(SEPERATOR));
|
return String.join(SEPARATOR, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String toEscapedString(String value) {
|
protected String toEscapedString(String value) {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import java.util.Set;
|
|||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
@@ -338,13 +337,13 @@ public abstract class GenericItem implements ActiveItem {
|
|||||||
if (!getTags().isEmpty()) {
|
if (!getTags().isEmpty()) {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append("Tags=[");
|
sb.append("Tags=[");
|
||||||
sb.append(getTags().stream().collect(Collectors.joining(", ")));
|
sb.append(String.join(", ", getTags()));
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
}
|
}
|
||||||
if (!getGroupNames().isEmpty()) {
|
if (!getGroupNames().isEmpty()) {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append("Groups=[");
|
sb.append("Groups=[");
|
||||||
sb.append(getGroupNames().stream().collect(Collectors.joining(", ")));
|
sb.append(String.join(", ", getGroupNames()));
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
}
|
}
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
|
|||||||
@@ -342,13 +342,13 @@ public class GroupItem extends GenericItem implements StateChangeListener, Metad
|
|||||||
if (!getTags().isEmpty()) {
|
if (!getTags().isEmpty()) {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append("Tags=[");
|
sb.append("Tags=[");
|
||||||
sb.append(getTags().stream().collect(Collectors.joining(", ")));
|
sb.append(String.join(", ", getTags()));
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
}
|
}
|
||||||
if (!getGroupNames().isEmpty()) {
|
if (!getGroupNames().isEmpty()) {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append("Groups=[");
|
sb.append("Groups=[");
|
||||||
sb.append(getGroupNames().stream().collect(Collectors.joining(", ")));
|
sb.append(String.join(", ", getGroupNames()));
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
}
|
}
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
|
|||||||
+1
-3
@@ -28,7 +28,6 @@ import java.nio.file.attribute.FileTime;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
@@ -1057,8 +1056,7 @@ public class ConfigDispatcherOSGiTest extends JavaOSGiTest {
|
|||||||
private void truncateLastLine(File file) throws IOException {
|
private void truncateLastLine(File file) throws IOException {
|
||||||
final Path path = file.toPath();
|
final Path path = file.toPath();
|
||||||
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
|
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
|
||||||
Files.writeString(path, lines.subList(0, lines.size() - 1).stream().collect(Collectors.joining("\n")),
|
Files.writeString(path, String.join("\n", lines.subList(0, lines.size() - 1)), StandardCharsets.UTF_8);
|
||||||
StandardCharsets.UTF_8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable String getLastModifiedValueForPoperty(String path, String property) {
|
private @Nullable String getLastModifiedValueForPoperty(String path, String property) {
|
||||||
|
|||||||
Reference in New Issue
Block a user