KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > poifs > filesystem > DocumentDescriptor


1
2 /* ====================================================================
3    Copyright 2002-2004 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.poi.poifs.filesystem;
20
21 /**
22  * Class DocumentDescriptor
23  *
24  * @author Marc Johnson (mjohnson at apache dot org)
25  * @version %I%, %G%
26  */

27
28 public class DocumentDescriptor
29 {
30     private POIFSDocumentPath path;
31     private String JavaDoc name;
32     private int hashcode = 0;
33
34     /**
35      * Trivial constructor
36      *
37      * @param path the Document path
38      * @param name the Document name
39      */

40
41     public DocumentDescriptor(final POIFSDocumentPath path, final String JavaDoc name)
42     {
43         if (path == null)
44         {
45             throw new NullPointerException JavaDoc("path must not be null");
46         }
47         if (name == null)
48         {
49             throw new NullPointerException JavaDoc("name must not be null");
50         }
51         if (name.length() == 0)
52         {
53             throw new IllegalArgumentException JavaDoc("name cannot be empty");
54         }
55         this.path = path;
56         this.name = name;
57     }
58
59     /**
60      * equality. Two DocumentDescriptor instances are equal if they
61      * have equal paths and names
62      *
63      * @param o the object we're checking equality for
64      *
65      * @return true if the object is equal to this object
66      */

67
68     public boolean equals(final Object JavaDoc o)
69     {
70         boolean rval = false;
71
72         if ((o != null) && (o.getClass() == this.getClass()))
73         {
74             if (this == o)
75             {
76                 rval = true;
77             }
78             else
79             {
80                 DocumentDescriptor descriptor = ( DocumentDescriptor ) o;
81
82                 rval = this.path.equals(descriptor.path)
83                        && this.name.equals(descriptor.name);
84             }
85         }
86         return rval;
87     }
88
89     /**
90      * calculate and return the hashcode
91      *
92      * @return hashcode
93      */

94
95     public int hashCode()
96     {
97         if (hashcode == 0)
98         {
99             hashcode = path.hashCode() ^ name.hashCode();
100         }
101         return hashcode;
102     }
103
104     public String JavaDoc toString()
105     {
106         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(40 * (path.length() + 1));
107
108         for (int j = 0; j < path.length(); j++)
109         {
110             buffer.append(path.getComponent(j)).append("/");
111         }
112         buffer.append(name);
113         return buffer.toString();
114     }
115 } // end public class DocumentDescriptor
116

117
Popular Tags