|
@@ -24,7 +24,9 @@ import org.elasticsearch.xcontent.json.JsonXContent;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.util.ArrayDeque;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Deque;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Random;
|
|
@@ -204,7 +206,7 @@ public final class XContentTestUtils {
|
|
|
)
|
|
|
) {
|
|
|
parser.nextToken();
|
|
|
- List<String> possiblePaths = XContentTestUtils.getInsertPaths(parser, new Stack<>());
|
|
|
+ List<String> possiblePaths = XContentTestUtils.getInsertPaths(parser, new ArrayDeque<>());
|
|
|
if (excludeFilter == null) {
|
|
|
insertPaths = possiblePaths;
|
|
|
} else {
|
|
@@ -268,17 +270,17 @@ public final class XContentTestUtils {
|
|
|
* <li>"foo3.foo4</li>
|
|
|
* </ul>
|
|
|
*/
|
|
|
- static List<String> getInsertPaths(XContentParser parser, Stack<String> currentPath) throws IOException {
|
|
|
+ static List<String> getInsertPaths(XContentParser parser, Deque<String> currentPath) throws IOException {
|
|
|
assert parser.currentToken() == XContentParser.Token.START_OBJECT || parser.currentToken() == XContentParser.Token.START_ARRAY
|
|
|
: "should only be called when new objects or arrays start";
|
|
|
List<String> validPaths = new ArrayList<>();
|
|
|
// parser.currentName() can be null for root object and unnamed objects in arrays
|
|
|
if (parser.currentName() != null) {
|
|
|
// dots in randomized field names need to be escaped, we use that character as the path separator
|
|
|
- currentPath.push(parser.currentName().replaceAll("\\.", "\\\\."));
|
|
|
+ currentPath.addLast(parser.currentName().replaceAll("\\.", "\\\\."));
|
|
|
}
|
|
|
if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
|
|
- validPaths.add(String.join(".", currentPath.toArray(String[]::new)));
|
|
|
+ validPaths.add(String.join(".", currentPath));
|
|
|
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
|
|
|
if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
|
|
|| parser.currentToken() == XContentParser.Token.START_ARRAY) {
|
|
@@ -290,15 +292,15 @@ public final class XContentTestUtils {
|
|
|
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
|
|
if (parser.currentToken() == XContentParser.Token.START_OBJECT
|
|
|
|| parser.currentToken() == XContentParser.Token.START_ARRAY) {
|
|
|
- currentPath.push(Integer.toString(itemCount));
|
|
|
+ currentPath.addLast(Integer.toString(itemCount));
|
|
|
validPaths.addAll(getInsertPaths(parser, currentPath));
|
|
|
- currentPath.pop();
|
|
|
+ currentPath.removeLast();
|
|
|
}
|
|
|
itemCount++;
|
|
|
}
|
|
|
}
|
|
|
if (parser.currentName() != null) {
|
|
|
- currentPath.pop();
|
|
|
+ currentPath.removeLast();
|
|
|
}
|
|
|
return validPaths;
|
|
|
}
|