Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase speed of finding components in large swing hierarchy. #261

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ final class FinderDelegate {
@Nonnull
Collection<Component> find(@Nonnull ComponentHierarchy h, @Nonnull ComponentMatcher m) {
Set<Component> found = newLinkedHashSet();
for (Component c : rootsOf(h)) {
find(h, m, checkNotNull(c), found);
}
execute(() -> {
for (Component c : rootsOf(h)) {
find(h, m, checkNotNull(c), found);
}
});
return found;
}

Expand All @@ -56,29 +58,31 @@ private void find(@Nonnull ComponentHierarchy h, @Nonnull ComponentMatcher m, @N
@RunsInEDT
@Nonnull private static Collection<Component> childrenOfComponent(final @Nonnull Component c,
final @Nonnull ComponentHierarchy h) {
Collection<Component> children = execute(() -> h.childrenOf(c));
Collection<Component> children = h.childrenOf(c);
return checkNotNull(children);
}

@RunsInEDT
private static boolean isMatching(@Nonnull final Component c, @Nonnull final ComponentMatcher m) {
Boolean matching = execute(() -> m.matches(c));
Boolean matching = m.matches(c);
return checkNotNull(matching);
}

@RunsInEDT
@Nonnull
<T extends Component> Collection<T> find(@Nonnull ComponentHierarchy h, @Nonnull GenericTypeMatcher<T> m) {
Set<T> found = newLinkedHashSet();
for (Component c : rootsOf(h)) {
find(h, m, checkNotNull(c), found);
}
execute(() -> {
for (Component c : rootsOf(h)) {
find(h, m, checkNotNull(c), found);
}
});
return found;
}

@RunsInEDT
@Nonnull private static Collection<? extends Component> rootsOf(final @Nonnull ComponentHierarchy h) {
return checkNotNull(execute(() -> h.roots()));
return checkNotNull(h.roots());
}

@RunsInEDT
Expand All @@ -95,7 +99,7 @@ private <T extends Component> void find(@Nonnull ComponentHierarchy h, @Nonnull
@RunsInEDT
private static <T extends Component> boolean isMatching(final @Nonnull Component c,
final @Nonnull GenericTypeMatcher<T> m) {
Boolean matching = execute(() -> m.matches(c));
Boolean matching = m.matches(c);
return checkNotNull(matching);
}
}