1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.types;
17
18
19
20
21
22
23
24 public class NamedDeviceType {
25
26 private UDN udn;
27 private DeviceType deviceType;
28
29 public NamedDeviceType(UDN udn, DeviceType deviceType) {
30 this.udn = udn;
31 this.deviceType = deviceType;
32 }
33
34 public UDN getUdn() {
35 return udn;
36 }
37
38 public DeviceType getDeviceType() {
39 return deviceType;
40 }
41
42 public static NamedDeviceType valueOf(String s) throws InvalidValueException {
43 String[] strings = s.split("::");
44 if (strings.length != 2) {
45 throw new InvalidValueException("Can't parse UDN::DeviceType from: " + s);
46 }
47
48 UDN udn;
49 try {
50 udn = UDN.valueOf(strings[0]);
51 } catch (Exception ex) {
52 throw new InvalidValueException("Can't parse UDN: " + strings[0]);
53 }
54
55 DeviceType deviceType = DeviceType.valueOf(strings[1]);
56 return new NamedDeviceType(udn, deviceType);
57 }
58
59 @Override
60 public String toString() {
61 return getUdn().toString() + "::" + getDeviceType().toString();
62 }
63
64 @Override
65 public boolean equals(Object o) {
66 if (this == o) return true;
67 if (o == null || !(o instanceof NamedDeviceType)) return false;
68
69 NamedDeviceType that = (NamedDeviceType) o;
70
71 if (!deviceType.equals(that.deviceType)) return false;
72 if (!udn.equals(that.udn)) return false;
73
74 return true;
75 }
76
77 @Override
78 public int hashCode() {
79 int result = udn.hashCode();
80 result = 31 * result + deviceType.hashCode();
81 return result;
82 }
83 }