Esempio n. 1
0
  private SortedSet<Artist> createArtists(
      List<MusicFolder> folders, String[] ignoredArticles, String[] shortcuts) throws IOException {
    SortedMap<String, Artist> artistMap = new TreeMap<String, Artist>();
    Set<String> shortcutSet = new HashSet<String>(Arrays.asList(shortcuts));

    for (MusicFolder folder : folders) {

      MusicFile parent = musicFileService.getMusicFile(folder.getPath());
      List<MusicFile> children = musicFileService.getChildDirectories(parent);
      for (MusicFile child : children) {
        if (shortcutSet.contains(child.getName())) {
          continue;
        }

        String sortableName = createSortableName(child.getName(), ignoredArticles);
        Artist artist = artistMap.get(sortableName);
        if (artist == null) {
          artist = new Artist(child.getName(), sortableName);
          artistMap.put(sortableName, artist);
        }
        artist.addMusicFile(child);
      }
    }

    return new TreeSet<Artist>(artistMap.values());
  }
Esempio n. 2
0
 /**
  * Returns the music index to which the given artist belongs.
  *
  * @param artist The artist in question.
  * @param indexes List of available indexes.
  * @return The music index to which this music file belongs, or {@link MusicIndex#OTHER} if no
  *     index applies.
  */
 private MusicIndex getIndex(Artist artist, List<MusicIndex> indexes) {
   String sortableName = artist.getSortableName().toUpperCase();
   for (MusicIndex index : indexes) {
     for (String prefix : index.getPrefixes()) {
       if (sortableName.startsWith(prefix.toUpperCase())) {
         return index;
       }
     }
   }
   return MusicIndex.OTHER;
 }