Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
272,800
void (@NotNull Runnable task, @NotNull AsyncTreeModel model, long time, int count) { //noinspection SSBasedInspection SwingUtilities.invokeLater(() -> { if (model.isProcessing()) { invokeWhenProcessingDone(task, model, time, 0); } else if (count < 2) { invokeWhenProcessingDone(task, model, time, count + 1); } else { printTime("wait for ", time); task.run(); } }); }
invokeWhenProcessingDone
272,801
int (int delay) { return delay + 20; }
getSecondsToWait
272,802
TreeModel (TreeModel model, Disposable disposable) { return model; }
createModelForTree
272,803
Runnable (@NotNull Runnable task) { return () -> { try { task.run(); } catch (Throwable throwable) { promise.setError(throwable); } }; }
wrap
272,804
void (boolean visible, @NotNull Runnable task) { tree.setRootVisible(visible); runOnSwingThreadWhenProcessingDone(task); }
setRootVisible
272,805
void (@NotNull TreePath path, @NotNull Runnable task) { tree.expandPath(path); runOnSwingThreadWhenProcessingDone(task); }
expand
272,806
void (@NotNull TreePath path, @NotNull Runnable task) { tree.collapsePath(path); runOnSwingThreadWhenProcessingDone(task); }
collapse
272,807
void (@NotNull TreePath path) { runOnSwingThread(() -> { tree.getModel().addTreeModelListener(new TreeModelAdapter() { @Override protected void process(@NotNull TreeModelEvent event, @NotNull EventType type) { assertEquals("unexpected tree path", path, event.getTreePath()); //noinspection SSBasedInspection SwingUtilities.invokeLater(ModelTest.this::done); } }); runOnModelThread(() -> { TreeModelEvent event = new TreeModelEvent(model, path); TreeModelListener[] listeners = ((DefaultTreeModel)model).getTreeModelListeners(); for (TreeModelListener listener : listeners) listener.treeStructureChanged(event); }); }); }
fireStructureChanged
272,808
void (@NotNull TreeModelEvent event, @NotNull EventType type) { assertEquals("unexpected tree path", path, event.getTreePath()); //noinspection SSBasedInspection SwingUtilities.invokeLater(ModelTest.this::done); }
process
272,809
void (Consumer<? super TreeModel> consumer, @NotNull Runnable task) { runOnModelThread(() -> { consumer.accept(model); runOnSwingThreadWhenProcessingDone(task); }); }
updateModelAndWait
272,810
void (@NotNull Runnable task) { if (model instanceof InvokerSupplier supplier) { supplier.getInvoker().invoke(wrap(task)); } else { runOnSwingThread(task); } }
runOnModelThread
272,811
void (@NotNull Runnable task) { if (SwingUtilities.isEventDispatchThread()) { wrap(task).run(); } else { //noinspection SSBasedInspection SwingUtilities.invokeLater(wrap(task)); } }
runOnSwingThread
272,812
void (@NotNull Runnable task) { TreeModel model = tree.getModel(); if (model instanceof AsyncTreeModel) { invokeWhenProcessingDone(wrap(task), (AsyncTreeModel)model, System.currentTimeMillis(), 0); } else { runOnSwingThread(task); } }
runOnSwingThreadWhenProcessingDone
272,813
void (@NotNull TreePath path, @NotNull Consumer<? super TreePath> consumer) { AsyncTreeModel model = (AsyncTreeModel)tree.getModel(); model.resolve(path).onError(promise::setError).onSuccess(consumer); }
resolve
272,814
void (@NotNull TreeVisitor visitor, boolean allowLoading, @NotNull Consumer<? super TreePath> consumer) { AsyncTreeModel model = (AsyncTreeModel)tree.getModel(); model.accept(visitor, allowLoading).onError(promise::setError).onSuccess(consumer); }
visit
272,815
String () { return model.toString(); }
toString
272,816
TreeModel (TreeModel model, Disposable disposable) { return new AsyncTreeModel(model, showLoadingNode, disposable); }
createModelForTree
272,817
String () { String string = super.toString(); if (showLoadingNode) string = "show loading node " + string; return string; }
toString
272,818
void () { if (this instanceof InvokerSupplier && THRESHOLD > Math.random()) { // sometimes throw an exception to cancel current operation if (PRINT) System.out.println("interrupt access to model:" + toString()); throw new ProcessCanceledException(); } if (delay > 0) { try { Thread.sleep(delay); } catch (InterruptedException ignored) { } } }
pause
272,819
Object () { pause(); return super.getRoot(); }
getRoot
272,820
Object (Object parent, int index) { if (index == 0) pause(); // do not pause for every child return super.getChild(parent, index); }
getChild
272,821
int (Object parent) { pause(); return super.getChildCount(parent); }
getChildCount
272,822
boolean (Object node) { pause(); return super.isLeaf(node); }
isLeaf
272,823
int (Object parent, Object child) { pause(); return super.getIndexOfChild(parent, child); }
getIndexOfChild
272,824
List<Object> (Object parent) { pause(); int count = super.getChildCount(parent); List<Object> res = new ArrayList<>(count); for (int i = 0; i < count; ++i) { res.add(super.getChild(parent, i)); } return res; }
getChildren
272,825
void () { }
dispose
272,826
String () { return getClass().getSimpleName() + "+" + delay + "ms"; }
toString
272,827
Invoker () { return invoker; }
getInvoker
272,828
Invoker () { return invoker; }
getInvoker
272,829
Invoker () { return invoker; }
getInvoker
272,830
int () { if (!mutable) return super.hashCode(); Object content = getUserObject(); return content == null ? 0 : content.hashCode(); }
hashCode
272,831
boolean (Object object) { if (!mutable) return super.equals(object); if (object instanceof Node node) { if (node.mutable) return Objects.equals(getUserObject(), node.getUserObject()); } return false; }
equals
272,832
String () { Object content = getUserObject(); if (content == null) return "null"; return "'" + content + "'"; }
toString
272,833
void () { testNodePreservingOnEventDispatchThread(false); testNodePreservingOnEventDispatchThread(true); }
testNodePreservingOnEventDispatchThread
272,834
void (boolean showLoadingNode) { testNodePreserving(showLoadingNode, new GroupModel() { private final Invoker invoker = Invoker.forEventDispatchThread(this); @NotNull @Override public Invoker getInvoker() { return invoker; } }); }
testNodePreservingOnEventDispatchThread
272,835
Invoker () { return invoker; }
getInvoker
272,836
void () { testNodePreservingOnBackgroundThread(false); testNodePreservingOnBackgroundThread(true); }
testNodePreservingOnBackgroundThread
272,837
void (boolean showLoadingNode) { testNodePreserving(showLoadingNode, new GroupModel() { private final Invoker invoker = Invoker.forBackgroundThreadWithReadAction(this); @NotNull @Override public Invoker getInvoker() { return invoker; } }); }
testNodePreservingOnBackgroundThread
272,838
Invoker () { return invoker; }
getInvoker
272,839
void () { testNodePreservingOnBackgroundPool(false); testNodePreservingOnBackgroundPool(true); }
testNodePreservingOnBackgroundPool
272,840
void (boolean showLoadingNode) { testNodePreserving(showLoadingNode, new GroupModel() { private final Invoker invoker = Invoker.forBackgroundPoolWithReadAction(this); @NotNull @Override public Invoker getInvoker() { return invoker; } }); }
testNodePreservingOnBackgroundPool
272,841
Invoker () { return invoker; }
getInvoker
272,842
void (boolean showLoadingNode, @NotNull GroupModel model) { new AsyncTest(showLoadingNode, model).start(test -> testPathState(test.tree, " +root\n node\n", () -> testNodePreserving(test, model, "first", () -> testNodePreserving(test, model, "second", () -> testNodePreserving(test, model, null, () -> testNodePreserving(test, model, "third", test::done))))), 10); }
testNodePreserving
272,843
void (@NotNull ModelTest test, @NotNull GroupModel model, Object group, @NotNull Runnable task) { model.setGroup(group, () -> test.runOnSwingThreadWhenProcessingDone(() -> test.visit(path -> { test.tree.makeVisible(path); return TreeVisitor.Action.CONTINUE; }, true, done -> testPathState(test.tree, group != null ? " +root\n +" + group + "\n +node\n leaf\n" : " +root\n +node\n leaf\n", task)))); }
testNodePreserving
272,844
void (Object group, @NotNull Runnable task) { getInvoker().invoke(() -> { myGroup = group; treeStructureChanged(null, null, null); task.run(); }); }
setGroup
272,845
Object () { return myRoot; }
getRoot
272,846
Object (Object parent, int index) { if (index == 0) { Object group = myGroup; if (group == null) { if (myRoot.equals(parent)) return myNode; } else { if (myRoot.equals(parent)) return group; if (group.equals(parent)) return myNode; } if (myNode.equals(parent)) return myLeaf; } throw new IllegalStateException(); }
getChild
272,847
int (Object parent) { Object group = myGroup; if (myRoot.equals(parent) || group != null && group.equals(parent)) return 1; if (myNode.equals(parent)) return 1; if (myLeaf.equals(parent)) return 0; throw new IllegalStateException(); }
getChildCount
272,848
boolean (Object node) { Object group = myGroup; if (myRoot.equals(node) || group != null && group.equals(node)) return false; if (myNode.equals(node)) return false; if (myLeaf.equals(node)) return true; throw new IllegalStateException(); }
isLeaf
272,849
int (Object parent, Object child) { Object group = myGroup; if (group == null) { if (myRoot.equals(parent) && myNode.equals(child)) return 0; } else { if (myRoot.equals(parent) && group.equals(child)) return 0; if (group.equals(parent) && myNode.equals(child)) return 0; } if (myNode.equals(parent) && myLeaf.equals(child)) return 0; throw new IllegalStateException(); }
getIndexOfChild
272,850
String () { return getClass().getName(); }
toString
272,851
void () { TreeNode root = createRoot(); test(root, 1, path -> TreeVisitor.Action.INTERRUPT, root); test(null, 0, path -> TreeVisitor.Action.INTERRUPT); }
testInterrupt
272,852
void () { test(createRoot(), 21, path -> TreeVisitor.Action.CONTINUE); test(null, 0, path -> TreeVisitor.Action.CONTINUE); }
testContinue
272,853
void () { test(createRoot(), 1, path -> TreeVisitor.Action.SKIP_SIBLINGS); test(null, 0, path -> TreeVisitor.Action.SKIP_SIBLINGS); }
testSkipSiblings
272,854
void () { test(createRoot(), 1, path -> TreeVisitor.Action.SKIP_CHILDREN); test(null, 0, path -> TreeVisitor.Action.SKIP_CHILDREN); }
testSkipChildren
272,855
void () { testDeepVisit(1); testDeepVisit(10); testDeepVisit(100); testDeepVisit(1000); if (PRINT) return; testDeepVisit(10000); testDeepVisit(100000); }
testDeepVisit
272,856
void (int count) { TreeNode node = node(count); for (int i = 1; i < count; i++) node = node(count - i, node); test(node, count, path -> TreeVisitor.Action.CONTINUE); }
testDeepVisit
272,857
void () { /* Walker walker = new Walker(path -> TreeVisitor.Action.CONTINUE, null, 0); assertResult(walker); */ }
testDoubleStart
272,858
void () { TreeNode root = createRoot(); TreeNode color = root.getChildAt(0); TreeNode digit = root.getChildAt(1); TreeNode greek = root.getChildAt(2); test(root, 1, createFinder(root), root); test(root, 2, createFinder(color), root, color); test(root, 3, createFinder(color.getChildAt(0)), root, color, color.getChildAt(0)); test(root, 4, createFinder(color.getChildAt(1)), root, color, color.getChildAt(1)); test(root, 5, createFinder(color.getChildAt(2)), root, color, color.getChildAt(2)); test(root, 3, createFinder(digit), root, digit); test(root, 4, createFinder(digit.getChildAt(0)), root, digit, digit.getChildAt(0)); test(root, 5, createFinder(digit.getChildAt(1)), root, digit, digit.getChildAt(1)); test(root, 6, createFinder(digit.getChildAt(2)), root, digit, digit.getChildAt(2)); test(root, 7, createFinder(digit.getChildAt(3)), root, digit, digit.getChildAt(3)); test(root, 8, createFinder(digit.getChildAt(4)), root, digit, digit.getChildAt(4)); test(root, 9, createFinder(digit.getChildAt(5)), root, digit, digit.getChildAt(5)); test(root, 10, createFinder(digit.getChildAt(6)), root, digit, digit.getChildAt(6)); test(root, 11, createFinder(digit.getChildAt(7)), root, digit, digit.getChildAt(7)); test(root, 12, createFinder(digit.getChildAt(8)), root, digit, digit.getChildAt(8)); test(root, 4, createFinder(greek), root, greek); test(root, 5, createFinder(greek.getChildAt(0)), root, greek, greek.getChildAt(0)); test(root, 6, createFinder(greek.getChildAt(1)), root, greek, greek.getChildAt(1)); test(root, 7, createFinder(greek.getChildAt(2)), root, greek, greek.getChildAt(2)); test(root, 8, createFinder(greek.getChildAt(3)), root, greek, greek.getChildAt(3)); test(root, 9, createFinder(greek.getChildAt(4)), root, greek, greek.getChildAt(4)); }
testFinder
272,859
void () { TreeNode root = createRoot(); TreeNode color = root.getChildAt(0); TreeNode digit = root.getChildAt(1); TreeNode greek = root.getChildAt(2); TreePath parent = new TreePath(root); test(parent, color, 1, createFinder(root)); test(parent, color, 1, createFinder(color), root, color); test(parent, color, 2, createFinder(color.getChildAt(0)), root, color, color.getChildAt(0)); test(parent, color, 3, createFinder(color.getChildAt(1)), root, color, color.getChildAt(1)); test(parent, color, 4, createFinder(color.getChildAt(2)), root, color, color.getChildAt(2)); test(parent, color, 1, createFinder(digit)); test(parent, color, 1, createFinder(greek)); }
testColorFinder
272,860
void () { TreeNode root = createRoot(); TreeNode color = root.getChildAt(0); TreeNode digit = root.getChildAt(1); TreeNode greek = root.getChildAt(2); TreePath parent = new TreePath(root); test(parent, digit, 1, createFinder(root)); test(parent, digit, 1, createFinder(color)); test(parent, digit, 1, createFinder(digit), root, digit); test(parent, digit, 2, createFinder(digit.getChildAt(0)), root, digit, digit.getChildAt(0)); test(parent, digit, 3, createFinder(digit.getChildAt(1)), root, digit, digit.getChildAt(1)); test(parent, digit, 4, createFinder(digit.getChildAt(2)), root, digit, digit.getChildAt(2)); test(parent, digit, 5, createFinder(digit.getChildAt(3)), root, digit, digit.getChildAt(3)); test(parent, digit, 6, createFinder(digit.getChildAt(4)), root, digit, digit.getChildAt(4)); test(parent, digit, 7, createFinder(digit.getChildAt(5)), root, digit, digit.getChildAt(5)); test(parent, digit, 8, createFinder(digit.getChildAt(6)), root, digit, digit.getChildAt(6)); test(parent, digit, 9, createFinder(digit.getChildAt(7)), root, digit, digit.getChildAt(7)); test(parent, digit, 10, createFinder(digit.getChildAt(8)), root, digit, digit.getChildAt(8)); test(parent, digit, 1, createFinder(greek)); }
testDigitFinder
272,861
void () { TreeNode root = createRoot(); TreeNode color = root.getChildAt(0); TreeNode digit = root.getChildAt(1); TreeNode greek = root.getChildAt(2); TreePath parent = new TreePath(root); test(parent, greek, 1, createFinder(root)); test(parent, greek, 1, createFinder(color)); test(parent, greek, 1, createFinder(digit)); test(parent, greek, 1, createFinder(greek), root, greek); test(parent, greek, 2, createFinder(greek.getChildAt(0)), root, greek, greek.getChildAt(0)); test(parent, greek, 3, createFinder(greek.getChildAt(1)), root, greek, greek.getChildAt(1)); test(parent, greek, 4, createFinder(greek.getChildAt(2)), root, greek, greek.getChildAt(2)); test(parent, greek, 5, createFinder(greek.getChildAt(3)), root, greek, greek.getChildAt(3)); test(parent, greek, 6, createFinder(greek.getChildAt(4)), root, greek, greek.getChildAt(4)); }
testGreekFinder
272,862
TreeVisitor (TreeNode node) { return new TreeVisitor.ByComponent<>(node, o -> o) { @Override protected boolean contains(@NotNull Object pathComponent, @NotNull TreeNode thisComponent) { while (pathComponent != thisComponent && thisComponent != null) thisComponent = thisComponent.getParent(); return thisComponent != null; } }; }
createFinder
272,863
boolean (@NotNull Object pathComponent, @NotNull TreeNode thisComponent) { while (pathComponent != thisComponent && thisComponent != null) thisComponent = thisComponent.getParent(); return thisComponent != null; }
contains
272,864
void () { TreeNode root = createRoot(); TreeNode color = root.getChildAt(0); TreeNode digit = root.getChildAt(1); TreeNode greek = root.getChildAt(2); test(root, 1, createPathFinder("root"), root); test(root, 1, createPathFinder("toor")); // not found test(root, 2, createPathFinder("root", "color"), root, color); test(root, 2, createPathFinderWithoutRoot("color"), root, color); test(root, 4, createPathFinder("root", "roloc")); // not found test(root, 4, createPathFinderWithoutRoot("roloc")); // not found test(root, 3, createPathFinder("root", "color", "red"), root, color, color.getChildAt(0)); test(root, 3, createPathFinderWithoutRoot("color", "red"), root, color, color.getChildAt(0)); test(root, 7, createPathFinder("root", "color", "der")); // not found test(root, 7, createPathFinderWithoutRoot("color", "der")); // not found test(root, 4, createPathFinder("root", "color", "green"), root, color, color.getChildAt(1)); test(root, 4, createPathFinderWithoutRoot("color", "green"), root, color, color.getChildAt(1)); test(root, 7, createPathFinder("root", "color", "neerg")); // not found test(root, 7, createPathFinderWithoutRoot("color", "neerg")); // not found test(root, 5, createPathFinder("root", "color", "blue"), root, color, color.getChildAt(2)); test(root, 5, createPathFinderWithoutRoot("color", "blue"), root, color, color.getChildAt(2)); test(root, 7, createPathFinder("root", "color", "eulb")); // not found test(root, 7, createPathFinderWithoutRoot("color", "eulb")); // not found test(root, 3, createPathFinder("root", "digit"), root, digit); test(root, 3, createPathFinderWithoutRoot("digit"), root, digit); test(root, 4, createPathFinder("root", "tigid")); // not found test(root, 4, createPathFinderWithoutRoot("tigid")); // not found test(root, 4, createPathFinder("root", "digit", "one"), root, digit, digit.getChildAt(0)); test(root, 4, createPathFinderWithoutRoot("digit", "one"), root, digit, digit.getChildAt(0)); test(root, 13, createPathFinder("root", "digit", "eno")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "eno")); // not found test(root, 5, createPathFinder("root", "digit", "two"), root, digit, digit.getChildAt(1)); test(root, 5, createPathFinderWithoutRoot("digit", "two"), root, digit, digit.getChildAt(1)); test(root, 13, createPathFinder("root", "digit", "owt")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "owt")); // not found test(root, 6, createPathFinder("root", "digit", "three"), root, digit, digit.getChildAt(2)); test(root, 6, createPathFinderWithoutRoot("digit", "three"), root, digit, digit.getChildAt(2)); test(root, 13, createPathFinder("root", "digit", "eerht")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "eerht")); // not found test(root, 7, createPathFinder("root", "digit", "four"), root, digit, digit.getChildAt(3)); test(root, 7, createPathFinderWithoutRoot("digit", "four"), root, digit, digit.getChildAt(3)); test(root, 13, createPathFinder("root", "digit", "ruof")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "ruof")); // not found test(root, 8, createPathFinder("root", "digit", "five"), root, digit, digit.getChildAt(4)); test(root, 8, createPathFinderWithoutRoot("digit", "five"), root, digit, digit.getChildAt(4)); test(root, 13, createPathFinder("root", "digit", "evif")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "evif")); // not found test(root, 9, createPathFinder("root", "digit", "six"), root, digit, digit.getChildAt(5)); test(root, 9, createPathFinderWithoutRoot("digit", "six"), root, digit, digit.getChildAt(5)); test(root, 13, createPathFinder("root", "digit", "xis")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "xis")); // not found test(root, 10, createPathFinder("root", "digit", "seven"), root, digit, digit.getChildAt(6)); test(root, 10, createPathFinderWithoutRoot("digit", "seven"), root, digit, digit.getChildAt(6)); test(root, 13, createPathFinder("root", "digit", "neves")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "neves")); // not found test(root, 11, createPathFinder("root", "digit", "eight"), root, digit, digit.getChildAt(7)); test(root, 11, createPathFinderWithoutRoot("digit", "eight"), root, digit, digit.getChildAt(7)); test(root, 13, createPathFinder("root", "digit", "thgie")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "thgie")); // not found test(root, 12, createPathFinder("root", "digit", "nine"), root, digit, digit.getChildAt(8)); test(root, 12, createPathFinderWithoutRoot("digit", "nine"), root, digit, digit.getChildAt(8)); test(root, 13, createPathFinder("root", "digit", "enin")); // not found test(root, 13, createPathFinderWithoutRoot("digit", "enin")); // not found test(root, 4, createPathFinder("root", "greek"), root, greek); test(root, 4, createPathFinderWithoutRoot("greek"), root, greek); test(root, 4, createPathFinder("root", "keerg")); // not found test(root, 4, createPathFinderWithoutRoot("keerg")); // not found test(root, 5, createPathFinder("root", "greek", "alpha"), root, greek, greek.getChildAt(0)); test(root, 5, createPathFinderWithoutRoot("greek", "alpha"), root, greek, greek.getChildAt(0)); test(root, 9, createPathFinder("root", "greek", "ahpla")); // not found test(root, 9, createPathFinderWithoutRoot("greek", "ahpla")); // not found test(root, 6, createPathFinder("root", "greek", "beta"), root, greek, greek.getChildAt(1)); test(root, 6, createPathFinderWithoutRoot("greek", "beta"), root, greek, greek.getChildAt(1)); test(root, 9, createPathFinder("root", "greek", "ateb")); // not found test(root, 9, createPathFinderWithoutRoot("greek", "ateb")); // not found test(root, 7, createPathFinder("root", "greek", "gamma"), root, greek, greek.getChildAt(2)); test(root, 7, createPathFinderWithoutRoot("greek", "gamma"), root, greek, greek.getChildAt(2)); test(root, 9, createPathFinder("root", "greek", "ammag")); // not found test(root, 9, createPathFinderWithoutRoot("greek", "ammag")); // not found test(root, 8, createPathFinder("root", "greek", "delta"), root, greek, greek.getChildAt(3)); test(root, 8, createPathFinderWithoutRoot("greek", "delta"), root, greek, greek.getChildAt(3)); test(root, 9, createPathFinder("root", "greek", "atled")); // not found test(root, 9, createPathFinderWithoutRoot("greek", "atled")); // not found test(root, 9, createPathFinder("root", "greek", "epsilon"), root, greek, greek.getChildAt(4)); test(root, 9, createPathFinderWithoutRoot("greek", "epsilon"), root, greek, greek.getChildAt(4)); test(root, 9, createPathFinder("root", "greek", "nolispe")); // not found test(root, 9, createPathFinderWithoutRoot("greek", "nolispe")); // not found }
testPathFinder
272,865
void () { TreeNode root = createRoot(); TreeNode color = root.getChildAt(0); TreePath parent = new TreePath(root); test(parent, color, 1, createPathFinder("root")); test(parent, color, 1, createPathFinder("toor")); // not found test(parent, color, 1, createPathFinder("root", "color"), root, color); test(parent, color, 1, createPathFinderWithoutRoot("color"), root, color); test(parent, color, 1, createPathFinder("root", "roloc")); // not found test(parent, color, 1, createPathFinderWithoutRoot("roloc")); // not found test(parent, color, 2, createPathFinder("root", "color", "red"), root, color, color.getChildAt(0)); test(parent, color, 2, createPathFinderWithoutRoot("color", "red"), root, color, color.getChildAt(0)); test(parent, color, 4, createPathFinder("root", "color", "der")); // not found test(parent, color, 4, createPathFinderWithoutRoot("color", "der")); // not found test(parent, color, 3, createPathFinder("root", "color", "green"), root, color, color.getChildAt(1)); test(parent, color, 3, createPathFinderWithoutRoot("color", "green"), root, color, color.getChildAt(1)); test(parent, color, 4, createPathFinder("root", "color", "neerg")); // not found test(parent, color, 4, createPathFinderWithoutRoot("color", "neerg")); // not found test(parent, color, 4, createPathFinder("root", "color", "blue"), root, color, color.getChildAt(2)); test(parent, color, 4, createPathFinderWithoutRoot("color", "blue"), root, color, color.getChildAt(2)); test(parent, color, 4, createPathFinder("root", "color", "eulb")); // not found test(parent, color, 4, createPathFinderWithoutRoot("color", "eulb")); // not found test(parent, color, 1, createPathFinder("root", "digit")); test(parent, color, 1, createPathFinderWithoutRoot("digit")); test(parent, color, 1, createPathFinder("root", "tigid")); // not found test(parent, color, 1, createPathFinderWithoutRoot("tigid")); // not found test(parent, color, 1, createPathFinder("root", "greek")); test(parent, color, 1, createPathFinderWithoutRoot("greek")); test(parent, color, 1, createPathFinder("root", "keerg")); // not found test(parent, color, 1, createPathFinderWithoutRoot("keerg")); // not found }
testColorPathFinder
272,866
void () { TreeNode root = createRoot(); TreeNode digit = root.getChildAt(1); TreePath parent = new TreePath(root); test(parent, digit, 1, createPathFinder("root")); test(parent, digit, 1, createPathFinder("toor")); // not found test(parent, digit, 1, createPathFinder("root", "color")); test(parent, digit, 1, createPathFinderWithoutRoot("color")); test(parent, digit, 1, createPathFinder("root", "roloc")); // not found test(parent, digit, 1, createPathFinderWithoutRoot("roloc")); // not found test(parent, digit, 1, createPathFinder("root", "digit"), root, digit); test(parent, digit, 1, createPathFinderWithoutRoot("digit"), root, digit); test(parent, digit, 1, createPathFinder("root", "tigid")); // not found test(parent, digit, 1, createPathFinderWithoutRoot("tigid")); // not found test(parent, digit, 2, createPathFinder("root", "digit", "one"), root, digit, digit.getChildAt(0)); test(parent, digit, 2, createPathFinderWithoutRoot("digit", "one"), root, digit, digit.getChildAt(0)); test(parent, digit, 10, createPathFinder("root", "digit", "eno")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "eno")); // not found test(parent, digit, 3, createPathFinder("root", "digit", "two"), root, digit, digit.getChildAt(1)); test(parent, digit, 3, createPathFinderWithoutRoot("digit", "two"), root, digit, digit.getChildAt(1)); test(parent, digit, 10, createPathFinder("root", "digit", "owt")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "owt")); // not found test(parent, digit, 4, createPathFinder("root", "digit", "three"), root, digit, digit.getChildAt(2)); test(parent, digit, 4, createPathFinderWithoutRoot("digit", "three"), root, digit, digit.getChildAt(2)); test(parent, digit, 10, createPathFinder("root", "digit", "eerht")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "eerht")); // not found test(parent, digit, 5, createPathFinder("root", "digit", "four"), root, digit, digit.getChildAt(3)); test(parent, digit, 5, createPathFinderWithoutRoot("digit", "four"), root, digit, digit.getChildAt(3)); test(parent, digit, 10, createPathFinder("root", "digit", "ruof")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "ruof")); // not found test(parent, digit, 6, createPathFinder("root", "digit", "five"), root, digit, digit.getChildAt(4)); test(parent, digit, 6, createPathFinderWithoutRoot("digit", "five"), root, digit, digit.getChildAt(4)); test(parent, digit, 10, createPathFinder("root", "digit", "evif")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "evif")); // not found test(parent, digit, 7, createPathFinder("root", "digit", "six"), root, digit, digit.getChildAt(5)); test(parent, digit, 7, createPathFinderWithoutRoot("digit", "six"), root, digit, digit.getChildAt(5)); test(parent, digit, 10, createPathFinder("root", "digit", "xis")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "xis")); // not found test(parent, digit, 8, createPathFinder("root", "digit", "seven"), root, digit, digit.getChildAt(6)); test(parent, digit, 8, createPathFinderWithoutRoot("digit", "seven"), root, digit, digit.getChildAt(6)); test(parent, digit, 10, createPathFinder("root", "digit", "neves")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "neves")); // not found test(parent, digit, 9, createPathFinder("root", "digit", "eight"), root, digit, digit.getChildAt(7)); test(parent, digit, 9, createPathFinderWithoutRoot("digit", "eight"), root, digit, digit.getChildAt(7)); test(parent, digit, 10, createPathFinder("root", "digit", "thgie")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "thgie")); // not found test(parent, digit, 10, createPathFinder("root", "digit", "nine"), root, digit, digit.getChildAt(8)); test(parent, digit, 10, createPathFinderWithoutRoot("digit", "nine"), root, digit, digit.getChildAt(8)); test(parent, digit, 10, createPathFinder("root", "digit", "enin")); // not found test(parent, digit, 10, createPathFinderWithoutRoot("digit", "enin")); // not found test(parent, digit, 1, createPathFinder("root", "greek")); test(parent, digit, 1, createPathFinderWithoutRoot("greek")); test(parent, digit, 1, createPathFinder("root", "keerg")); // not found test(parent, digit, 1, createPathFinderWithoutRoot("keerg")); // not found }
testDigitPathFinder
272,867
void () { TreeNode root = createRoot(); TreeNode greek = root.getChildAt(2); TreePath parent = new TreePath(root); test(parent, greek, 1, createPathFinder("root")); test(parent, greek, 1, createPathFinder("toor")); // not found test(parent, greek, 1, createPathFinder("root", "color")); test(parent, greek, 1, createPathFinderWithoutRoot("color")); test(parent, greek, 1, createPathFinder("root", "roloc")); // not found test(parent, greek, 1, createPathFinderWithoutRoot("roloc")); // not found test(parent, greek, 1, createPathFinder("root", "digit")); test(parent, greek, 1, createPathFinderWithoutRoot("digit")); test(parent, greek, 1, createPathFinder("root", "tigid")); // not found test(parent, greek, 1, createPathFinderWithoutRoot("tigid")); // not found test(parent, greek, 1, createPathFinder("root", "greek"), root, greek); test(parent, greek, 1, createPathFinderWithoutRoot("greek"), root, greek); test(parent, greek, 1, createPathFinder("root", "keerg")); // not found test(parent, greek, 1, createPathFinderWithoutRoot("keerg")); // not found test(parent, greek, 2, createPathFinder("root", "greek", "alpha"), root, greek, greek.getChildAt(0)); test(parent, greek, 2, createPathFinderWithoutRoot("greek", "alpha"), root, greek, greek.getChildAt(0)); test(parent, greek, 6, createPathFinder("root", "greek", "ahpla")); // not found test(parent, greek, 6, createPathFinderWithoutRoot("greek", "ahpla")); // not found test(parent, greek, 3, createPathFinder("root", "greek", "beta"), root, greek, greek.getChildAt(1)); test(parent, greek, 3, createPathFinderWithoutRoot("greek", "beta"), root, greek, greek.getChildAt(1)); test(parent, greek, 6, createPathFinder("root", "greek", "ateb")); // not found test(parent, greek, 6, createPathFinderWithoutRoot("greek", "ateb")); // not found test(parent, greek, 4, createPathFinder("root", "greek", "gamma"), root, greek, greek.getChildAt(2)); test(parent, greek, 4, createPathFinderWithoutRoot("greek", "gamma"), root, greek, greek.getChildAt(2)); test(parent, greek, 6, createPathFinder("root", "greek", "ammag")); // not found test(parent, greek, 6, createPathFinderWithoutRoot("greek", "ammag")); // not found test(parent, greek, 5, createPathFinder("root", "greek", "delta"), root, greek, greek.getChildAt(3)); test(parent, greek, 5, createPathFinderWithoutRoot("greek", "delta"), root, greek, greek.getChildAt(3)); test(parent, greek, 6, createPathFinder("root", "greek", "atled")); // not found test(parent, greek, 6, createPathFinderWithoutRoot("greek", "atled")); // not found test(parent, greek, 6, createPathFinder("root", "greek", "epsilon"), root, greek, greek.getChildAt(4)); test(parent, greek, 6, createPathFinderWithoutRoot("greek", "epsilon"), root, greek, greek.getChildAt(4)); test(parent, greek, 6, createPathFinder("root", "greek", "nolispe")); // not found test(parent, greek, 6, createPathFinderWithoutRoot("greek", "nolispe")); // not found }
testGreekPathFinder
272,868
TreeVisitor (String... names) { return new TreeVisitor.ByTreePath<>(TreePathUtil.convertArrayToTreePath(names), Object::toString); }
createPathFinder
272,869
TreeVisitor (String... names) { return new TreeVisitor.ByTreePath<>(true, TreePathUtil.convertArrayToTreePath(names), Object::toString); }
createPathFinderWithoutRoot
272,870
void (TreeNode node, int count, @NotNull TreeVisitor visitor, Object... expected) { test(null, node, count, visitor, expected); }
test
272,871
void (TreePath parent, TreeNode node, int count, TreeVisitor visitor, Object... expected) { test(parent, node, count, false, new Walker(visitor), expected); test(parent, node, count, false, new Walker(visitor) { @Override protected Collection<TreeNode> getChildren(@NotNull TreeNode node) { setChildren(super.getChildren(node)); return null; } }, expected); }
test
272,872
Collection<TreeNode> (@NotNull TreeNode node) { setChildren(super.getChildren(node)); return null; }
getChildren
272,873
void (TreePath parent, TreeNode node, int count, boolean error, Walker walker, Object... expected) { walker.start(parent, node); switch (walker.promise().getState()) { case PENDING -> throw new IllegalStateException("not processed"); case SUCCEEDED -> { if (error) throw new IllegalStateException("not rejected"); } case REJECTED -> { if (!error) throw new IllegalStateException("not fulfilled"); } } TreeVisitor wrapper = getField(AbstractTreeWalker.class, walker, TreeVisitor.class, "visitor"); assertEquals(Integer.valueOf(count), getField(Wrapper.class, wrapper, int.class, "count")); assertResult(walker, TreePathUtil.convertArrayToTreePath(expected)); }
test
272,874
void (Walker walker, TreePath expected) { try { assertEquals("unexpected result", expected, walker.promise().blockingGet(1)); } catch (TimeoutException | ExecutionException e) { throw new AssertionError(e); } }
assertResult
272,875
TreeNode () { return node("root", node("color", "red", "green", "blue"), node("digit", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"), node("greek", "alpha", "beta", "gamma", "delta", "epsilon")); }
createRoot
272,876
Collection<TreeNode> (@NotNull TreeNode node) { int count = node.getChildCount(); ArrayList<TreeNode> list = new ArrayList<>(count); for (int i = 0; i < count; i++) list.add(node.getChildAt(i)); return list; }
getChildren
272,877
Action (@NotNull TreePath path) { count++; if (PRINT) System.out.println(path); return visitor.visit(path); }
visit
272,878
void () { }
dispose
272,879
void (@NotNull Runnable runnable) { TreeModel model = tree.getModel(); if (model instanceof AsyncTreeModel async) { if (async.isProcessing()) { invokeLater(() -> invokeAfterProcessing(runnable)); return; // do nothing if delayed } } invokeSafely(runnable); }
invokeAfterProcessing
272,880
void (@NotNull Runnable runnable) { EventQueue.invokeLater(() -> invokeSafely(runnable)); }
invokeLater
272,881
void (@NotNull Runnable runnable) { try { runnable.run(); } catch (Throwable throwable) { promise.setResult(throwable); } }
invokeSafely
272,882
void (@NotNull String expected, @NotNull Runnable runnable) { assertTree(expected, false, runnable); }
assertTree
272,883
void (@NotNull String expected, boolean showSelection, @NotNull Runnable runnable) { invokeSafely(() -> { Assert.assertEquals(expected, new TreeTestUtil(getTree()).setSelection(showSelection).toString()); runnable.run(); }); }
assertTree
272,884
void (TreePath path, @NotNull Runnable runnable) { invokeSafely(() -> { Assert.assertNotNull(path); Assert.assertTrue(getTree().isVisible(path)); getTree().addSelectionPath(path); runnable.run(); }); }
addSelection
272,885
void () { promise.setResult(null); }
done
272,886
JTree () { return tree; }
getTree
272,887
void (Supplier<? extends TreeNode> supplier, Consumer<? super TreeTest> consumer) { test(FAST, 1, supplier, consumer); test(SLOW, 2, supplier, consumer); }
test
272,888
void (long delay, int minutes, Supplier<? extends TreeNode> supplier, Consumer<? super TreeTest> consumer) { new TreeTest(minutes, consumer, parent -> model(supplier, delay, false, null)); new TreeTest(minutes, consumer, parent -> model(supplier, delay, true, Invoker.forEventDispatchThread(parent))); new TreeTest(minutes, consumer, parent -> model(supplier, delay, false, Invoker.forEventDispatchThread(parent))); new TreeTest(minutes, consumer, parent -> model(supplier, delay, true, Invoker.forBackgroundThreadWithReadAction(parent))); new TreeTest(minutes, consumer, parent -> model(supplier, delay, false, Invoker.forBackgroundThreadWithReadAction(parent))); }
test
272,889
TreeModel (Supplier<? extends TreeNode> supplier, long delay, boolean showLoadingNode, Invoker invoker) { TreeModel model = new DefaultTreeModel(supplier.get()); if (delay > 0) { model = new Wrapper.WithDelay(model, delay); } if (invoker != null) { model = new Wrapper.WithInvoker(model, invoker); model = new AsyncTreeModel(model, showLoadingNode, invoker); } return model; }
model
272,890
Object () { return model.getRoot(); }
getRoot
272,891
Object (Object parent, int index) { return model.getChild(parent, index); }
getChild
272,892
int (Object parent) { return model.getChildCount(parent); }
getChildCount
272,893
int (Object parent, Object child) { return model.getIndexOfChild(parent, child); }
getIndexOfChild
272,894
boolean (Object child) { return model.isLeaf(child); }
isLeaf
272,895
void (TreePath path, Object value) { model.valueForPathChanged(path, value); }
valueForPathChanged
272,896
void (TreeModelListener listener) { model.addTreeModelListener(listener); }
addTreeModelListener
272,897
void (TreeModelListener listener) { model.removeTreeModelListener(listener); }
removeTreeModelListener
272,898
Object () { pause(); return super.getRoot(); }
getRoot
272,899
Object (Object parent, int index) { if (index == 0) pause(); // do not pause for every child return super.getChild(parent, index); }
getChild