From fb1982d2dc92e417d16ab692e4965657e49df869 Mon Sep 17 00:00:00 2001 From: "stephen@sfnelson.org" Date: Thu, 14 May 2009 22:00:50 +0000 Subject: [PATCH] Added an optional default value to Track.get(..) to remove necessity for null pointer checks in some situations. git-svn-id: https://stereo.googlecode.com/svn/trunk@471 c67ee986-0855-0410-825f-15918b819f62 --- DACPServer/src/util/command/ctrlint/PlayStatusUpdate.java | 10 +++++----- MemphisDJ/src/interfaces/AbstractTrack.java | 10 ++++++++++ MemphisDJ/src/interfaces/Track.java | 1 + MemphisDJ/src/music/CollectionTrack.java | 10 ++++++++++ MemphisDJ/src/music/LibraryTrack.java | 10 ++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/DACPServer/src/util/command/ctrlint/PlayStatusUpdate.java b/DACPServer/src/util/command/ctrlint/PlayStatusUpdate.java index ac63deb..aff89c0 100644 --- a/DACPServer/src/util/command/ctrlint/PlayStatusUpdate.java +++ b/DACPServer/src/util/command/ctrlint/PlayStatusUpdate.java @@ -74,11 +74,11 @@ public class PlayStatusUpdate implements Command, PlaybackListener { update = new util.response.ctrlint.PlayStatusUpdate.Active( revision, state, false, 0, database, playlist.id(), position, current.id(), - (String)current.get(Constants.dmap_itemname), - (String)current.get(Constants.daap_songartist), - (String)current.get(Constants.daap_songalbum), - (String)current.get(Constants.daap_songgenre), - (Long)current.get(Constants.daap_songalbumid), + (String)current.get(Constants.dmap_itemname, ""), + (String)current.get(Constants.daap_songartist, ""), + (String)current.get(Constants.daap_songalbum, ""), + (String)current.get(Constants.daap_songgenre, ""), + (Long)current.get(Constants.daap_songalbumid, new Long(0)), 1 /* only support songs atm */, total-elapsed, total); diff --git a/MemphisDJ/src/interfaces/AbstractTrack.java b/MemphisDJ/src/interfaces/AbstractTrack.java index 539925b..e752756 100644 --- a/MemphisDJ/src/interfaces/AbstractTrack.java +++ b/MemphisDJ/src/interfaces/AbstractTrack.java @@ -49,6 +49,16 @@ public abstract class AbstractTrack implements Track { return tags.get(tag); } + public Object get(Constants tag, Object defaultValue) { + Object ret = get(tag); + if (ret == null) { + return defaultValue; + } + else { + return ret; + } + } + public void put(Constants tag, Object value) { tags.put(tag, value); } diff --git a/MemphisDJ/src/interfaces/Track.java b/MemphisDJ/src/interfaces/Track.java index 3c067a4..3bfb6c5 100644 --- a/MemphisDJ/src/interfaces/Track.java +++ b/MemphisDJ/src/interfaces/Track.java @@ -12,6 +12,7 @@ public interface Track extends HasMetadata { public Album getAlbum(); public void setAlbum(Album album); public Object get(Constants tag); + public Object get(Constants tag, Object defaultValue); public void put(Constants tag, Object value); public Iterable getAllTags(); public void getStream(StreamReader reader) throws IOException; diff --git a/MemphisDJ/src/music/CollectionTrack.java b/MemphisDJ/src/music/CollectionTrack.java index 0d47f1f..c2083af 100644 --- a/MemphisDJ/src/music/CollectionTrack.java +++ b/MemphisDJ/src/music/CollectionTrack.java @@ -41,6 +41,16 @@ public class CollectionTrack implements Track { return track.get(tag); } } + + public Object get(Constants tag, Object defaultValue) { + Object ret = get(tag); + if (ret == null) { + return defaultValue; + } + else { + return ret; + } + } public Album getAlbum() { return track.getAlbum(); diff --git a/MemphisDJ/src/music/LibraryTrack.java b/MemphisDJ/src/music/LibraryTrack.java index 41fc9d0..907af0b 100644 --- a/MemphisDJ/src/music/LibraryTrack.java +++ b/MemphisDJ/src/music/LibraryTrack.java @@ -58,6 +58,16 @@ public class LibraryTrack implements Track { if (current == null) return null; return current.get(tag); } + + public Object get(Constants tag, Object defaultValue) { + Object ret = get(tag); + if (ret == null) { + return defaultValue; + } + else { + return ret; + } + } public Iterable getAllTags() { Track current = current(); -- 2.11.4.GIT