Improves performance and accuracy of the song list.

Most of the problem was sorting stuff.
This commit is contained in:
Markil3
2021-09-14 13:26:25 -06:00
parent 849771853c
commit 2e8b65ca9c
7 changed files with 599 additions and 273 deletions

View File

@@ -4,6 +4,8 @@
package edu.regis.universeplayer.data;
import java.util.Arrays;
import javax.swing.ImageIcon;
public class Album implements Comparable<Album>
@@ -20,13 +22,22 @@ public class Album implements Comparable<Album>
@Override
public int compareTo(Album o)
{
if (o != null)
if (o != null && o.name != null)
{
return this.name.compareTo(o.name);
return this.name.compareToIgnoreCase(o.name);
}
else
{
return -1;
}
}
@Override
public String toString()
{
return "Album{" +
"name='" + name + '\'' +
", artists=" + Arrays.toString(artists) +
'}';
}
}

View File

@@ -4,9 +4,52 @@
package edu.regis.universeplayer.data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
public class InternetSong extends Song
{
private static final Logger logger = LoggerFactory
.getLogger(InternetSong.class);
public URL location;
@Override
public int compareTo(Song o)
{
int compare = super.compareTo(o);
if (compare == 0)
{
if (o instanceof LocalSong)
{
try
{
compare =
this.location.toURI()
.compareTo(((InternetSong) o).location
.toURI());
}
catch (URISyntaxException e)
{
logger.error("Could not compare locations {} and {}",
this.location, ((InternetSong) o).location, e);
}
}
}
return compare;
}
@Override
public String toString()
{
return "Song{" +
"title='" + title + '\'' +
", artists=" + Arrays.toString(artists) +
", album=" + album +
", url=" + location +
'}';
}
}

View File

@@ -5,6 +5,7 @@
package edu.regis.universeplayer.data;
import java.io.File;
import java.util.Arrays;
/**
* This song represents a song found on the local file system.
@@ -14,4 +15,29 @@ public class LocalSong extends Song
public File file;
public String type;
public String codec;
@Override
public int compareTo(Song o)
{
int compare = super.compareTo(o);
if (compare == 0)
{
if (o instanceof LocalSong)
{
compare = this.file.compareTo(((LocalSong) o).file);
}
}
return compare;
}
@Override
public String toString()
{
return "Song{" +
"title='" + title + '\'' +
", artists=" + Arrays.toString(artists) +
", album=" + album +
", url=" + file.getAbsolutePath() +
'}';
}
}

View File

@@ -5,6 +5,7 @@
package edu.regis.universeplayer.data;
import java.io.Serializable;
import java.util.Arrays;
/**
* Contains data for a song.
@@ -16,18 +17,20 @@ public class Song implements Comparable<Song>, Serializable
public int trackNum;
public int disc;
public long duration;
/**
* A reference to the album this song is part of.
*/
public Album album;
@Override
public int compareTo(Song o)
{
if (o != null)
{
int comp = this.album != null ? this.album.compareTo(o.album) : o.album != null ? 1 : 0;
int comp = this.album != null ?
(o.album != null ? this.album.compareTo(o.album) :
-1) : o.album != null ? 1 : 0;
if (comp == 0)
{
comp = Integer.compare(this.disc, o.disc);
@@ -36,7 +39,10 @@ public class Song implements Comparable<Song>, Serializable
comp = Integer.compare(this.trackNum, o.trackNum);
if (comp == 0)
{
comp = this.title != null ? this.title.compareTo(o.title) : o.title != null ? 1 : 0;
comp = this.title != null ?
(o.title != null ?
this.title.compareTo(o.title) :
-1) : o.title != null ? 1 : 0;
}
}
}
@@ -47,4 +53,14 @@ public class Song implements Comparable<Song>, Serializable
return -1;
}
}
@Override
public String toString()
{
return "Song{" +
"title='" + title + '\'' +
", artists=" + Arrays.toString(artists) +
", album=" + album +
'}';
}
}