public <T> Collection<T> byType(Class<T> type) {
        if (realmPrincipals == null || realmPrincipals.isEmpty()) {
            return Collections.EMPTY_SET;
        }
        Set<T> typed = new LinkedHashSet<T>();
        Collection<Set> values = realmPrincipals.values();
        for (Set set : values) {
            for (Object o : set) {
                if (type.isAssignableFrom(o.getClass())) {
                    typed.add((T) o);
                }
            }
        }
        if (typed.isEmpty()) {
            return Collections.EMPTY_SET;
        }
        return Collections.unmodifiableSet(typed);
    }
Returns the first available principal from any of the {@code Realm} principals, or {@code null} if there are
no principals yet.
<p/>
The 'first available principal' is interpreted as the principal that would be returned by
<code>{@link #iterator() iterator()}.{@link java.util.Iterator#next() next()}.</code>

@inheritDoc
core/src/main/java/org/apache/shiro/subject/SimplePrincipalCollection.java