class Types {

    @SuppressWarnings("unchecked") // This is actually checked
    public static <O, T extends O> ImmutableList<T> getInstancesOfTypeUntil(Collection<O> collection, Class<T> clazz, Predicate<O> condition) {
        Builder<T> resultBuilder = ImmutableList.builder();

        for (O o : collection) {
            if (!condition.test(o)) {
                break;
            }

            if (clazz.isAssignableFrom(o.getClass())) {
                resultBuilder.add((T) o);
            }
        }

        return resultBuilder.build();
    }

    private  Types();

}