From a1a18f77a50804e0127dfa4b0f5240c49c541184 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 2 Jul 2012 21:24:02 -0700 Subject: Initial Commit --- .../sourceforge/subsonic/domain/MusicIndex.java | 167 +++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 subsonic-main/src/main/java/net/sourceforge/subsonic/domain/MusicIndex.java (limited to 'subsonic-main/src/main/java/net/sourceforge/subsonic/domain/MusicIndex.java') diff --git a/subsonic-main/src/main/java/net/sourceforge/subsonic/domain/MusicIndex.java b/subsonic-main/src/main/java/net/sourceforge/subsonic/domain/MusicIndex.java new file mode 100644 index 00000000..5753fa4d --- /dev/null +++ b/subsonic-main/src/main/java/net/sourceforge/subsonic/domain/MusicIndex.java @@ -0,0 +1,167 @@ +/* + This file is part of Subsonic. + + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + + Copyright 2009 (C) Sindre Mehus + */ +package net.sourceforge.subsonic.domain; + +import java.util.ArrayList; +import java.util.List; +import java.io.Serializable; + +/** + * A music index is a mapping from an index string to a list of prefixes. A complete index consists of a list of + * MusicIndex instances.

+ *

+ * For a normal alphabetical index, such a mapping would typically be "A" -> ["A"]. The index can also be used + * to group less frequently used letters, such as "X-Å" -> ["X", "Y", "Z", "Æ", "Ø", "Å"], or to make multiple + * indexes for frequently used letters, such as "SA" -> ["SA"] and "SO" -> ["SO"]

+ *

+ * Clicking on an index in the user interface will typically bring up a list of all music files that are categorized + * under that index. + * + * @author Sindre Mehus + */ +public class MusicIndex implements Serializable { + + public static final MusicIndex OTHER = new MusicIndex("#"); + + private final String index; + private final List prefixes = new ArrayList(); + + /** + * Creates a new index with the given index string. + * + * @param index The index string, e.g., "A" or "The". + */ + public MusicIndex(String index) { + this.index = index; + } + + /** + * Adds a prefix to this index. Music files that starts with this prefix will be categorized under this index entry. + * + * @param prefix The prefix. + */ + public void addPrefix(String prefix) { + prefixes.add(prefix); + } + + /** + * Returns the index name. + * + * @return The index name. + */ + public String getIndex() { + return index; + } + + /** + * Returns the list of prefixes. + * + * @return The list of prefixes. + */ + public List getPrefixes() { + return prefixes; + } + + /** + * Returns whether this object is equal to another one. + * + * @param o Object to compare to. + * @return true if, and only if, the other object is a MusicIndex with the same + * index name as this one. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof MusicIndex)) { + return false; + } + + final MusicIndex musicIndex = (MusicIndex) o; + + if (index != null ? !index.equals(musicIndex.index) : musicIndex.index != null) { + return false; + } + + return true; + } + + /** + * Returns a hash code for this object. + * + * @return A hash code for this object. + */ + @Override + public int hashCode() { + return (index != null ? index.hashCode() : 0); + } + + /** + * An artist in an index. + */ + public static class Artist implements Comparable, Serializable { + + private final String name; + private final String sortableName; + private final List mediaFiles = new ArrayList(); + + public Artist(String name, String sortableName) { + this.name = name; + this.sortableName = sortableName; + } + + public void addMediaFile(MediaFile mediaFile) { + mediaFiles.add(mediaFile); + } + + public String getName() { + return name; + } + + public String getSortableName() { + return sortableName; + } + + public List getMediaFiles() { + return mediaFiles; + } + + public int compareTo(Artist artist) { + return sortableName.compareToIgnoreCase(artist.sortableName); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Artist artist = (Artist) o; + return sortableName.equalsIgnoreCase(artist.sortableName); + } + + @Override + public int hashCode() { + return sortableName.hashCode(); + } + } +} -- cgit v1.2.3