- /** Compares two {@link Album}s by {@link #getTitle()}. */
- Comparator<Album> TITLE_COMPARATOR = new Comparator<Album>() {
-
- @Override
- public int compare(Album leftAlbum, Album rightAlbum) {
- return leftAlbum.getTitle().compareToIgnoreCase(rightAlbum.getTitle());
- }
- };
-
- /** Function that flattens the given album and all albums beneath it. */
- Function<Album, List<Album>> FLATTENER = new Function<Album, List<Album>>() {
-
- @Override
- @Nonnull
- public List<Album> apply(Album album) {
- if (album == null) {
- return emptyList();
- }
- List<Album> albums = new ArrayList<Album>();
- albums.add(album);
- for (Album subAlbum : album.getAlbums()) {
- albums.addAll(FluentIterable.from(ImmutableList.of(subAlbum)).transformAndConcat(FLATTENER).toList());
- }
- return albums;
- }
- };
-