1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.http.pathmap;
20
21 import org.eclipse.jetty.util.annotation.ManagedAttribute;
22 import org.eclipse.jetty.util.annotation.ManagedObject;
23
24 @ManagedObject("Mapped Resource")
25 public class MappedResource<E> implements Comparable<MappedResource<E>>
26 {
27 private final PathSpec pathSpec;
28 private final E resource;
29
30 public MappedResource(PathSpec pathSpec, E resource)
31 {
32 this.pathSpec = pathSpec;
33 this.resource = resource;
34 }
35
36
37
38
39 @Override
40 public int compareTo(MappedResource<E> other)
41 {
42 return this.pathSpec.compareTo(other.pathSpec);
43 }
44
45 @Override
46 public boolean equals(Object obj)
47 {
48 if (this == obj)
49 {
50 return true;
51 }
52 if (obj == null)
53 {
54 return false;
55 }
56 if (getClass() != obj.getClass())
57 {
58 return false;
59 }
60 MappedResource<?> other = (MappedResource<?>)obj;
61 if (pathSpec == null)
62 {
63 if (other.pathSpec != null)
64 {
65 return false;
66 }
67 }
68 else if (!pathSpec.equals(other.pathSpec))
69 {
70 return false;
71 }
72 return true;
73 }
74
75 @ManagedAttribute(value = "path spec", readonly = true)
76 public PathSpec getPathSpec()
77 {
78 return pathSpec;
79 }
80
81 @ManagedAttribute(value = "resource", readonly = true)
82 public E getResource()
83 {
84 return resource;
85 }
86
87 @Override
88 public int hashCode()
89 {
90 final int prime = 31;
91 int result = 1;
92 result = (prime * result) + ((pathSpec == null) ? 0 : pathSpec.hashCode());
93 return result;
94 }
95
96 @Override
97 public String toString()
98 {
99 return String.format("MappedResource[pathSpec=%s,resource=%s]",pathSpec,resource);
100 }
101 }