summaryrefslogtreecommitdiff
path: root/songdbj/AlbumEntry.java
diff options
context:
space:
mode:
authorMichiel Van Der Kolk <not.valid@email.address>2005-07-11 15:42:37 +0000
committerMichiel Van Der Kolk <not.valid@email.address>2005-07-11 15:42:37 +0000
commit9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e (patch)
tree4c304cd4151020bd5494d279ee68a105ae3a5a3a /songdbj/AlbumEntry.java
parentdfa8ecbe609ca8ea194d08560a44fb9a92e94b4b (diff)
Songdb java version, source. only 1.5 compatible
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7101 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'songdbj/AlbumEntry.java')
-rw-r--r--songdbj/AlbumEntry.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/songdbj/AlbumEntry.java b/songdbj/AlbumEntry.java
new file mode 100644
index 0000000000..14c209547b
--- /dev/null
+++ b/songdbj/AlbumEntry.java
@@ -0,0 +1,76 @@
+import java.util.*;
+import java.io.*;
+
+public class AlbumEntry extends Entry implements Comparable {
+ protected String name;
+ protected ArtistEntry artist;
+ protected Vector songs;
+ protected int songcount;
+
+ public AlbumEntry(String n) {
+ name=n;
+ songs=new Vector();
+ artist=null;
+ songcount=0;
+ }
+
+ protected class SongSorter implements Comparator {
+ public int compare(Object o1, Object o2) {
+ SongEntry s1=(SongEntry)o1;
+ SongEntry s2=(SongEntry)o2;
+ int track1=s1.getTrack(),track2=s2.getTrack();
+ if(track1>track2)
+ return 1;
+ else if(track1<track2)
+ return -1;
+ return s1.getFile().getFile().getName().compareTo(s2.getFile().getFile().getName());
+ }
+ }
+
+ public void addSong(SongEntry e) {
+ songs.add(e);
+ e.setAlbum(this);
+ e.setArtist(artist);
+ songcount++;
+ Collections.sort(songs,new SongSorter());
+ }
+
+ public int size() { return songcount; }
+ public void setArtist(ArtistEntry a) {
+ a.addAlbum(this);
+ if(artist!=null&&artist!=a&&!artist.getName().equals("<various artists>")) {
+ artist.removeAlbum(this);
+ artist=TagDatabase.getInstance().getArtistEntry("<various artists>");
+ }
+ else
+ artist=a;
+ }
+ public ArtistEntry getArtist() { return artist; }
+
+ public int compareTo(Object o) {
+ return String.CASE_INSENSITIVE_ORDER.compare(name,((AlbumEntry)o).getName());
+ }
+
+ public String getName() { return name; }
+ public Collection getSongs() { return songs; }
+ public void write(DataOutputStream w) throws IOException {
+ int x;
+ w.writeBytes(name);
+ for(x=TagDatabase.getInstance().albumlen-name.length();x>0;x--)
+ w.write(0);
+ w.writeInt(artist.getOffset());
+ Iterator i2 = songs.iterator();
+ x=0;
+ while(i2.hasNext()) {
+ Entry e = (Entry) i2.next();
+ w.writeInt(e.getOffset());
+ x++;
+ }
+ for(;x<TagDatabase.getInstance().songarraylen;x++)
+ w.writeInt(0);
+ }
+ public static int entrySize() {
+ TagDatabase td=TagDatabase.getInstance();
+ return td.albumlen+4+td.songarraylen*4;
+ }
+} \ No newline at end of file