From 4c18bd07a26d7077ee21d803b8e6147f543ed4f9 Mon Sep 17 00:00:00 2001 From: aj Date: Thu, 5 Apr 2018 00:10:58 -0700 Subject: [PATCH] fmobj comparable, objects in objlist get sorted --- .../src/sarsoo/fmframework/drive/Driver.java | 10 +-- .../sarsoo/fmframework/gui/FMObjListView.java | 4 + .../src/sarsoo/fmframework/music/Album.java | 76 ++++++++++--------- .../src/sarsoo/fmframework/music/Artist.java | 57 +++++++------- .../src/sarsoo/fmframework/music/FMObj.java | 8 +- .../src/sarsoo/fmframework/music/Track.java | 53 +++++++------ 6 files changed, 116 insertions(+), 92 deletions(-) diff --git a/fmframework/src/sarsoo/fmframework/drive/Driver.java b/fmframework/src/sarsoo/fmframework/drive/Driver.java index 9804442..a99af90 100644 --- a/fmframework/src/sarsoo/fmframework/drive/Driver.java +++ b/fmframework/src/sarsoo/fmframework/drive/Driver.java @@ -9,17 +9,17 @@ import sarsoo.fmframework.util.Reference; public class Driver { public static void main(String[] args) { - String username = JOptionPane.showInputDialog(null, "Enter User-Name"); +// String username = JOptionPane.showInputDialog(null, "Enter User-Name"); // System.out.println(username); - if (username != null) { -// Reference.setUserName("sarsoo"); - Reference.setUserName(username); +// if (username != null) { + Reference.setUserName("sarsoo"); +// Reference.setUserName(username); // System.out.println(Getter.getScrobbles(Reference.getUserName())); MainMenu main = new MainMenu(); main.setVisible(true); - } +// } } } diff --git a/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java b/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java index 875ecd8..0fec403 100644 --- a/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java +++ b/fmframework/src/sarsoo/fmframework/gui/FMObjListView.java @@ -7,6 +7,7 @@ import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.text.NumberFormat; +import java.util.Collections; import java.util.Locale; import javax.swing.JButton; @@ -64,6 +65,9 @@ public class FMObjListView extends JFrame { add(headerLabels); + Collections.sort(objects); + Collections.reverse(objects); + int counter; for (counter = 0; counter < objects.size(); counter++) { FMObj fmObj = objects.get(counter); diff --git a/fmframework/src/sarsoo/fmframework/music/Album.java b/fmframework/src/sarsoo/fmframework/music/Album.java index bb80a22..bd36dbd 100644 --- a/fmframework/src/sarsoo/fmframework/music/Album.java +++ b/fmframework/src/sarsoo/fmframework/music/Album.java @@ -9,56 +9,61 @@ import sarsoo.fmframework.net.Network; import sarsoo.fmframework.parser.Parser; import sarsoo.fmframework.util.Reference; -public class Album extends FMObj{ +public class Album extends FMObj { protected Artist artist; protected ArrayList tagList; -// protected ArrayList trackList; - + // protected ArrayList trackList; + public Album(String name, String artist) { super(name, null, null, 0, 0, 0, null); this.artist = Artist.getArtist(artist, Reference.getUserName()); } - - public Album(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount, Wiki wiki) { + + public Album(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount, + Wiki wiki) { super(name, url, mbid, listeners, playCount, userPlayCount, wiki); this.artist = artist; } - + public Artist getArtist() { return artist; } - + public static Album getAlbum(String name, String artist, String username) { String url = Network.getAlbumInfoUrl(name, artist, username); Document response = Network.getResponse(url); - Album album = Parser.parseAlbum(response); - return album; + if (response != null) { + Album album = Parser.parseAlbum(response); + return album; + } + return null; } - -// public Track getTrack(int track) { -// return trackList.get(track); -// } -// -// public ArrayList getTrackList(){ -// return trackList; -// } -// -// public void addTrack(Track track) { -// trackList.add(track); -// } -// - public ArrayList getTags(){ + + // public Track getTrack(int track) { + // return trackList.get(track); + // } + // + // public ArrayList getTrackList(){ + // return trackList; + // } + // + // public void addTrack(Track track) { + // trackList.add(track); + // } + // + public ArrayList getTags() { return tagList; } - + public String getRymURL() { - return "https://rateyourmusic.com/release/album/" + getArtist().getName().replaceAll(" ", "_").toLowerCase() + "/" + getName().replaceAll(" ", "_").toLowerCase(); + return "https://rateyourmusic.com/release/album/" + getArtist().getName().replaceAll(" ", "_").toLowerCase() + + "/" + getName().replaceAll(" ", "_").toLowerCase(); } - + @Override public String getMusicBrainzURL() { - return "https://musicbrainz.org/release/" + mbid; - + return "https://musicbrainz.org/release/" + mbid; + } @Override @@ -69,18 +74,19 @@ public class Album extends FMObj{ @Override public boolean equals(Object obj) { - if(obj.getClass() != this.getClass()) return false; - - Album album = (Album)obj; - if(getName() == album.getName()) - if(getArtist().equals(album.getArtist())) + if (obj.getClass() != this.getClass()) + return false; + + Album album = (Album) obj; + if (getName() == album.getName()) + if (getArtist().equals(album.getArtist())) return true; - + return false; } public String toString() { return name + " - " + artist.getName(); - + } } diff --git a/fmframework/src/sarsoo/fmframework/music/Artist.java b/fmframework/src/sarsoo/fmframework/music/Artist.java index 2ad963d..2192583 100644 --- a/fmframework/src/sarsoo/fmframework/music/Artist.java +++ b/fmframework/src/sarsoo/fmframework/music/Artist.java @@ -8,71 +8,74 @@ import sarsoo.fmframework.net.Network; //import sarsoo.fmframework.net.TestCall; import sarsoo.fmframework.parser.Parser; -public class Artist extends FMObj{ -// protected boolean streamable; -// protected boolean onTour; +public class Artist extends FMObj { + // protected boolean streamable; + // protected boolean onTour; protected ArrayList albums; protected ArrayList similarArtists; protected ArrayList tagList; - + public Artist(String name) { super(name, null, null, 0, 0, 0, null); } - + public Artist(String name, String url, String mbid, int listeners, int playCount, int userPlayCount, Wiki wiki) { super(name, url, mbid, listeners, playCount, userPlayCount, wiki); } - + public static Artist getArtist(String name, String username) { String url = Network.getArtistInfoUrl(name, username); -// TestCall.test(url); + // TestCall.test(url); Document response = Network.getResponse(url); - Artist artist = Parser.parseArtist(response); - return artist; + if (response != null) { + Artist artist = Parser.parseArtist(response); + return artist; + } + return null; } - + public static Artist getArtistByMbid(String mbid, String username) { String url = Network.getArtistInfoMbidUrl(mbid, username); Document response = Network.getResponse(url); Artist artist = Parser.parseArtist(response); return artist; } - - public ArrayList getAlbum(){ + + public ArrayList getAlbum() { return albums; } - - public ArrayList getSimilarArtists(){ + + public ArrayList getSimilarArtists() { return similarArtists; } - - public ArrayList getTags(){ + + public ArrayList getTags() { return tagList; } - + @Override public String getMusicBrainzURL() { - return "https://musicbrainz.org/artist/" + mbid; + return "https://musicbrainz.org/artist/" + mbid; } - + public String getRymURL() { return "https://rateyourmusic.com/artist/" + getName().replaceAll(" ", "_").toLowerCase(); } @Override public boolean equals(Object obj) { - if(obj.getClass() != this.getClass()) return false; - - Artist artist = (Artist)obj; - if(getName() == artist.getName()) - return true; - + if (obj.getClass() != this.getClass()) + return false; + + Artist artist = (Artist) obj; + if (getName() == artist.getName()) + return true; + return false; } public String toString() { return name; } - - + } diff --git a/fmframework/src/sarsoo/fmframework/music/FMObj.java b/fmframework/src/sarsoo/fmframework/music/FMObj.java index 146471f..be12c3a 100644 --- a/fmframework/src/sarsoo/fmframework/music/FMObj.java +++ b/fmframework/src/sarsoo/fmframework/music/FMObj.java @@ -2,7 +2,7 @@ package sarsoo.fmframework.music; import sarsoo.fmframework.gui.FMObjView; -public abstract class FMObj { +public abstract class FMObj implements Comparable{ protected String name; protected String url; @@ -33,6 +33,12 @@ public abstract class FMObj { return name; } + @Override + public int compareTo(FMObj obj) { + + return userPlayCount - obj.getUserPlayCount(); + } + public String getName() { return name; } diff --git a/fmframework/src/sarsoo/fmframework/music/Track.java b/fmframework/src/sarsoo/fmframework/music/Track.java index 8566c35..315b3ea 100644 --- a/fmframework/src/sarsoo/fmframework/music/Track.java +++ b/fmframework/src/sarsoo/fmframework/music/Track.java @@ -9,7 +9,7 @@ import sarsoo.fmframework.net.Network; //import sarsoo.fmframework.net.TestCall; import sarsoo.fmframework.parser.Parser; -public class Track extends FMObj{ +public class Track extends FMObj { protected Album album; protected Artist artist; protected int trackNumber; @@ -17,59 +17,64 @@ public class Track extends FMObj{ protected boolean streamable; protected boolean isLoved; protected ArrayList tagList; - + public Track(String name, String artist) { super(name, null, null, 0, 0, 0, null); this.artist = new Artist(artist); } - - public Track(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount, Wiki wiki) { + + public Track(String name, String url, String mbid, Artist artist, int listeners, int playCount, int userPlayCount, + Wiki wiki) { super(name, url, mbid, listeners, playCount, userPlayCount, wiki); this.artist = artist; } - + public static Track getTrack(String name, String artist, String username) { String url = Network.getTrackInfoUrl(name, artist, username); -// TestCall.test(url); + // TestCall.test(url); Document response = Network.getResponse(url); - Track track = Parser.parseTrack(response); - return track; + if (response != null) { + Track track = Parser.parseTrack(response); + return track; + } + return null; } - + public Artist getArtist() { return artist; } - - public ArrayList getTags(){ + + public ArrayList getTags() { return tagList; } - + public void setAlbum(Album album) { this.album = album; } - + @Override public String getMusicBrainzURL() { - return "https://musicbrainz.org/artist/" + mbid; + return "https://musicbrainz.org/artist/" + mbid; } - + public String getLyricsURL() { return Network.getLyricsUrl(name, artist.getName()); } - + public Album getAlbum() { return album; } @Override public boolean equals(Object obj) { - if(obj.getClass() != this.getClass()) return false; - - Track track = (Track)obj; - if(getName() == track.getName()) - if(getArtist().equals(track.getArtist())) + if (obj.getClass() != this.getClass()) + return false; + + Track track = (Track) obj; + if (getName() == track.getName()) + if (getArtist().equals(track.getArtist())) return true; - + return false; } @@ -78,9 +83,9 @@ public class Track extends FMObj{ TrackView view = new TrackView(this); view.setVisible(true); } - + public String toString() { return name + " - " + artist.getName(); - + } }