}
@RunsInCurrentThread
@Nonnull TreePath findMatchingPath(@Nonnull JTree tree, @Nonnull String path) {
String[] pathStrings = splitPath(path);
TreeModel model = tree.getModel();
List<Object> newPathValues = newArrayList();
Object node = model.getRoot();
int pathElementCount = pathStrings.length;
for (int stringIndex = 0; stringIndex < pathElementCount; stringIndex++) {
String pathString = pathStrings[stringIndex];
Object match = null;
if (stringIndex == 0 && tree.isRootVisible()) {
if (!pathString.equals(value(tree, node))) {
throw pathNotFound(path);
}
newPathValues.add(node);
continue;
}
int childCount = model.getChildCount(node);
for (int childIndex = 0; childIndex < childCount; childIndex++) {
Object child = model.getChild(node, childIndex);
if (pathString.equals(value(tree, child))) {
if (match != null) {
throw multipleMatchingNodes(pathString, value(tree, node));
}
match = child;