@@ -219,22 +219,10 @@ public static Map<String, Object> filter(Map<String, ?> map, String[] includes,
219
219
* @see #filter(Map, String[], String[]) for details
220
220
*/
221
221
public static Function <Map <String , ?>, Map <String , Object >> filter (String [] includes , String [] excludes ) {
222
-
223
- return (map ) -> {
224
- if (hasNoDottedKeys (map ) && hasNoWildcardsOrDots (includes ) && hasNoWildcardsOrDots (excludes )) {
225
- return createSetBasedFilter (includes , excludes ).apply (map );
226
- }
227
- return createAutomatonFilter (includes , excludes ).apply (map );
228
- };
229
- }
230
-
231
- private static boolean hasNoDottedKeys (Map <String , ?> map ) {
232
- for (String key : map .keySet ()) {
233
- if (key .indexOf ('.' ) != -1 ) {
234
- return false ;
235
- }
222
+ if (hasNoWildcardsOrDots (includes ) && hasNoWildcardsOrDots (excludes )) {
223
+ return createSetBasedFilter (includes , excludes );
236
224
}
237
- return true ;
225
+ return createAutomatonFilter ( includes , excludes ) ;
238
226
}
239
227
240
228
private static boolean hasNoWildcardsOrDots (String [] fields ) {
@@ -254,7 +242,6 @@ private static boolean hasNoWildcardsOrDots(String[] fields) {
254
242
* Creates a simple HashSet-based filter for exact field name matching
255
243
*/
256
244
private static Function <Map <String , ?>, Map <String , Object >> createSetBasedFilter (String [] includes , String [] excludes ) {
257
-
258
245
Set <String > includeSet = (includes == null || includes .length == 0 ) ? null : new HashSet <>(Arrays .asList (includes ));
259
246
Set <String > excludeSet = (excludes == null || excludes .length == 0 )
260
247
? Collections .emptySet ()
@@ -264,8 +251,12 @@ private static boolean hasNoWildcardsOrDots(String[] fields) {
264
251
Map <String , Object > filtered = new HashMap <>();
265
252
for (Map .Entry <String , ?> entry : map .entrySet ()) {
266
253
String key = entry .getKey ();
254
+ int dotPos = key .indexOf ('.' );
255
+ if (dotPos > 0 ) {
256
+ key = key .substring (0 , dotPos );
257
+ }
267
258
if ((includeSet == null || includeSet .contains (key )) && !excludeSet .contains (key )) {
268
- filtered .put (key , entry .getValue ());
259
+ filtered .put (entry . getKey () , entry .getValue ());
269
260
}
270
261
}
271
262
return filtered ;
0 commit comments