38
38
*/
39
39
class DefaultPersistentPropertyPath <P extends PersistentProperty <P >> implements PersistentPropertyPath <P > {
40
40
41
- private static final Converter <PersistentProperty <?>, String > DEFAULT_CONVERTER = ( source ) -> source . getName () ;
41
+ private static final Converter <PersistentProperty <?>, String > DEFAULT_CONVERTER = PersistentProperty :: getName ;
42
42
private static final String DEFAULT_DELIMITER = "." ;
43
43
44
44
private final List <P > properties ;
@@ -60,7 +60,7 @@ public DefaultPersistentPropertyPath(List<P> properties) {
60
60
*
61
61
* @return
62
62
*/
63
- public static <T extends PersistentProperty <T >> DefaultPersistentPropertyPath <T > empty () {
63
+ static <T extends PersistentProperty <T >> DefaultPersistentPropertyPath <T > empty () {
64
64
return new DefaultPersistentPropertyPath <T >(Collections .emptyList ());
65
65
}
66
66
@@ -71,15 +71,14 @@ public static <T extends PersistentProperty<T>> DefaultPersistentPropertyPath<T>
71
71
* @return a new {@link DefaultPersistentPropertyPath} with the given property appended to the current one.
72
72
* @throws IllegalArgumentException in case the property is not a property of the type of the current leaf property.
73
73
*/
74
- public DefaultPersistentPropertyPath <P > append (P property ) {
74
+ DefaultPersistentPropertyPath <P > append (P property ) {
75
75
76
76
Assert .notNull (property , "Property must not be null" );
77
77
78
78
if (isEmpty ()) {
79
79
return new DefaultPersistentPropertyPath <>(Collections .singletonList (property ));
80
80
}
81
81
82
- @ SuppressWarnings ("null" )
83
82
Class <?> leafPropertyType = getLeafProperty ().getActualType ();
84
83
85
84
Assert .isTrue (property .getOwner ().getType ().equals (leafPropertyType ),
@@ -91,45 +90,50 @@ public DefaultPersistentPropertyPath<P> append(P property) {
91
90
return new DefaultPersistentPropertyPath <>(properties );
92
91
}
93
92
94
- @ Nullable
93
+ @ Override
95
94
public String toDotPath () {
96
95
return toPath (DEFAULT_DELIMITER , DEFAULT_CONVERTER );
97
96
}
98
97
99
- @ Nullable
98
+ @ Override
100
99
public String toDotPath (Converter <? super P , String > converter ) {
101
100
return toPath (DEFAULT_DELIMITER , converter );
102
101
}
103
102
104
- @ Nullable
103
+ @ Override
105
104
public String toPath (String delimiter ) {
106
105
return toPath (delimiter , DEFAULT_CONVERTER );
107
106
}
108
107
109
- @ Nullable
108
+ @ Override
110
109
public String toPath (String delimiter , Converter <? super P , String > converter ) {
111
110
112
111
Assert .hasText (delimiter , "Delimiter must not be null or empty" );
113
112
Assert .notNull (converter , "Converter must not be null" );
114
113
115
- String result = properties .stream () //
114
+ return properties .stream () //
116
115
.map (converter ::convert ) //
117
116
.filter (StringUtils ::hasText ) //
118
117
.collect (Collectors .joining (delimiter ));
119
-
120
- return result .isEmpty () ? null : result ;
121
118
}
122
119
123
- @ Nullable
120
+ @ Override
124
121
public P getLeafProperty () {
125
- return properties .isEmpty () ? null : properties .get (properties .size () - 1 );
122
+
123
+ Assert .state (properties .size () > 0 , "Empty PersistentPropertyPath should not exist" );
124
+
125
+ return properties .get (properties .size () - 1 );
126
126
}
127
127
128
- @ Nullable
128
+ @ Override
129
129
public P getBaseProperty () {
130
- return properties .isEmpty () ? null : properties .get (0 );
130
+
131
+ Assert .state (properties .size () > 0 , "Empty PersistentPropertyPath should not exist" );
132
+
133
+ return properties .get (0 );
131
134
}
132
135
136
+ @ Override
133
137
public boolean isBasePathOf (PersistentPropertyPath <P > path ) {
134
138
135
139
Assert .notNull (path , "PersistentPropertyPath must not be null" );
@@ -152,37 +156,31 @@ public boolean isBasePathOf(PersistentPropertyPath<P> path) {
152
156
return true ;
153
157
}
154
158
159
+ @ Override
155
160
public PersistentPropertyPath <P > getExtensionForBaseOf (PersistentPropertyPath <P > base ) {
156
161
157
162
if (!base .isBasePathOf (this )) {
158
163
return this ;
159
164
}
160
165
161
- List <P > result = new ArrayList <>();
162
- Iterator <P > iterator = iterator ();
163
-
164
- for (int i = 0 ; i < base .getLength (); i ++) {
165
- iterator .next ();
166
- }
167
-
168
- while (iterator .hasNext ()) {
169
- result .add (iterator .next ());
170
- }
171
-
172
- return new DefaultPersistentPropertyPath <>(result );
166
+ return new DefaultPersistentPropertyPath <>(properties .subList (base .getLength (), getLength ()));
173
167
}
174
168
169
+ @ Nullable
170
+ @ Override
175
171
public PersistentPropertyPath <P > getParentPath () {
176
172
177
173
int size = properties .size ();
178
174
179
- return size == 0 ? this : new DefaultPersistentPropertyPath <>(properties .subList (0 , size - 1 ));
175
+ return size == 1 ? null : new DefaultPersistentPropertyPath <>(properties .subList (0 , size - 1 ));
180
176
}
181
177
178
+ @ Override
182
179
public int getLength () {
183
180
return properties .size ();
184
181
}
185
182
183
+ @ Override
186
184
public Iterator <P > iterator () {
187
185
return properties .iterator ();
188
186
}
@@ -202,7 +200,7 @@ public boolean containsPropertyOfType(@Nullable TypeInformation<?> type) {
202
200
}
203
201
204
202
@ Override
205
- public boolean equals (Object o ) {
203
+ public boolean equals (@ Nullable Object o ) {
206
204
207
205
if (this == o ) {
208
206
return true ;
0 commit comments