@@ -296,30 +296,37 @@ private ImmutableOpenMap<String, List<AliasMetaData>> findAliases(String[] origi
296
296
return ImmutableOpenMap .of ();
297
297
}
298
298
299
- List <String > includeAliases = new ArrayList <>();
300
- List <String > excludeAliases = new ArrayList <>();
301
- boolean wildcardSeen = false ;
302
- for (final String alias : aliases ) {
303
- if (Regex .isSimpleMatchPattern (alias )) {
304
- wildcardSeen = true ;
305
- }
306
- if (wildcardSeen && alias .charAt (0 ) == '-' ) {
307
- excludeAliases .add (alias .substring (1 ));
299
+ String [] patterns = new String [aliases .length ];
300
+ boolean [] include = new boolean [aliases .length ];
301
+ for (int i = 0 ; i < aliases .length ; i ++) {
302
+ String alias = aliases [i ];
303
+ if (alias .charAt (0 ) == '-' ) {
304
+ patterns [i ] = alias .substring (1 );
305
+ include [i ] = false ;
308
306
} else {
309
- includeAliases .add (alias );
307
+ patterns [i ] = alias ;
308
+ include [i ] = true ;
310
309
}
311
310
}
312
- String [] included = includeAliases .toArray (Strings .EMPTY_ARRAY );
313
- String [] excluded = excludeAliases .toArray (Strings .EMPTY_ARRAY );
314
- boolean matchAllAliases = matchAllAliases (included );
311
+ boolean matchAllAliases = patterns .length == 0 ;
315
312
ImmutableOpenMap .Builder <String , List <AliasMetaData >> mapBuilder = ImmutableOpenMap .builder ();
316
313
for (String index : concreteIndices ) {
317
314
IndexMetaData indexMetaData = indices .get (index );
318
315
List <AliasMetaData > filteredValues = new ArrayList <>();
319
316
for (ObjectCursor <AliasMetaData > cursor : indexMetaData .getAliases ().values ()) {
320
317
AliasMetaData value = cursor .value ;
321
- if ((matchAllAliases || Regex .simpleMatch (included , value .alias ()))
322
- && Regex .simpleMatch (excluded , value .alias ()) == false ) {
318
+ boolean matched = matchAllAliases ;
319
+ String alias = value .alias ();
320
+ for (int i = 0 ; i < patterns .length ; i ++) {
321
+ if (include [i ]) {
322
+ if (matched == false ) {
323
+ matched = Regex .simpleMatch (patterns [i ], alias );
324
+ }
325
+ } else if (matched ) {
326
+ matched = Regex .simpleMatch (patterns [i ], alias ) == false ;
327
+ }
328
+ }
329
+ if (matched ) {
323
330
filteredValues .add (value );
324
331
}
325
332
}
@@ -333,15 +340,6 @@ private ImmutableOpenMap<String, List<AliasMetaData>> findAliases(String[] origi
333
340
return mapBuilder .build ();
334
341
}
335
342
336
- private static boolean matchAllAliases (final String [] aliases ) {
337
- for (String alias : aliases ) {
338
- if (alias .equals (ALL )) {
339
- return true ;
340
- }
341
- }
342
- return aliases .length == 0 ;
343
- }
344
-
345
343
/**
346
344
* Checks if at least one of the specified aliases exists in the specified concrete indices. Wildcards are supported in the
347
345
* alias names for partial matches.
0 commit comments