1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs;
18
19 import java.util.Map;
20 import java.util.TreeMap;
21
22 /***
23 * Container for FileSystemOptions.<br>
24 * You have to use *FileSystemConfigBuilder.getInstance() to fill this container<br>
25 * * = the filesystem provider short name
26 *
27 * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
28 * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
29 * @see org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder
30 * @see org.apache.commons.vfs.provider.ftp.FtpFileSystemConfigBuilder
31 */
32 public class FileSystemOptions
33 {
34 private Map options = new TreeMap();
35
36 private class FileSystemOptionKey implements Comparable
37 {
38 private final Class fileSystemClass;
39 private final String name;
40
41 private FileSystemOptionKey(Class fileSystemClass, String name)
42 {
43 this.fileSystemClass = fileSystemClass;
44 this.name = name;
45 }
46
47 public int compareTo(Object o)
48 {
49 FileSystemOptionKey k = (FileSystemOptionKey) o;
50
51 int ret = k.fileSystemClass.getName().compareTo(k.fileSystemClass.getName());
52 if (ret != 0)
53 {
54 return ret;
55 }
56
57 return name.compareTo(k.name);
58 }
59
60 public boolean equals(Object o)
61 {
62 if (this == o)
63 {
64 return true;
65 }
66 if (o == null || getClass() != o.getClass())
67 {
68 return false;
69 }
70
71 final FileSystemOptionKey that = (FileSystemOptionKey) o;
72
73 if (!fileSystemClass.equals(that.fileSystemClass))
74 {
75 return false;
76 }
77 if (!name.equals(that.name))
78 {
79 return false;
80 }
81
82 return true;
83 }
84
85 public int hashCode()
86 {
87 int result;
88 result = fileSystemClass.hashCode();
89 result = 29 * result + name.hashCode();
90 return result;
91 }
92 }
93
94 public FileSystemOptions()
95 {
96 }
97
98 void setOption(Class fileSystemClass, String name, Object value)
99 {
100 options.put(new FileSystemOptionKey(fileSystemClass, name), value);
101 }
102
103 Object getOption(Class fileSystemClass, String name)
104 {
105 FileSystemOptionKey key = new FileSystemOptionKey(fileSystemClass, name);
106 return options.get(key);
107 }
108
109 boolean hasOption(Class fileSystemClass, String name)
110 {
111 FileSystemOptionKey key = new FileSystemOptionKey(fileSystemClass, name);
112 return options.containsKey(key);
113 }
114
115 public int compareTo(FileSystemOptions other)
116 {
117 if (this == other)
118 {
119
120 return 0;
121 }
122
123 int propsSz = options == null ? 0 : options.size();
124 int propsFkSz = other.options == null ? 0 : other.options.size();
125 if (propsSz < propsFkSz)
126 {
127 return -1;
128 }
129 if (propsSz > propsFkSz)
130 {
131 return 1;
132 }
133 if (propsSz == 0)
134 {
135
136 return 0;
137 }
138
139 int hash = options.hashCode();
140 int hashFk = other.options.hashCode();
141 if (hash < hashFk)
142 {
143 return -1;
144 }
145 if (hash > hashFk)
146 {
147 return 1;
148 }
149
150
151
152 return 0;
153 }
154 }