1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.resource;
17
18 import org.fourthline.cling.model.ExpirationDetails;
19
20 import java.net.URI;
21 import java.net.URISyntaxException;
22 import java.util.List;
23
24
25
26
27
28
29
30
31 public class Resource<M> {
32
33 private URI pathQuery;
34 private M model;
35
36
37
38
39
40 public Resource(URI pathQuery, M model) {
41 try {
42 this.pathQuery = new URI(null, null, pathQuery.getPath(), pathQuery.getQuery(), null);
43 } catch (URISyntaxException ex) {
44 throw new RuntimeException(ex);
45 }
46 this.model = model;
47 if (model == null) {
48 throw new IllegalArgumentException("Model instance must not be null");
49 }
50 }
51
52 public URI getPathQuery() {
53 return pathQuery;
54 }
55
56 public M getModel() {
57 return model;
58 }
59
60
61
62
63
64
65 public boolean matches(URI pathQuery) {
66 return pathQuery.equals(getPathQuery());
67 }
68
69
70
71
72
73
74
75
76
77
78 public void maintain(List<Runnable> pendingExecutions,
79 ExpirationDetails expirationDetails) {
80
81 }
82
83
84
85
86
87
88
89 public void shutdown() {
90
91 }
92
93 @Override
94 public boolean equals(Object o) {
95 if (this == o) return true;
96 if (o == null || getClass() != o.getClass()) return false;
97
98 Resource resource = (Resource) o;
99
100 if (!getPathQuery().equals(resource.getPathQuery())) return false;
101
102 return true;
103 }
104
105 @Override
106 public int hashCode() {
107 return getPathQuery().hashCode();
108 }
109
110 @Override
111 public String toString() {
112 return "(" + getClass().getSimpleName() + ") URI: " + getPathQuery();
113 }
114
115 }