1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.meta;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.fourthline.cling.model.Constants;
22 import org.fourthline.cling.model.Validatable;
23 import org.fourthline.cling.model.ValidationError;
24 import org.fourthline.cling.model.types.UDN;
25
26
27
28
29
30
31 public class DeviceIdentity implements Validatable {
32
33 final private UDN udn;
34 final private Integer maxAgeSeconds;
35
36 public DeviceIdentity(UDN udn, DeviceIdentity template) {
37 this.udn = udn;
38 this.maxAgeSeconds = template.getMaxAgeSeconds();
39 }
40
41 public DeviceIdentity(UDN udn) {
42 this.udn = udn;
43 this.maxAgeSeconds = Constants.MIN_ADVERTISEMENT_AGE_SECONDS;
44 }
45
46 public DeviceIdentity(UDN udn, Integer maxAgeSeconds) {
47 this.udn = udn;
48 this.maxAgeSeconds = maxAgeSeconds;
49 }
50
51 public UDN getUdn() {
52 return udn;
53 }
54
55 public Integer getMaxAgeSeconds() {
56 return maxAgeSeconds;
57 }
58
59 @Override
60 public boolean equals(Object o) {
61 if (this == o) return true;
62 if (o == null || getClass() != o.getClass()) return false;
63
64 DeviceIdentity that = (DeviceIdentity) o;
65
66 if (!udn.equals(that.udn)) return false;
67
68 return true;
69 }
70
71 @Override
72 public int hashCode() {
73 return udn.hashCode();
74 }
75
76 @Override
77 public String toString() {
78 return "(" + getClass().getSimpleName() + ") UDN: " + getUdn();
79 }
80
81 @Override
82 public List<ValidationError> validate() {
83 List<ValidationError> errors = new ArrayList<>();
84
85 if (getUdn() == null) {
86 errors.add(new ValidationError(
87 getClass(),
88 "major",
89 "Device has no UDN"
90 ));
91 }
92
93 return errors;
94 }
95 }