/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package moe.nekojimi.musicsearcher; import java.net.URL; /** * * @author jim */ public class Result implements Comparable { private URL link; private String artist; private String album; private String title; private String sourceName; private String sourceAbbr; private double score; public URL getLink() { return link; } public void setLink(URL link) { this.link = link; } public String getArtist() { return artist; } public void setArtist(String artist) { this.artist = artist; } public String getAlbum() { return album; } public void setAlbum(String album) { this.album = album; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getSourceName() { return sourceName; } public void setSource(String name, String abbr) { sourceName = name; sourceAbbr = abbr; } public String getSourceAbbr() { return sourceAbbr; } public double getScore() { return score; } public void setScore(double score) { this.score = score; } @Override public String toString() { return "Result{" + "artist=" + artist + ", album=" + album + ", title=" + title + ", sourceAbbr=" + sourceAbbr + ", score=" + score + '}'; } public void setAlbumArtist(String field) { // System.out.println("Parsing album-artist: " + field); String fieldLower = field.toLowerCase(); if (fieldLower.contains("from") || field.toLowerCase().contains("by")) { artist = ""; album = ""; String[] words = field.split("\\s+"); boolean readingArtist = false; for (String word: words) { if (word.equals("from")) readingArtist = false; else if (word.equals("by")) readingArtist = true; else { if (readingArtist) artist += word + " "; else album += word + " "; } } artist = artist.trim(); album = album.trim(); } } @Override public int compareTo(Result t) { return (int) Math.signum(score - t.score); } }