code: @SuppressWarnings("unchecked")
      private static <T> T convert(final Resource resource, final Class<T> targetType) {
          if (resource == null) {
              return null;
          }
          if (targetType.isAssignableFrom(resource.getClass())) {
              return (T) resource;
          }
          return resource.adaptTo(targetType);
      }
docs: Converts the given {@link Resource} to the given target type
  by either {@link import org.apache.sling.api.adapter.Adaptable#adaptTo(Class) adapting}
  the resource to the target type or by returning the resource itself if the target type
  is {@link Resource}.