1 package util
.command
.databases
;
3 import interfaces
.DJInterface
;
4 import interfaces
.Track
;
5 import interfaces
.collection
.Collection
;
6 import interfaces
.collection
.Source
;
8 import java
.util
.ArrayList
;
12 import util
.command
.Command
;
13 import util
.queryparser
.ApplyFilter
;
14 import util
.queryparser
.Filter
;
15 import util
.queryparser
.QueryParser
;
18 public class Items
implements Command
{
20 private Map
<String
,String
> args
;
21 private int container
;
23 public Items(int container
) {
24 this.container
= container
;
27 public void init(Map
<String
, String
> args
) {
31 public Response
run(DJInterface dj
) {
33 Source
<?
extends Track
> source
= null;
35 for (Collection
<?
extends Track
> p
: dj
.library().collections()) {
36 if (p
.id() == container
) {
43 System
.err
.println("requested playlist not found!");
47 System
.out
.println("playlist has " + source
.size() + " elements");
49 List
<?
extends Track
> pl
;
51 if (args
!= null && args
.containsKey("query")) {
52 Filter f
= QueryParser
.parse(args
.get("query"));
53 System
.out
.println(f
);
54 pl
= ApplyFilter
.filter(f
, source
.tracks());
57 List
<Track
> l
= new ArrayList
<Track
>();
58 for (Track t
: source
.tracks()) {
64 /*Collections.sort(playlist, new Comparator<Track>() {
65 public int compare(Track o1, Track o2) {
66 String a = (String)o1.getTag(DAAPConstants.NAME);
67 String b = (String)o2.getTag(DAAPConstants.NAME);
68 if (a == null) a = "";
69 if (b == null) b = "";
70 return a.compareTo(b);
74 System
.out
.println("returning " + source
.size() + " elements");
76 return new util
.response
.PlaylistSongs(pl
);