return new MusicLibrary()
{
public Track getById(long id)
{
Track result = idToTrack.get(id);
if (result != null) return result;
throw new IllegalArgumentException(String.format("No track with id #%d.", id));
}
public List<Track> getTracks()
{
return tracks;
}
public List<Track> findByMatchingTitle(String title)
{
String titleLower = title.toLowerCase();
List<Track> result = CollectionFactory.newList();
for (Track t : tracks)
{
if (t.getTitle().toLowerCase().contains(titleLower)) result.add(t);
}
return result;
}
};