KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > common > Scope


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/common/Scope.java,v 1.8 2004/07/28 09:38:16 ib Exp $
3  * $Revision: 1.8 $
4  * $Date: 2004/07/28 09:38:16 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.common;
25
26 /**
27  * Scope object.
28  * <p/>
29  * A scope represents a directory on the server. Ex : /foo/bar.txt belongs
30  * to the /foo/ scope.
31  *
32  * @version $Revision: 1.8 $
33  */

34 public final class Scope {
35     
36     public static final Scope ROOT = new Scope("/");
37     
38     // ----------------------------------------------------------- Constructors
39

40     
41     /**
42      * Constructor.
43      *
44      * @param scope String representation of the scope.
45      */

46     public Scope(String JavaDoc scope) {
47         this.scope = scope;
48         scopeID = scope.hashCode();
49     }
50     
51     
52     // ----------------------------------------------------- Instance Variables
53

54     
55     /**
56      * Hash code of the scope.
57      */

58     private int scopeID;
59     
60     
61     /**
62      * String representation of the scope.
63      */

64     private String JavaDoc scope;
65     
66     
67     // --------------------------------------------------------- Public Methods
68

69     
70     /**
71      * Returns the String representation of the scope.
72      *
73      * @return String
74      */

75     public String JavaDoc toString() {
76         return this.scope;
77     }
78     
79     
80     /**
81      * Tests if two scopes ore equal.
82      *
83      * @param obj Object to test
84      * @return boolean True if the object is equal to the scope
85      */

86     public boolean equals(Object JavaDoc obj) {
87         boolean result = false;
88         if ((obj != null) && (obj instanceof Scope)) {
89             Scope scope = (Scope) obj;
90             result = (this.scopeID == scope.hashCode());
91         }
92         return result;
93     }
94     
95     
96     /**
97      * Hash code.
98      *
99      * @return int Result is the hash code of the String representation
100      * of the scope
101      */

102     public int hashCode() {
103         return this.scopeID;
104     }
105     
106 }
107
Popular Tags