Exemplo n.º 1
0
  /**
   * Return sorted top albums based on the average of each album rating.
   *
   * @param bHideUnmounted if true, unmounted albums are not chosen
   * @param iNbBestofAlbums nb of items to return
   * @return top albums, can be less items than required according to nb of available albums
   */
  public List<Album> getBestOfAlbums(boolean bHideUnmounted, int iNbBestofAlbums) {
    // TODO: this code does not look at "bHideUnmounted" at all, so most of this
    // method and
    // the double copying is not necessary, or?

    // create a temporary table to remove unmounted albums
    // We consider an album as mounted if a least one track is mounted
    // This hashmap contains album-> album rates
    final Map<Album, Float> cacheRate =
        new HashMap<Album, Float>(AlbumManager.getInstance().getElementCount());
    ReadOnlyIterator<Album> it = AlbumManager.getInstance().getAlbumsIterator();
    while (it.hasNext()) {
      Album album = it.next();
      cacheRate.put(album, (float) album.getRate());
    }
    // Now sort albums by rating
    List<Album> sortedAlbums = new ArrayList<Album>(cacheRate.keySet());
    Collections.sort(
        sortedAlbums,
        new Comparator<Album>() {
          public int compare(Album o1, Album o2) {
            // lowest first
            return (int) (cacheRate.get(o1) - cacheRate.get(o2));
          }
        });
    return getTopAlbums(sortedAlbums, iNbBestofAlbums);
  }
Exemplo n.º 2
0
 /**
  * Force to refresh the album max rating, it is not done soon as it is pretty CPU consumming and
  * we don't need a track by track rating precision.
  */
 public void refreshMaxRating() {
   // create a temporary table to remove unmounted albums
   // We consider an album as mounted if a least one track is mounted
   // This hashmap contains album-> album rates
   final Map<Album, Float> cacheRate =
       new HashMap<Album, Float>(AlbumManager.getInstance().getElementCount());
   ReadOnlyIterator<Album> it = AlbumManager.getInstance().getAlbumsIterator();
   while (it.hasNext()) {
     Album album = it.next();
     cacheRate.put(album, (float) album.getRate());
   }
   // OK, now keep only the highest score
   for (Map.Entry<Album, Float> album : cacheRate.entrySet()) {
     long value = Math.round(album.getValue());
     if (value > maxRate) {
       maxRate = value;
     }
   }
 }