1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.types;
17
18 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
20
21
22
23
24
25
26
27
28
29
30 public class DLNADoc {
31
32 public static final Pattern PATTERN = Pattern.compile("(.+?)[ -]([0-9].[0-9]{2})");
33
34 public enum Version {
35 V1_0("1.00"),
36 V1_5("1.50");
37
38 String s;
39
40 Version(String s) {
41 this.s = s;
42 }
43
44
45 @Override
46 public String toString() {
47 return s;
48 }
49 }
50
51 final private String devClass;
52 final private String version;
53
54 public DLNADoc(String devClass, String version) {
55 this.devClass = devClass;
56 this.version = version;
57 }
58
59 public DLNADoc(String devClass, Version version) {
60 this.devClass = devClass;
61 this.version = version.s;
62 }
63
64 public String getDevClass() {
65 return devClass;
66 }
67
68 public String getVersion() {
69 return version;
70 }
71
72 public static DLNADoc valueOf(String s) throws InvalidValueException {
73 Matcher matcher = PATTERN.matcher(s);
74 if (matcher.matches()) {
75 return new DLNADoc(matcher.group(1), matcher.group(2));
76 } else {
77 throw new InvalidValueException("Can't parse DLNADoc: " + s);
78 }
79 }
80
81 @Override
82 public boolean equals(Object o) {
83 if (this == o) return true;
84 if (o == null || getClass() != o.getClass()) return false;
85
86 DLNADoc dlnaDoc = (DLNADoc) o;
87
88 if (!devClass.equals(dlnaDoc.devClass)) return false;
89 if (!version.equals(dlnaDoc.version)) return false;
90
91 return true;
92 }
93
94 @Override
95 public int hashCode() {
96 int result = devClass.hashCode();
97 result = 31 * result + version.hashCode();
98 return result;
99 }
100
101 @Override
102 public String toString() {
103 return getDevClass() + "-" + getVersion();
104 }
105 }