|
15 | 15 | */ |
16 | 16 | package org.springframework.data.mapping; |
17 | 17 |
|
18 | | -import java.util.Iterator; |
19 | | -import java.util.regex.Pattern; |
20 | | - |
21 | | -import org.jspecify.annotations.Nullable; |
22 | | - |
23 | | -import org.springframework.data.util.Streamable; |
24 | | -import org.springframework.data.util.TypeInformation; |
25 | | -import org.springframework.util.Assert; |
26 | | - |
27 | 18 | /** |
28 | | - * Abstraction of a {@link PropertyPath} within a domain class. |
| 19 | + * Abstraction of a {@code PropertyPath} within a domain class. |
29 | 20 | * |
30 | 21 | * @author Oliver Gierke |
31 | 22 | * @author Christoph Strobl |
32 | 23 | * @author Mark Paluch |
33 | 24 | * @author Mariusz Mączkowski |
34 | 25 | * @author Johannes Englmeier |
| 26 | + * @deprecated since 4.1, use its replacement that moved to {@code org.springframework.data.util} package. |
35 | 27 | */ |
36 | | -public interface PropertyPath extends Streamable<PropertyPath> { |
37 | | - |
38 | | - /** |
39 | | - * Syntax sugar to create a {@link TypedPropertyPath} from an existing one, ideal for method handles. |
40 | | - * |
41 | | - * @param propertyPath |
42 | | - * @return |
43 | | - * @param <T> owning type. |
44 | | - * @param <R> property type. |
45 | | - * @since xxx |
46 | | - */ |
47 | | - public static <T, R> TypedPropertyPath<T, R> of(TypedPropertyPath<T, R> propertyPath) { |
48 | | - return TypedPropertyPath.of(propertyPath); |
49 | | - } |
50 | | - |
51 | | - /** |
52 | | - * Returns the owning type of the {@link PropertyPath}. |
53 | | - * |
54 | | - * @return the owningType will never be {@literal null}. |
55 | | - */ |
56 | | - TypeInformation<?> getOwningType(); |
57 | | - |
58 | | - /** |
59 | | - * Returns the first part of the {@link PropertyPath}. For example: |
60 | | - * |
61 | | - * <pre class="code"> |
62 | | - * PropertyPath.from("a.b.c", Some.class).getSegment(); |
63 | | - * </pre> |
64 | | - * |
65 | | - * results in {@code a}. |
66 | | - * |
67 | | - * @return the name will never be {@literal null}. |
68 | | - */ |
69 | | - String getSegment(); |
70 | | - |
71 | | - /** |
72 | | - * Returns the leaf property of the {@link PropertyPath}. |
73 | | - * |
74 | | - * @return will never be {@literal null}. |
75 | | - */ |
76 | | - default PropertyPath getLeafProperty() { |
77 | | - |
78 | | - PropertyPath result = this; |
79 | | - |
80 | | - while (result != null && result.hasNext()) { |
81 | | - result = result.next(); |
82 | | - } |
83 | | - |
84 | | - return result == null ? this : result; |
85 | | - } |
86 | | - |
87 | | - /** |
88 | | - * Returns the type of the leaf property of the current {@link PropertyPath}. |
89 | | - * |
90 | | - * @return will never be {@literal null}. |
91 | | - */ |
92 | | - default Class<?> getLeafType() { |
93 | | - return getLeafProperty().getType(); |
94 | | - } |
95 | | - |
96 | | - /** |
97 | | - * Returns the actual type of the property. Will return the plain resolved type for simple properties, the component |
98 | | - * type for any {@link Iterable} or the value type of a {@link java.util.Map}. |
99 | | - * |
100 | | - * @return the actual type of the property. |
101 | | - */ |
102 | | - default Class<?> getType() { |
103 | | - return getTypeInformation().getRequiredActualType().getType(); |
104 | | - } |
105 | | - |
106 | | - /** |
107 | | - * Returns the type information of the property. |
108 | | - * |
109 | | - * @return the actual type of the property. |
110 | | - */ |
111 | | - TypeInformation<?> getTypeInformation(); |
112 | | - |
113 | | - /** |
114 | | - * Returns the {@link PropertyPath} path that results from removing the first element of the current one. For example: |
115 | | - * |
116 | | - * <pre class="code"> |
117 | | - * PropertyPath.from("a.b.c", Some.class).next().toDotPath(); |
118 | | - * </pre> |
119 | | - * |
120 | | - * results in the output: {@code b.c} |
121 | | - * |
122 | | - * @return the next nested {@link PropertyPath} or {@literal null} if no nested {@link PropertyPath} available. |
123 | | - * @see #hasNext() |
124 | | - */ |
125 | | - @Nullable |
126 | | - PropertyPath next(); |
127 | | - |
128 | | - /** |
129 | | - * Returns whether there is a nested {@link PropertyPath}. If this returns {@literal true} you can expect |
130 | | - * {@link #next()} to return a non- {@literal null} value. |
131 | | - * |
132 | | - * @return |
133 | | - */ |
134 | | - default boolean hasNext() { |
135 | | - return next() != null; |
136 | | - } |
137 | | - |
138 | | - /** |
139 | | - * Returns the {@link PropertyPath} in dot notation. |
140 | | - * |
141 | | - * @return the {@link PropertyPath} in dot notation. |
142 | | - */ |
143 | | - default String toDotPath() { |
144 | | - |
145 | | - PropertyPath next = next(); |
146 | | - return next != null ? getSegment() + "." + next.toDotPath() : getSegment(); |
147 | | - } |
148 | | - |
149 | | - /** |
150 | | - * Returns whether the {@link PropertyPath} is actually a collection. |
151 | | - * |
152 | | - * @return {@literal true} whether the {@link PropertyPath} is actually a collection. |
153 | | - */ |
154 | | - default boolean isCollection() { |
155 | | - return getTypeInformation().isCollectionLike(); |
156 | | - } |
157 | | - |
158 | | - /** |
159 | | - * Returns the {@link PropertyPath} for the path nested under the current property. |
160 | | - * |
161 | | - * @param path must not be {@literal null} or empty. |
162 | | - * @return will never be {@literal null}. |
163 | | - */ |
164 | | - default PropertyPath nested(String path) { |
165 | | - |
166 | | - Assert.hasText(path, "Path must not be null or empty"); |
167 | | - |
168 | | - String lookup = toDotPath().concat(".").concat(path); |
169 | | - |
170 | | - return SimplePropertyPath.from(lookup, getOwningType()); |
171 | | - } |
172 | | - |
173 | | - /** |
174 | | - * Returns an {@link Iterator Iterator of PropertyPath} that iterates over all the partial property paths with the |
175 | | - * same leaf type but decreasing length. For example: |
176 | | - * |
177 | | - * <pre class="code"> |
178 | | - * PropertyPath propertyPath = PropertyPath.from("a.b.c", Some.class); |
179 | | - * propertyPath.forEach(p -> p.toDotPath()); |
180 | | - * </pre> |
181 | | - * |
182 | | - * results in the dot paths: |
183 | | - * |
184 | | - * <pre class="code"> |
185 | | - * a.b.c |
186 | | - * b.c |
187 | | - * c |
188 | | - * </pre> |
189 | | - */ |
190 | | - @Override |
191 | | - Iterator<PropertyPath> iterator(); |
192 | | - |
193 | | - /** |
194 | | - * Extracts the {@link PropertyPath} chain from the given source {@link String} and {@link TypeInformation}. <br /> |
195 | | - * Uses {@code (?:[%s]?([%s]*?[^%s]+))} by default and {@code (?:[%s]?([%s]*?[^%s]+))} for |
196 | | - * {@link Pattern#quote(String) quoted} literals. |
197 | | - * <p> |
198 | | - * Separate parts of the path may be separated by {@code "."} or by {@code "_"} or by camel case. When the match to |
199 | | - * properties is ambiguous longer property names are preferred. So for {@code userAddressCity} the interpretation |
200 | | - * {@code userAddress.city} is preferred over {@code user.address.city}. |
201 | | - * |
202 | | - * @param source a String denoting the property path, must not be {@literal null}. |
203 | | - * @param type the owning type of the property path, must not be {@literal null}. |
204 | | - * @return a new {@link PropertyPath} guaranteed to be not {@literal null}. |
205 | | - */ |
206 | | - static PropertyPath from(String source, Class<?> type) { |
207 | | - return from(source, TypeInformation.of(type)); |
208 | | - } |
209 | | - |
210 | | - /** |
211 | | - * Extracts the {@link PropertyPath} chain from the given source {@link String} and {@link TypeInformation}. <br /> |
212 | | - * Uses {@code (?:[%s]?([%s]*?[^%s]+))} by default and {@code (?:[%s]?([%s]*?[^%s]+))} for |
213 | | - * {@link Pattern#quote(String) quoted} literals. |
214 | | - * <p> |
215 | | - * Separate parts of the path may be separated by {@code "."} or by {@code "_"} or by camel case. When the match to |
216 | | - * properties is ambiguous longer property names are preferred. So for {@code userAddressCity} the interpretation |
217 | | - * {@code userAddress.city} is preferred over {@code user.address.city}. |
218 | | - * |
219 | | - * @param source a String denoting the property path, must not be {@literal null}. |
220 | | - * @param type the owning type of the property path, must not be {@literal null}. |
221 | | - * @return a new {@link PropertyPath} guaranteed to be not {@literal null}. |
222 | | - */ |
223 | | - static PropertyPath from(String source, TypeInformation<?> type) { |
224 | | - return SimplePropertyPath.from(source, type); |
225 | | - } |
| 28 | +@Deprecated |
| 29 | +public interface PropertyPath extends org.springframework.data.util.PropertyPath { |
226 | 30 |
|
227 | 31 | } |
0 commit comments