KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > cache > FileSystemAndNameKey


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.cache;
17
18 import org.apache.commons.vfs.FileName;
19 import org.apache.commons.vfs.FileSystem;
20
21 /**
22  * Key for various cache implementations.<br>
23  * It compares the fileSystem (by hashCode) and the filename.
24  *
25  * @author <a HREF="mailto:imario@apache.org">Mario Ivankovits</a>
26  */

27 class FileSystemAndNameKey implements Comparable JavaDoc
28 {
29     private final FileSystem fileSystem;
30     private final FileName fileName;
31     private final int fileSystemId;
32
33     FileSystemAndNameKey(final FileSystem fileSystem, final FileName fileName)
34     {
35         this.fileSystem = fileSystem;
36         this.fileSystemId = System.identityHashCode(fileSystem);
37
38         this.fileName = fileName;
39     }
40
41     public int compareTo(Object JavaDoc o)
42     {
43         FileSystemAndNameKey other = (FileSystemAndNameKey) o;
44
45         if (fileSystemId < other.fileSystemId)
46         {
47             return -1;
48         }
49         if (fileSystemId > other.fileSystemId)
50         {
51             return 1;
52         }
53
54         return fileName.compareTo(other.fileName);
55     }
56
57     FileSystem getFileSystem()
58     {
59         return fileSystem;
60     }
61
62     FileName getFileName()
63     {
64         return fileName;
65     }
66 }
67
Popular Tags