Skip to content

Commit b3b4182

Browse files
committed
Merge branch 'release/1_07_2_final'
2 parents f320932 + ba27d2a commit b3b4182

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+720
-822
lines changed

JMPDComm/src/main/java/org/a0z/mpd/CommandQueue.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
import java.io.IOException;
3434
import java.util.ArrayList;
3535
import java.util.Collections;
36+
import java.util.Iterator;
3637
import java.util.List;
3738

3839
/** A class to generate and send a command queue. */
39-
final class CommandQueue {
40+
public class CommandQueue implements Iterable<MPDCommand> {
4041

4142
private static final boolean DEBUG = false;
4243

@@ -54,14 +55,14 @@ final class CommandQueue {
5455

5556
private int mCommandQueueStringLength;
5657

57-
CommandQueue() {
58+
public CommandQueue() {
5859
super();
5960

6061
mCommandQueue = new ArrayList<>();
6162
mCommandQueueStringLength = getStartLength();
6263
}
6364

64-
CommandQueue(final int size) {
65+
public CommandQueue(final int size) {
6566
super();
6667

6768
mCommandQueue = new ArrayList<>(size);
@@ -103,7 +104,7 @@ private static List<String[]> separatedQueueResults(final Iterable<String> lines
103104
*
104105
* @param commandQueue The command queue to add to this one.
105106
*/
106-
void add(final CommandQueue commandQueue) {
107+
public void add(final CommandQueue commandQueue) {
107108
mCommandQueue.addAll(commandQueue.mCommandQueue);
108109
mCommandQueueStringLength += commandQueue.mCommandQueueStringLength;
109110
}
@@ -114,7 +115,7 @@ void add(final CommandQueue commandQueue) {
114115
* @param position The position of this command queue to add the new command queue.
115116
* @param commandQueue The command queue to add to this one.
116117
*/
117-
void add(final int position, final CommandQueue commandQueue) {
118+
public void add(final int position, final CommandQueue commandQueue) {
118119
mCommandQueue.addAll(position, commandQueue.mCommandQueue);
119120
mCommandQueueStringLength += commandQueue.mCommandQueueStringLength;
120121
}
@@ -125,7 +126,7 @@ void add(final int position, final CommandQueue commandQueue) {
125126
* @param position The position of this command queue to add the new command.
126127
* @param command The command to add to this command queue.
127128
*/
128-
void add(final int position, final MPDCommand command) {
129+
public void add(final int position, final MPDCommand command) {
129130
mCommandQueue.add(position, command);
130131
mCommandQueueStringLength += command.toString().length();
131132
}
@@ -135,7 +136,7 @@ void add(final int position, final MPDCommand command) {
135136
*
136137
* @param command Command to add to the queue.
137138
*/
138-
void add(final MPDCommand command) {
139+
public void add(final MPDCommand command) {
139140
mCommandQueue.add(command);
140141
mCommandQueueStringLength += command.toString().length();
141142
}
@@ -145,12 +146,12 @@ void add(final MPDCommand command) {
145146
*
146147
* @param command Command to add to the queue.
147148
*/
148-
void add(final String command, final String... args) {
149+
public void add(final String command, final String... args) {
149150
add(new MPDCommand(command, args));
150151
}
151152

152153
/** Clear the command queue. */
153-
void clear() {
154+
public void clear() {
154155
mCommandQueueStringLength = getStartLength();
155156
mCommandQueue.clear();
156157
}
@@ -159,8 +160,18 @@ public boolean isEmpty() {
159160
return mCommandQueue.isEmpty();
160161
}
161162

163+
/**
164+
* Returns an {@link java.util.Iterator} for the elements in this object.
165+
*
166+
* @return An {@code Iterator} instance.
167+
*/
168+
@Override
169+
public Iterator<MPDCommand> iterator() {
170+
return mCommandQueue.iterator();
171+
}
172+
162173
/** Reverse the command queue order, useful for removing playlist entries. */
163-
void reverse() {
174+
public void reverse() {
164175
Collections.reverse(mCommandQueue);
165176
}
166177

@@ -172,7 +183,7 @@ void reverse() {
172183
* @throws IOException Thrown upon a communication error with the server.
173184
* @throws MPDException Thrown if an error occurs as a result of command execution.
174185
*/
175-
List<String> send(final MPDConnection mpdConnection) throws IOException, MPDException {
186+
public List<String> send(final MPDConnection mpdConnection) throws IOException, MPDException {
176187
return send(mpdConnection, false);
177188
}
178189

JMPDComm/src/main/java/org/a0z/mpd/MPD.java

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.a0z.mpd.item.Music;
4141
import org.a0z.mpd.item.PlaylistFile;
4242
import org.a0z.mpd.item.Stream;
43+
import org.a0z.mpd.subsystem.Sticker;
4344

4445
import java.io.IOException;
4546
import java.net.InetAddress;
@@ -1216,71 +1217,32 @@ public List<String[]> listAlbumArtists(final List<Album> albums)
12161217
* @throws MPDException Thrown if an error occurs as a result of command execution.
12171218
*/
12181219
public List<String> listAlbums() throws IOException, MPDException {
1219-
return listAlbums(null, false, true);
1220+
return listAlbums(null, false);
12201221
}
12211222

12221223
/**
1223-
* List all albums from database.
1224-
*
1225-
* @param useAlbumArtist use AlbumArtist instead of Artist
1226-
* @return {@code Collection} with all album names from database.
1227-
* @throws IOException Thrown upon a communication error with the server.
1228-
* @throws MPDException Thrown if an error occurs as a result of command execution.
1229-
*/
1230-
public List<String> listAlbums(final boolean useAlbumArtist) throws IOException, MPDException {
1231-
return listAlbums(null, useAlbumArtist, true);
1232-
}
1233-
1234-
/**
1235-
* List all albums from a given artist, including an entry for songs with no
1236-
* album tag.
1224+
* List all albums from a given artist.
12371225
*
12381226
* @param artist artist to list albums
12391227
* @param useAlbumArtist use AlbumArtist instead of Artist
1240-
* @return {@code Collection} with all album names from database.
1241-
* @throws IOException Thrown upon a communication error with the server.
1242-
* @throws MPDException Thrown if an error occurs as a result of command execution.
1243-
*/
1244-
public List<String> listAlbums(final String artist, final boolean useAlbumArtist)
1245-
throws IOException, MPDException {
1246-
return listAlbums(artist, useAlbumArtist, true);
1247-
}
1248-
1249-
/**
1250-
* List all albums from a given artist.
1251-
*
1252-
* @param artist artist to list albums
1253-
* @param useAlbumArtist use AlbumArtist instead of Artist
1254-
* @param includeUnknownAlbum include an entry for songs with no album tag
12551228
* @return {@code Collection} with all album names from the given
12561229
* artist present in database.
12571230
* @throws IOException Thrown upon a communication error with the server.
12581231
* @throws MPDException Thrown if an error occurs as a result of command execution.
12591232
*/
1260-
public List<String> listAlbums(final String artist, final boolean useAlbumArtist,
1261-
final boolean includeUnknownAlbum) throws IOException, MPDException {
1262-
boolean foundSongWithoutAlbum = false;
1263-
1233+
public List<String> listAlbums(final String artist, final boolean useAlbumArtist)
1234+
throws IOException, MPDException {
12641235
final List<String> response =
1265-
mConnection.sendCommand
1266-
(listAlbumsCommand(artist, useAlbumArtist));
1236+
mConnection.sendCommand(listAlbumsCommand(artist, useAlbumArtist));
1237+
final List<String> result;
12671238

1268-
final List<String> result = new ArrayList<>(response.size());
1269-
for (final String line : response) {
1270-
final String name = line.substring("Album: ".length());
1271-
if (name.isEmpty()) {
1272-
foundSongWithoutAlbum = true;
1273-
} else {
1274-
result.add(name);
1275-
}
1276-
}
1277-
1278-
// add a single blank entry to host all songs without an album set
1279-
if (includeUnknownAlbum && foundSongWithoutAlbum) {
1280-
result.add("");
1239+
if (response.isEmpty()) {
1240+
result = Collections.emptyList();
1241+
} else {
1242+
result = Tools.parseResponse(response, "Album");
1243+
Collections.sort(result);
12811244
}
12821245

1283-
Collections.sort(result);
12841246
return result;
12851247
}
12861248

JMPDComm/src/main/java/org/a0z/mpd/MPDCommand.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public class MPDCommand {
4646

4747
public static final String MPD_CMD_CLOSE = "close";
4848

49-
public static final String MPD_CMD_COMMANDS = "commands";
50-
5149
public static final String MPD_CMD_CONSUME = "consume";
5250

5351
public static final String MPD_CMD_COUNT = "count";
@@ -89,8 +87,6 @@ public class MPDCommand {
8987

9088
public static final String MPD_CMD_PAUSE = "pause";
9189

92-
public static final String MPD_CMD_PERMISSION = "permission";
93-
9490
public static final String MPD_CMD_PING = "ping";
9591

9692
public static final String MPD_CMD_PLAY = "play";

JMPDComm/src/main/java/org/a0z/mpd/MusicList.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ private void add(final Music music) {
9797
mSongID.add(null);
9898
}
9999

100+
if (songPos == -1) {
101+
throw new IllegalStateException("Media server protocol error: songPos not " +
102+
"included with the playlist changes included with the following " +
103+
"music. Path:" + music.getFullPath() + " Name: " + music.getName());
104+
}
105+
100106
mList.set(songPos, music);
101107
mSongID.set(songPos, music.getSongId());
102108
}

JMPDComm/src/main/java/org/a0z/mpd/Tools.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
package org.a0z.mpd;
2929

30+
import org.a0z.mpd.exception.InvalidResponseException;
31+
3032
import java.security.MessageDigest;
3133
import java.util.ArrayList;
3234
import java.util.Collection;
@@ -253,6 +255,11 @@ public static String[] splitResponse(final String line) {
253255
final int delimiterIndex = line.indexOf(':');
254256
final String[] result = new String[2];
255257

258+
if (delimiterIndex == -1) {
259+
throw new InvalidResponseException("Failed to parse server response key for line: " +
260+
line);
261+
}
262+
256263
result[0] = line.substring(0, delimiterIndex);
257264

258265
/** Skip ': ' */

JMPDComm/src/main/java/org/a0z/mpd/connection/MPDConnection.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.a0z.mpd.MPDStatusMonitor;
3333
import org.a0z.mpd.Tools;
3434
import org.a0z.mpd.exception.MPDException;
35+
import org.a0z.mpd.subsystem.Reflection;
3536

3637
import java.io.BufferedReader;
3738
import java.io.EOFException;
@@ -52,8 +53,6 @@
5253
import java.util.concurrent.ThreadPoolExecutor;
5354
import java.util.concurrent.TimeUnit;
5455

55-
import static org.a0z.mpd.Tools.VALUE;
56-
5756
/**
5857
* Class representing a connection to MPD Server.
5958
*/
@@ -127,23 +126,6 @@ public abstract class MPDConnection {
127126
}
128127
}
129128

130-
/**
131-
* Puts all available commands into a set backed collection.
132-
*
133-
* @param response The media server response to the {@link MPDCommand#MPD_CMD_COMMANDS}
134-
* command.
135-
* @return A collection of available commands from the response.
136-
*/
137-
private static Collection<String> getCommands(final Collection<String> response) {
138-
final Collection<String> commands = new HashSet<>(response.size());
139-
140-
for (final String[] pair : Tools.splitResponse(response)) {
141-
commands.add(pair[VALUE]);
142-
}
143-
144-
return commands;
145-
}
146-
147129
/**
148130
* Sets up connection to host/port pair with MPD password.
149131
*
@@ -162,12 +144,14 @@ public final void connect(final InetAddress host, final int port, final String p
162144
mPassword = password;
163145
mSocketAddress = new InetSocketAddress(host, port);
164146

165-
final MPDCommand mpdCommand = new MPDCommand(MPDCommand.MPD_CMD_COMMANDS);
147+
final MPDCommand mpdCommand = new MPDCommand(Reflection.CMD_ACTION_COMMANDS);
166148
final CommandResult commandResult = processCommand(mpdCommand);
167149

168150
synchronized (mAvailableCommands) {
151+
final Collection<String> response = Tools.
152+
parseResponse(commandResult.getResult(), Reflection.CMD_RESPONSE_COMMANDS);
169153
mAvailableCommands.clear();
170-
mAvailableCommands.addAll(getCommands(commandResult.getResult()));
154+
mAvailableCommands.addAll(response);
171155
}
172156

173157
if (!commandResult.isHeaderValid()) {

0 commit comments

Comments
 (0)