]> WPIA git - gigi.git/blob - lib/jetty/org/eclipse/jetty/http/pathmap/MappedResource.java
Merge "Update notes about password security"
[gigi.git] / lib / jetty / org / eclipse / jetty / http / pathmap / MappedResource.java
1 //
2 //  ========================================================================
3 //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 //  ------------------------------------------------------------------------
5 //  All rights reserved. This program and the accompanying materials
6 //  are made available under the terms of the Eclipse Public License v1.0
7 //  and Apache License v2.0 which accompanies this distribution.
8 //
9 //      The Eclipse Public License is available at
10 //      http://www.eclipse.org/legal/epl-v10.html
11 //
12 //      The Apache License v2.0 is available at
13 //      http://www.opensource.org/licenses/apache2.0.php
14 //
15 //  You may elect to redistribute this code under either of these licenses.
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      * Comparison is based solely on the pathSpec
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 }