}
@RunsInCurrentThread
TreePath findMatchingPath(JTree tree, String path) {
String[] pathStrings = splitPath(path);
TreeModel model = tree.getModel();
List<Object> newPathValues = new ArrayList<Object>(pathStrings.length + 1);
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;
}
}