Skip to content

Commit af3f2d6

Browse files
committed
Polishing.
Tweak Javadoc. Refine tests. See #2491
1 parent ddeb70c commit af3f2d6

File tree

2 files changed

+37
-44
lines changed

2 files changed

+37
-44
lines changed

src/main/java/org/springframework/data/mapping/PropertyPath.java

+27-40
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,13 @@ public TypeInformation<?> getOwningType() {
108108
}
109109

110110
/**
111-
* Returns the first part of the {@link PropertyPath}.
111+
* Returns the first part of the {@link PropertyPath}. For example:
112112
*
113-
* <pre>
114-
* {@code
113+
* <pre class="code">
115114
* PropertyPath.from("a.b.c", Some.class).getSegment();
116-
* }
117115
* </pre>
118116
*
119-
* will result in {@code "a"}
117+
* results in {@code a}.
120118
*
121119
* @return the name will never be {@literal null}.
122120
*/
@@ -150,10 +148,10 @@ public Class<?> getLeafType() {
150148
}
151149

152150
/**
153-
* Returns the type of the property will return the plain resolved type for simple properties, the component type for
154-
* any {@link Iterable} or the value type of a {@link java.util.Map} if the property is one.
151+
* Returns the actual type of the property. Will return the plain resolved type for simple properties, the component
152+
* type for any {@link Iterable} or the value type of a {@link java.util.Map}.
155153
*
156-
* @return
154+
* @return the actual type of the property.
157155
*/
158156
public Class<?> getType() {
159157
return this.actualTypeInformation.getType();
@@ -164,15 +162,13 @@ public TypeInformation<?> getTypeInformation() {
164162
}
165163

166164
/**
167-
* Returns the {@link PropertyPath} path that results from removing the first element of the current one.
165+
* Returns the {@link PropertyPath} path that results from removing the first element of the current one. For example:
168166
*
169-
* <pre>
170-
* {@code
171-
* System.out.println(PropertyPath.from("a.b.c", Some.class).next().toDotPath());
172-
* }
167+
* <pre class="code">
168+
* PropertyPath.from("a.b.c", Some.class).next().toDotPath();
173169
* </pre>
174170
*
175-
* Will result in the output: {@code b.c}
171+
* results in the output: {@code b.c}
176172
*
177173
* @return the next nested {@link PropertyPath} or {@literal null} if no nested {@link PropertyPath} available.
178174
* @see #hasNext()
@@ -195,7 +191,7 @@ public boolean hasNext() {
195191
/**
196192
* Returns the {@link PropertyPath} in dot notation.
197193
*
198-
* @return
194+
* @return the {@link PropertyPath} in dot notation.
199195
*/
200196
public String toDotPath() {
201197

@@ -209,7 +205,7 @@ public String toDotPath() {
209205
/**
210206
* Returns whether the {@link PropertyPath} is actually a collection.
211207
*
212-
* @return
208+
* @return {@literal true} whether the {@link PropertyPath} is actually a collection.
213209
*/
214210
public boolean isCollection() {
215211
return isCollection;
@@ -232,37 +228,34 @@ public PropertyPath nested(String path) {
232228

233229
/**
234230
* Returns an {@link Iterator<PropertyPath>} that iterates over all the partial property paths with the same leaf type
235-
* but decreasing length.
231+
* but decreasing length. For example:
236232
*
237-
* <pre>
238-
* {@code
233+
* <pre class="code">
239234
* PropertyPath propertyPath = PropertyPath.from("a.b.c", Some.class);
240-
* for (p : propertyPath.iterator()) {
241-
* System.out.println(p.toDotPath());
242-
* };
243-
* }
235+
* propertyPath.forEach(p -> p.toDotPath());
244236
* </pre>
245237
*
246-
* Results in the output:
238+
* results in the dot paths: *
247239
*
248-
* <pre>
249-
* {@code
240+
* <pre class="code">
250241
* a.b.c
251242
* b.c
252243
* c
253-
* }
254244
* </pre>
255245
*/
246+
@Override
256247
public Iterator<PropertyPath> iterator() {
257248

258249
return new Iterator<PropertyPath>() {
259250

260251
private @Nullable PropertyPath current = PropertyPath.this;
261252

253+
@Override
262254
public boolean hasNext() {
263255
return current != null;
264256
}
265257

258+
@Override
266259
@Nullable
267260
public PropertyPath next() {
268261

@@ -275,10 +268,6 @@ public PropertyPath next() {
275268
this.current = result.next();
276269
return result;
277270
}
278-
279-
public void remove() {
280-
throw new UnsupportedOperationException();
281-
}
282271
};
283272
}
284273

@@ -297,11 +286,9 @@ public boolean equals(@Nullable Object o) {
297286
return false;
298287
}
299288

300-
return Objects.equals(this.owningType, that.owningType)
301-
&& Objects.equals(this.name, that.name)
289+
return Objects.equals(this.owningType, that.owningType) && Objects.equals(this.name, that.name)
302290
&& Objects.equals(this.typeInformation, that.typeInformation)
303-
&& Objects.equals(this.actualTypeInformation, that.actualTypeInformation)
304-
&& Objects.equals(next, that.next);
291+
&& Objects.equals(this.actualTypeInformation, that.actualTypeInformation) && Objects.equals(next, that.next);
305292
}
306293

307294
@Override
@@ -312,7 +299,7 @@ public int hashCode() {
312299
/**
313300
* Returns the next {@link PropertyPath}.
314301
*
315-
* @return
302+
* @return the next {@link PropertyPath}.
316303
* @throws IllegalStateException it there's no next one.
317304
*/
318305
private PropertyPath requiredNext() {
@@ -337,8 +324,8 @@ private PropertyPath requiredNext() {
337324
* "userAddress.city" is preferred over "user.address.city".
338325
* </p>
339326
*
340-
* @param source a String denoting the property path. Must not be {@literal null}.
341-
* @param type the owning type of the property path. Must not be {@literal null}.
327+
* @param source a String denoting the property path, must not be {@literal null}.
328+
* @param type the owning type of the property path, must not be {@literal null}.
342329
* @return a new {@link PropertyPath} guaranteed to be not {@literal null}.
343330
*/
344331
public static PropertyPath from(String source, Class<?> type) {
@@ -355,8 +342,8 @@ public static PropertyPath from(String source, Class<?> type) {
355342
* "userAddress.city" is preferred over "user.address.city".
356343
* </p>
357344
*
358-
* @param source a String denoting the property path. Must not be {@literal null}.
359-
* @param type the owning type of the property path. Must not be {@literal null}.
345+
* @param source a String denoting the property path, must not be {@literal null}.
346+
* @param type the owning type of the property path, must not be {@literal null}.
360347
* @return a new {@link PropertyPath} guaranteed to be not {@literal null}.
361348
*/
362349
public static PropertyPath from(String source, TypeInformation<?> type) {

src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
import static org.assertj.core.api.Assertions.*;
1919
import static org.springframework.data.mapping.PropertyPath.from;
2020

21+
import java.util.ArrayList;
22+
import java.util.List;
2123
import java.util.Map;
2224
import java.util.Set;
2325
import java.util.regex.Pattern;
2426

2527
import org.junit.jupiter.api.Test;
26-
import org.springframework.data.util.ClassTypeInformation;
2728
import org.springframework.data.util.TypeInformation;
2829

2930
/**
@@ -174,7 +175,7 @@ void returnsCorrectIteratorForSingleElement() {
174175
assertThat(iterator.hasNext()).isFalse();
175176
}
176177

177-
@Test
178+
@Test // GH-2491
178179
void returnsCorrectIteratorForMultipleElement() {
179180

180181
var propertyPath = PropertyPath.from("user.name", Bar.class);
@@ -185,14 +186,19 @@ void returnsCorrectIteratorForMultipleElement() {
185186
assertThat(iterator.hasNext()).isTrue();
186187
assertThat(iterator.next()).isEqualTo(propertyPath.next());
187188
assertThat(iterator.hasNext()).isFalse();
189+
190+
List<String> paths = new ArrayList<>();
191+
propertyPath.forEach(it -> paths.add(it.toDotPath()));
192+
193+
assertThat(paths).containsExactly("user.name", "name");
188194
}
189195

190196
@Test // GH-2491
191-
public void nextReturnsPathWithoutFirstElement() {
197+
void nextReturnsPathWithoutFirstElement() {
192198

193199
PropertyPath propertyPath = PropertyPath.from("bar.user.name", Sample.class);
194200

195-
final PropertyPath next = propertyPath.next();
201+
PropertyPath next = propertyPath.next();
196202
assertThat(next).isNotNull();
197203
assertThat(next.toDotPath()).isEqualTo("user.name");
198204
}

0 commit comments

Comments
 (0)