code: public TypedQuery<Long> count(Filter filter) {
          CriteriaQuery<Long> query = cb.createQuery(Long.class);
          Root<T> from = query.from(getEntityClass());
  
          if (filter != null) {
              Predicate where = new CriteriaMapper(from, cb).create(filter);
              query.where(where);
          }
  
          return getEntityManager().createQuery(query.select(cb.count(from)));
      }
docs: Creates a new TypedQuery that queries the amount of entities of the entity class of this QueryFactory, that a
  query for the given Filter would return.
  
  @param filter the filter
  @return a query