1 package org.simantics.db.common.recursive;
3 import java.util.Collections;
6 import org.simantics.db.Resource;
7 import org.simantics.db.exception.DatabaseException;
9 import gnu.trove.set.hash.THashSet;
12 * Finds all roots reachable by {@code children} function
14 public abstract class FindRoots extends CachedRecursiveSearch<Set<Resource>> {
15 protected abstract boolean isRoot(Resource resource) throws DatabaseException;
17 protected Set<Resource> getSourceValue(Resource resource) throws org.simantics.db.exception.DatabaseException {
19 return Collections.singleton(resource);
24 private static int sharedElements(Set<Resource> a, Set<Resource> b) {
33 protected Set<Resource> combineNotNull(Set<Resource> a, Set<Resource> b) throws DatabaseException {
39 shared = sharedElements(a, b);
44 shared = sharedElements(b, a);
49 // Both set contain elements not in the other set
50 THashSet<Resource> combined = new THashSet<Resource>(aSize + bSize - shared);