fmobj comparable, objects in objlist get sorted

This commit is contained in:
aj 2018-04-05 00:10:58 -07:00
parent e90f12f6dd
commit 4c18bd07a2
6 changed files with 116 additions and 92 deletions

View File

@ -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);
}
// }
}
}

View File

@ -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);

View File

@ -19,7 +19,8 @@ public class Album extends FMObj{
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;
}
@ -31,9 +32,12 @@ public class Album extends FMObj{
public static Album getAlbum(String name, String artist, String username) {
String url = Network.getAlbumInfoUrl(name, artist, username);
Document response = Network.getResponse(url);
if (response != null) {
Album album = Parser.parseAlbum(response);
return album;
}
return null;
}
// public Track getTrack(int track) {
// return trackList.get(track);
@ -52,7 +56,8 @@ public class Album extends FMObj{
}
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
@ -69,7 +74,8 @@ public class Album extends FMObj{
@Override
public boolean equals(Object obj) {
if(obj.getClass() != this.getClass()) return false;
if (obj.getClass() != this.getClass())
return false;
Album album = (Album) obj;
if (getName() == album.getName())

View File

@ -27,9 +27,12 @@ public class Artist extends FMObj{
String url = Network.getArtistInfoUrl(name, username);
// TestCall.test(url);
Document response = Network.getResponse(url);
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);
@ -61,7 +64,8 @@ public class Artist extends FMObj{
@Override
public boolean equals(Object obj) {
if(obj.getClass() != this.getClass()) return false;
if (obj.getClass() != this.getClass())
return false;
Artist artist = (Artist) obj;
if (getName() == artist.getName())
@ -74,5 +78,4 @@ public class Artist extends FMObj{
return name;
}
}

View File

@ -2,7 +2,7 @@ package sarsoo.fmframework.music;
import sarsoo.fmframework.gui.FMObjView;
public abstract class FMObj {
public abstract class FMObj implements Comparable<FMObj>{
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;
}

View File

@ -23,7 +23,8 @@ public class Track extends FMObj{
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;
}
@ -32,9 +33,12 @@ public class Track extends FMObj{
String url = Network.getTrackInfoUrl(name, artist, username);
// TestCall.test(url);
Document response = Network.getResponse(url);
if (response != null) {
Track track = Parser.parseTrack(response);
return track;
}
return null;
}
public Artist getArtist() {
return artist;
@ -63,7 +67,8 @@ public class Track extends FMObj{
@Override
public boolean equals(Object obj) {
if(obj.getClass() != this.getClass()) return false;
if (obj.getClass() != this.getClass())
return false;
Track track = (Track) obj;
if (getName() == track.getName())