|
19 | 19 | import java.util.Collections;
|
20 | 20 | import java.util.Iterator;
|
21 | 21 | import java.util.List;
|
22 |
| -import java.util.stream.Collectors; |
23 | 22 |
|
24 | 23 | import org.springframework.core.convert.converter.Converter;
|
25 | 24 | import org.springframework.data.mapping.PersistentProperty;
|
|
28 | 27 | import org.springframework.lang.Nullable;
|
29 | 28 | import org.springframework.util.Assert;
|
30 | 29 | import org.springframework.util.ObjectUtils;
|
31 |
| -import org.springframework.util.StringUtils; |
32 | 30 |
|
33 | 31 | /**
|
34 | 32 | * Abstraction of a path of {@link PersistentProperty}s.
|
@@ -111,10 +109,27 @@ public String toPath(String delimiter, Converter<? super P, String> converter) {
|
111 | 109 | Assert.hasText(delimiter, "Delimiter must not be null or empty");
|
112 | 110 | Assert.notNull(converter, "Converter must not be null");
|
113 | 111 |
|
114 |
| - return properties.stream() // |
115 |
| - .map(converter::convert) // |
116 |
| - .filter(StringUtils::hasText) // |
117 |
| - .collect(Collectors.joining(delimiter)); |
| 112 | + StringBuilder builder = null; |
| 113 | + for (P property : properties) { |
| 114 | + |
| 115 | + String converted = converter.convert(property); |
| 116 | + |
| 117 | + if (ObjectUtils.isEmpty(converted)) { |
| 118 | + continue; |
| 119 | + } |
| 120 | + |
| 121 | + if (builder == null) { |
| 122 | + builder = new StringBuilder(); |
| 123 | + } |
| 124 | + |
| 125 | + if (!builder.isEmpty()) { |
| 126 | + builder.append(delimiter); |
| 127 | + } |
| 128 | + |
| 129 | + builder.append(converted); |
| 130 | + } |
| 131 | + |
| 132 | + return builder == null ? "" : builder.toString(); |
118 | 133 | }
|
119 | 134 |
|
120 | 135 | @Override
|
|
0 commit comments