KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > parser > URLString


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/parser/URLString.java,v 1.4 2004/03/30 18:08:09 sebb Exp $
2
/*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
22
23 /**
24  * Helper class to allow URLs to be stored in Collections without
25  * incurring the cost of the hostname lookup performed by the
26  * URL methods equals() and hashCode()
27  * URL is a final class, so cannot be extended ...
28  *
29  * @version $Revision: 1.4 $ $Date: 2004/03/30 18:08:09 $
30  */

31 public class URLString
32     implements Comparable JavaDoc // To allow use in Sorted Collections
33
{
34
35      private URL JavaDoc url;
36      private String JavaDoc urlAsString;
37      private int hashCode;
38      
39     private URLString()// not instantiable
40
{
41     }
42
43     public URLString(URL JavaDoc u)
44     {
45         url=u;
46         urlAsString=u.toExternalForm();
47         /*
48          * TODO improve string version to better match browser behaviour?
49          * e.g. do browsers regard http://host/ and http://Host:80/ as the
50          * same? If 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 JavaDoc s)
60     {
61         url=null;
62         urlAsString=s;
63         hashCode=urlAsString.hashCode();
64     }
65
66     public String JavaDoc toString()
67     {
68         return urlAsString;
69     }
70
71     public URL JavaDoc getURL()
72     {
73         return url;
74     }
75     
76     public int compareTo(Object JavaDoc o)
77     {
78         return urlAsString.compareTo(o.toString());
79     }
80     
81     public boolean equals(Object JavaDoc o)
82     {
83         return (o instanceof URLString && urlAsString.equals(o.toString()));
84     }
85
86     public int hashCode()
87     {
88         return hashCode;
89     }
90 }
91
Popular Tags