Get subset of current threads.

@param pred Predicate to match.
@return {@link ThreadSet} scoped to current runtime containing subset of threads that match the predicate.
320047
public @Nonnull SetType where(ProcessThread.Predicate pred) {
        HashSet<ThreadType> subset = new HashSet<ThreadType>(size() / 2);
        for (ThreadType thread: threads) {
            if (pred.isValid(thread)) subset.add(thread);
        }

        return runtime.getThreadSet(subset);
    }
945219
public @Nonnull SetType derive(@Nonnull Collection<ThreadType> threads) {
        return runtime.getThreadSet(threads);
    }
536767
static public Thread[] getAllThreads() {
        final ThreadGroup root = getRootThreadGroup();
        final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
        int nAlloc = thbean.getThreadCount();
        int n = 0;
        Thread[] threads;
        do {
            nAlloc *= 2;
            threads = new Thread[nAlloc];
            n = root.enumerate(threads, true);
        } while (n == nAlloc);
        return java.util.Arrays.copyOf(threads, n);
    }
1287561
public @Nonnull ThreadType onlyThread() throws IllegalStateException {
        if (size() != 1) throw new IllegalStateException(
                "Exactly one thread expected in the set. Found " + size()
        );

        return threads.iterator().next();
    }
13993
@Override
	public  T listGetPrevious(final T currentElement) {

		Relation<T, T, OneStartpoint<T>, OneEndpoint<T>> prevRel = currentElement.getIncomingRelationship(getSiblingLinkType());
		if (prevRel != null) {

			return (T)prevRel.getSourceNode();
		}

		return null;
	}
1258100
public @CheckForNull JvmThread forThread(@CheckForNull Thread needle) {
        if (needle == null) return null;

        for (JvmThread candidate: this) {
            final JvmThread jvmThread = candidate;
            if (needle.equals(jvmThread.getThread())) return jvmThread;
        }
        return null;
    }
462514
public static ThreadGroup findRootThreadGroup()
    {
        ThreadGroup root = Thread.currentThread().getThreadGroup();
        while (root.getParent() != null) {
            root = root.getParent();
        }
        return root;
    }
1020135
private Thread[] getAllThreads() {
		
	    final ThreadGroup root = getRootThreadGroup( );
	    int ct = Thread.activeCount();
	    int n = 0;
	    Thread[] threads;
	    do {
	        ct *= 2;
	        threads = new Thread[ ct ];
	        n = root.enumerate( threads, true );
	    } while ( n == ct );
	    return java.util.Arrays.copyOf( threads, n );
		
	}
750964
public <T> List<Class<? extends T>> getImplementations(final Class<T> clazz, Predicate<Class<? extends T>> predicate)
	{
		final long started = System.currentTimeMillis();
		try
		{
			if (clazz.isInterface())
				return filter(finder.findImplementations(clazz), predicate);
			else
				return filter(finder.findSubclasses(clazz), predicate);
		}
		finally
		{
			final long finished = System.currentTimeMillis();
			searchTime.addAndGet(finished - started);

			if (log.isTraceEnabled())
				log.trace("getExtendingClasses " +
				          clazz +
				          " with predicate=" +
				          predicate +
				          " returned in " +
				          (finished - started) +
				          " ms");
		}
	}
1228454
def _all_pred(opts)
      predicate = opts[:predicate]
      raise 'predicate must be provided' unless predicate

      visible = opts.fetch :visible, true
      %($.mainApp().getAllWithPredicate("#{predicate}", #{visible});)
    end
126321
def findall_with_pred(predicate, prs):
    
    return sorted((p for p in prs if predicate(p)),
                  key=operator.methodcaller("priority"), reverse=True)
256506
public static Mapper filterMapper(final Predicate pred){
        return new Mapper(){
            public Object map(Object a) {
                return pred.evaluate(a) ? a : null;
            }
        };
    }
481435
private static <T> ThreadContext<T> getCurrentThreadContext(ThreadContext<T> threadContext)
    {
        return ((ThreadContextImpl<T>) threadContext).get();
    }
108971
private Thread fullGetFirstQueuedThread() {
        /*
         * The first node is normally head.next. Try to get its
         * thread field, ensuring consistent reads: If thread
         * field is nulled out or s.prev is no longer head, then
         * some other thread(s) concurrently performed setHead in
         * between some of our reads. We try this twice before
         * resorting to traversal.
         */
        Node h, s;
        Thread st;
        if (((h = head) != null && (s = h.next) != null &&
             s.prev == head && (st = s.thread) != null) ||
            ((h = head) != null && (s = h.next) != null &&
             s.prev == head && (st = s.thread) != null))
            return st;

        /*
         * Head's next field might not have been set yet, or may have
         * been unset after setHead. So we must check to see if tail
         * is actually first node. If not, we continue on, safely
         * traversing from tail back to head to find first,
         * guaranteeing termination.
         */

        Thread firstThread = null;
        for (Node p = tail; p != null && p != head; p = p.prev) {
            Thread t = p.thread;
            if (t != null)
                firstThread = t;
        }
        return firstThread;
    }
677680
public Set<String> getRegisteredAccountReservationKeysForCurrentThread() {
		lock.lock();
		try {
			Map<MailAccount, String> accountsForThread = transformValues(filterValues(usedAccounts, new CurrentThreadWrapperPredicate()),
					new Function<ThreadReservationKeyWrapper, String>() {
						@Override
						public String apply(final ThreadReservationKeyWrapper input) {
							return input.accountReservationKey;
						}
					}
			);

			return ImmutableSet.copyOf(accountsForThread.values());
		} finally {
			lock.unlock();
		}
	}
522412
public @CheckForNull ThreadType getBlockingThread() {
        if (state.waitingToLock == null && state.waitingOnLock == null) {
            return null;
        }

        for (ThreadType thread: runtime.getThreads()) {
            if (thread == this) continue;
            Set<ThreadLock> acquired = thread.getAcquiredLocks();
            if (acquired.isEmpty()) continue;
            if (acquired.contains(state.waitingToLock) || acquired.contains(state.waitingOnLock)) {
                return thread;
            }
        }

        return null;
    }
1341088
public int threads() {
        return Integer.parseInt(
            this.map.getOrDefault(
                "threads",
                String.valueOf(Runtime.getRuntime().availableProcessors() << 2)
            )
        );
    }