01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.protocol.http.parser;
20:
21: import java.net.URL;
22:
23: /**
24: * Helper class to allow URLs to be stored in Collections without incurring the
25: * cost of the hostname lookup performed by the URL methods equals() and
26: * hashCode() URL is a final class, so cannot be extended ...
27: *
28: * @version $Revision: 493789 $ $Date: 2007-01-07 18:10:21 +0000 (Sun, 07 Jan 2007) $
29: */
30: public class URLString implements Comparable // To allow use in Sorted
31: // Collections
32: {
33:
34: private URL url;
35:
36: private String urlAsString;
37:
38: private int hashCode;
39:
40: private URLString()// not instantiable
41: {
42: }
43:
44: public URLString(URL u) {
45: url = u;
46: urlAsString = u.toExternalForm();
47: /*
48: * TODO improve string version to better match browser behaviour? e.g.
49: * do browsers regard http://host/ and http://Host:80/ as the same? If
50: * so, it would be better to reflect this in the string
51: */
52:
53: hashCode = urlAsString.hashCode();
54: }
55:
56: /*
57: * Parsers can return the URL as a string if it does not parse properly
58: */
59: public URLString(String s) {
60: url = null;
61: urlAsString = s;
62: hashCode = urlAsString.hashCode();
63: }
64:
65: public String toString() {
66: return urlAsString;
67: }
68:
69: public URL getURL() {
70: return url;
71: }
72:
73: public int compareTo(Object o) {
74: return urlAsString.compareTo(o.toString());
75: }
76:
77: public boolean equals(Object o) {
78: return (o instanceof URLString && urlAsString.equals(o
79: .toString()));
80: }
81:
82: public int hashCode() {
83: return hashCode;
84: }
85: }
|