1 package util
.command
.databases
;
3 import interfaces
.Album
;
4 import interfaces
.Constants
;
5 import interfaces
.DJInterface
;
7 import java
.util
.ArrayList
;
8 import java
.util
.Collections
;
9 import java
.util
.Comparator
;
10 import java
.util
.List
;
13 import util
.command
.Command
;
14 import util
.queryparser
.ApplyFilter
;
15 import util
.queryparser
.Filter
;
16 import util
.queryparser
.QueryParser
;
18 import api
.nodes
.AlbumNode
;
20 public class Groups
implements Command
{
22 private Map
<String
, String
> args
;
24 public void init(Map
<String
, String
> args
) {
28 public Response
run(DJInterface dj
) {
30 Iterable
<?
extends Album
> albums
= dj
.library().albums();
33 throw new IllegalArgumentException("no arguments to group query");
36 //don't query, as albums store name as minm not asal
38 List
<?
extends Album
> als
;
39 if (args
.containsKey("query")) {
40 String query
= args
.get("query").replace(' ', '_');
41 Filter q
= QueryParser
.parse(query
);
42 System
.out
.println(q
);
43 als
= ApplyFilter
.filter(q
, albums
);
46 List
<Album
> as
= new ArrayList
<Album
>();
47 for (Album a
: albums
) {
58 include-sort-headers=1
59 query=(('com.apple.itunes.mediakind:1','com.apple.itunes.mediakind:32')+'daap.songalbum!:'
62 if (!args
.containsKey("group-type") || !args
.get("group-type").equals("albums")) {
63 throw new IllegalArgumentException("trying to handle unknown group-type: " + args
.get("group-type"));
66 Collections
.sort(als
, new Comparator
<Album
>() {
67 public int compare(Album a
, Album b
) {
68 int c
= a
.name().compareTo(b
.name());
70 return a
.artist().compareTo(b
.artist());
76 List
<AlbumNode
> nodes
= new ArrayList
<AlbumNode
>();
78 nodes
.add(new AlbumNode(a
));
81 System
.out
.println("returning " + nodes
.size() + " elements");
83 return new util
.response
.databases
.Groups
<AlbumNode
>(Constants
.daap_albumgrouping
, nodes
);