private static List<Resource> getResourcesSortedById(final Book book) {
   List<Resource> resources = new ArrayList<>(book.getResources().getAll());
   Collections.sort(
       resources,
       (Resource resource1, Resource resource2) ->
           resource1.getId().compareToIgnoreCase(resource2.getId()));
   return resources;
 }
  public Image get(Object key) {
    try {
      if (book == null) {
        return null;
      }

      String imageURL = key.toString();

      // see if the image is already in the cache
      Image result = cache.get(imageURL);
      if (result != null) {
        return result;
      }

      // get the image resource href
      String resourceHref = getResourceHref(imageURL);

      // find the image resource in the book resources
      Resource imageResource = book.getResources().getByHref(resourceHref);
      if (imageResource == null) {
        return result;
      }

      // create an image from the resource and add it to the cache
      result = createImage(imageResource);

      if (result != null) {
        cache.put(imageURL.toString(), result);
      }
      return result;
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }