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);
  }
 /** @return ItemManager associated with selected element in combo box */
 ItemManager getItemManager() {
   ItemManager im = null;
   switch (jcbItemChoice.getSelectedIndex()) {
     case 0:
       im = TrackManager.getInstance();
       break;
     case 1:
       im = FileManager.getInstance();
       break;
     case 2:
       im = StyleManager.getInstance();
       break;
     case 3:
       im = AuthorManager.getInstance();
       break;
     case 4:
       im = AlbumManager.getInstance();
       break;
     case 5:
       im = DeviceManager.getInstance();
       break;
     case 6:
       im = DirectoryManager.getInstance();
       break;
     case 7:
       im = PlaylistFileManager.getInstance();
       break;
     case 8:
       im = YearManager.getInstance();
       break;
   }
   return im;
 }
Exemplo n.º 3
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;
     }
   }
 }
Exemplo n.º 4
0
 /**
  * Return ordered rarely listen albums list.
  *
  * @param bHideUnmounted if true, unmounted albums are not chosen
  * @param iNb nb of items to return
  * @return top albums, can be less items than required according to nb of available albums
  */
 public List<Album> getRarelyListenAlbums(boolean bHideUnmounted, int iNb) {
   // 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 hits (each track hit average)
   final Map<Album, Float> cache =
       new HashMap<Album, Float>(AlbumManager.getInstance().getElementCount());
   // This hashmap contains album-> nb of tracks already taken into account
   // for average
   Map<Album, Integer> cacheNb =
       new HashMap<Album, Integer>(AlbumManager.getInstance().getElementCount());
   ReadOnlyIterator<Track> it = TrackManager.getInstance().getTracksIterator();
   while (it.hasNext()) {
     Track track = it.next();
     if (track.getPlayeableFile(bHideUnmounted) != null) {
       float newHits = 0f;
       Integer nb = cacheNb.get(track.getAlbum());
       if (nb == null) {
         nb = 0;
       }
       Float previousRate = cache.get(track.getAlbum());
       if (previousRate == null) {
         newHits = track.getHits();
       } else {
         newHits = ((previousRate * nb) + track.getHits()) / (nb + 1);
       }
       cacheNb.put(track.getAlbum(), nb + 1);
       cache.put(track.getAlbum(), newHits);
     }
   }
   // Now sort albums by rating
   List<Album> sortedAlbums = new ArrayList<Album>(cache.keySet());
   Collections.sort(
       sortedAlbums,
       new Comparator<Album>() {
         public int compare(Album o1, Album o2) {
           // We inverse comparison as we want lowest scores
           return (int) (cache.get(o2) - cache.get(o1));
         }
       });
   return getTopAlbums(sortedAlbums, iNb);
 }
Exemplo n.º 5
0
 /**
  * Return 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) {
   // 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 HashMap<Album, Float> cacheRate =
       new HashMap<Album, Float>(AlbumManager.getInstance().getElementCount());
   // This hashmap contains album-> nb of tracks already taken into account
   // for average
   HashMap<Album, Integer> cacheNb =
       new HashMap<Album, Integer>(AlbumManager.getInstance().getElementCount());
   for (Track track : TrackManager.getInstance().getTracks()) {
     if (track.getPlayeableFile(bHideUnmounted) != null) {
       float newRate = 0f;
       Integer nb = cacheNb.get(track.getAlbum());
       if (nb == null) {
         nb = 0;
       }
       Float previousRate = cacheRate.get(track.getAlbum());
       if (previousRate == null) {
         newRate = track.getRate();
       } else {
         newRate = ((previousRate * nb) + track.getRate()) / (nb + 1);
       }
       cacheNb.put(track.getAlbum(), nb + 1);
       cacheRate.put(track.getAlbum(), newRate);
     }
   }
   // Now sort albums by rating
   ArrayList<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.º 6
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 HashMap<Album, Float> cacheRate =
       new HashMap<Album, Float>(AlbumManager.getInstance().getElementCount());
   // This hashmap contains album-> nb of tracks already taken into account
   // for average
   HashMap<Album, Integer> cacheNb =
       new HashMap<Album, Integer>(AlbumManager.getInstance().getElementCount());
   for (Track track : TrackManager.getInstance().getTracks()) {
     if (track.getPlayeableFile(ConfigurationManager.getBoolean(CONF_OPTIONS_HIDE_UNMOUNTED))
         != null) {
       float newRate = 0f;
       Integer nb = cacheNb.get(track.getAlbum());
       if (nb == null) {
         nb = 0;
       }
       Float previousRate = cacheRate.get(track.getAlbum());
       if (previousRate == null) {
         newRate = track.getRate();
       } else {
         newRate = ((previousRate * nb) + track.getRate()) / (nb + 1);
       }
       cacheNb.put(track.getAlbum(), nb + 1);
       cacheRate.put(track.getAlbum(), newRate);
     }
   }
   // OK, now keep only the highest score
   for (Album album : cacheRate.keySet()) {
     long value = Math.round(cacheRate.get(album));
     if (value > maxRate) {
       maxRate = value;
     }
   }
 }
Exemplo n.º 7
0
 /**
  * Get albums associated with this item
  *
  * @param item
  * @return
  */
 public Set<Album> getAssociatedAlbums(Item item) {
   synchronized (AlbumManager.getInstance().getLock()) {
     Set<Album> out = new TreeSet<Album>();
     // If item is a track, return albums containing this track
     if (item instanceof Track) {
       // we can return as a track has only one album
       if (item != null) {
         out.add(((Track) item).getAlbum());
       }
     } else {
       Set<Track> tracks = TrackManager.getInstance().getAssociatedTracks(item);
       for (Track track : tracks) {
         out.add(track.getAlbum());
       }
     }
     return out;
   }
 }
Exemplo n.º 8
0
 /**
  * Return newest albums
  *
  * @param bHideUnmounted if true, unmounted albums are not chosen
  * @param iNb nb of items to return
  * @return newest albums
  */
 public List<Album> getNewestAlbums(boolean bHideUnmounted, int iNb) {
   // 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-> discovery date
   final HashMap<Album, Date> cache =
       new HashMap<Album, Date>(AlbumManager.getInstance().getElementCount());
   for (Track track : TrackManager.getInstance().getTracks()) {
     if (track.getPlayeableFile(bHideUnmounted) != null) {
       cache.put(track.getAlbum(), track.getAdditionDate());
     }
   }
   // Now sort albums by discovery date
   ArrayList<Album> sortedAlbums = new ArrayList<Album>(cache.keySet());
   Collections.sort(
       sortedAlbums,
       new Comparator<Album>() {
         public int compare(Album o1, Album o2) {
           return cache.get(o1).compareTo(cache.get(o2));
         }
       });
   return getTopAlbums(sortedAlbums, iNb);
 }