1 package util
.queryparser
;
3 import interfaces
.Element
;
5 import java
.math
.BigInteger
;
7 import daap
.DAAPConstants
;
9 public class Token
implements Filter
{
11 public final boolean falseify
;
12 public final String property
;
13 public final String value
;
15 public Token(String t
) {
16 System
.out
.println("token: " + t
);
19 int i
= t
.indexOf(':');
22 value
= t
.substring(i
+1);
29 if (p
.charAt(p
.length()-1) == '!') {
31 property
= p
.substring(0, p
.length()-1);
39 public boolean check(Element t
) {
41 Integer code
= DAAPConstants
.shortCodes
.get(property
);
46 Object pval
= t
.getTag(code
);
48 int ae00
= 0x61650000;
49 if ((0xFFFF0000 & code
) == ae00
) {
50 //TODO we ignore apple codes because mt-daapd doesn't implement them
54 switch (DAAPConstants
.types
.get(code
)) {
55 case 1: tval
= Byte
.parseByte(value
); break;
56 case 5: tval
= Integer
.parseInt(value
); break;
57 //using big integer ensures unsigned longs are parsed correctly
58 case 7: tval
= new BigInteger(value
).longValue(); break;
59 case 9: tval
= value
; break; //string
61 throw new IllegalArgumentException("unknown or unimplemented type: "
62 + DAAPConstants
.types
.get(code
) + " for " + property
);
65 return (pval
!= null && tval
.equals(pval
)) ^ falseify
;
68 throw new IllegalArgumentException("unknown property: " + property
);
72 public String
toString() {
73 return "'"+property
+(falseify?
"!":"")+":"+value
+"'";