}
}
if (indexOrPattern.isEmpty() || !Regex.isSimpleMatchPattern(indexOrPattern)) {
if (!availableIndices.contains(indexOrPattern)) {
if (!indicesOptions.ignoreUnavailable()) {
throw new IndexMissingException(new Index(indexOrPattern));
} else {
if (result == null) {
// add all the previous ones...
result = new HashSet<>();
result.addAll(availableIndices.subList(0, i));
}
}
} else {
if (result != null) {
if (add) {
result.add(indexOrPattern);
} else {
result.remove(indexOrPattern);
}
}
}
continue;
}
if (result == null) {
// add all the previous ones...
result = new HashSet<>();
result.addAll(availableIndices.subList(0, i));
}
boolean found = false;
for (String index : availableIndices) {
if (Regex.simpleMatch(indexOrPattern, index)) {
found = true;
if (add) {
result.add(index);
} else {
result.remove(index);
}
}
}
if (!found && !indicesOptions.allowNoIndices()) {
throw new IndexMissingException(new Index(indexOrPattern));
}
}
if (result == null) {
return ImmutableList.copyOf(selectedIndices);
}