public <T> T findWithRole(String id, Class<T> role) { Account account = findById(id); if (!role.isAssignableFrom(account.getClass())) { throw new NotFoundException(); } return (T) account; }
public Collection<Account> withRole(Class<?> role) { ArrayList<Account> result = new ArrayList<Account>(); for (Account account : accounts.values()) { if (role.isAssignableFrom(account.getClass())) { result.add(account); } } return result; }