sk.baka.ambient.playlist
Class Utils

java.lang.Object
  extended by sk.baka.ambient.playlist.Utils

public final class Utils
extends Object

Utility methods.

Author:
Martin Vysny

Field Summary
static Comparator<PlaylistItem> PLAYLIST_ALBUM_ORDER_COMPARATOR
          Orders the tracks by albums, track number and finally by filenames.
static Random RANDOM
          The random number generator.
 
Method Summary
static void addToAlbumMap(Map<String,List<TrackMetadataBean>> albumMap, TrackMetadataBean item)
          Adds given track to the album map structure.
static List<PlaylistItem> filterOnAlbum(List<PlaylistItem> playlist, String album)
          Creates new list, having all items with given album.
static Map<String,List<TrackMetadataBean>> getAlbumsFromBeans(List<TrackMetadataBean> playlist, boolean sort)
          Retrieves a map of album names to a list of tracks in that particular album.
static Map<String,List<PlaylistItem>> getAlbumsFromPlaylist(List<PlaylistItem> playlist)
          Retrieves a map of album names to a list of tracks in that particular album.
static List<PlaylistItem> getAlbumSublist(List<PlaylistItem> playlist, String album)
          Returns List.subList(int, int) from given list with all items having given album.
static void removeFromAlbumMap(Map<String,List<TrackMetadataBean>> albumMap, TrackMetadataBean item)
          Removes given track from the album map structure.
static void replaceLocations(List<PlaylistItem> playlist, Map<String,String> locationMap)
          Modifies the playlist by changing all PlaylistItem locations.
static void sortPlaylistByAlbumOrder(List<PlaylistItem> playlist)
          Sorts the tracks by albums, track number and finally by filenames.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLAYLIST_ALBUM_ORDER_COMPARATOR

public static final Comparator<PlaylistItem> PLAYLIST_ALBUM_ORDER_COMPARATOR
Orders the tracks by albums, track number and finally by filenames.


RANDOM

public static final Random RANDOM
The random number generator.

Method Detail

sortPlaylistByAlbumOrder

public static void sortPlaylistByAlbumOrder(List<PlaylistItem> playlist)
Sorts the tracks by albums, track number and finally by filenames.

Parameters:
playlist - the playlist to sort.

getAlbumsFromPlaylist

public static Map<String,List<PlaylistItem>> getAlbumsFromPlaylist(List<PlaylistItem> playlist)
Retrieves a map of album names to a list of tracks in that particular album.

Parameters:
playlist - retrieve the map from this playlist.
Returns:
map from album name to its tracks. The track ordering is the same as in the playlist. Same tracks may appear multiple times in the album if they appeared multiple times in the original playlist.

addToAlbumMap

public static void addToAlbumMap(Map<String,List<TrackMetadataBean>> albumMap,
                                 TrackMetadataBean item)
Adds given track to the album map structure.

Parameters:
albumMap - the map to modify, must not be null
item - the track to add, must not be null

removeFromAlbumMap

public static void removeFromAlbumMap(Map<String,List<TrackMetadataBean>> albumMap,
                                      TrackMetadataBean item)
Removes given track from the album map structure.

Parameters:
albumMap - the map to modify, must not be null
item - the track to remove, must not be null

getAlbumsFromBeans

public static Map<String,List<TrackMetadataBean>> getAlbumsFromBeans(List<TrackMetadataBean> playlist,
                                                                     boolean sort)
Retrieves a map of album names to a list of tracks in that particular album.

Parameters:
playlist - retrieve the map from this playlist.
sort - if true then all albums tracks will be sorted.
Returns:
map from album name to its tracks. The track ordering is the same as in the playlist unless sort is required. Same tracks may appear multiple times in the album if they appeared multiple times in the original playlist.

getAlbumSublist

public static List<PlaylistItem> getAlbumSublist(List<PlaylistItem> playlist,
                                                 String album)
Returns List.subList(int, int) from given list with all items having given album.

Parameters:
playlist - the playlist
album - the album to search for
Returns:
first continuous sublist from given list with given album name. Returns empty list from the end of the playlist if no album match.

filterOnAlbum

public static List<PlaylistItem> filterOnAlbum(List<PlaylistItem> playlist,
                                               String album)
Creates new list, having all items with given album.

Parameters:
playlist - the playlist
album - the album to search for
Returns:
all items from given playlist in the playlist ordering. Never null, may be empty.

replaceLocations

public static void replaceLocations(List<PlaylistItem> playlist,
                                    Map<String,String> locationMap)
Modifies the playlist by changing all PlaylistItem locations.

Parameters:
locationMap - maps old locations to new locations.
playlist - the playlist


Copyright © 2007-2008. All Rights Reserved.