List<TreePath> (List<? extends TreePath> paths, Collection<? extends ServiceViewItem> roots, Object treeRoot) { List<TreePath> result = new SmartList<>(); for (TreePath path : paths) { Object[] items = path.getPath(); for (int i = 1; i < items.length; i++) { if (roots.contains(items[i])) { Object[] adjustedItems = ArrayUtil.insert(items, 0, treeRoot); result.add(new TreePath(adjustedItems)); break; } } } return result; }