1 16 package org.apache.commons.vfs; 17 18 import java.util.Map ; 19 import java.util.TreeMap ; 20 21 30 public class FileSystemOptions 31 { 32 private Map options = new TreeMap (); 33 34 private class FileSystemOptionKey implements Comparable 35 { 36 private final Class fileSystemClass; 37 private final String name; 38 39 private FileSystemOptionKey(Class fileSystemClass, String name) 40 { 41 this.fileSystemClass = fileSystemClass; 42 this.name = name; 43 } 44 45 public int compareTo(Object o) 46 { 47 FileSystemOptionKey k = (FileSystemOptionKey) o; 48 49 int ret = k.fileSystemClass.getName().compareTo(k.fileSystemClass.getName()); 50 if (ret != 0) 51 { 52 return ret; 53 } 54 55 return name.compareTo(k.name); 56 } 57 58 public boolean equals(Object o) 59 { 60 if (this == o) 61 { 62 return true; 63 } 64 if (o == null || getClass() != o.getClass()) 65 { 66 return false; 67 } 68 69 final FileSystemOptionKey that = (FileSystemOptionKey) o; 70 71 if (!fileSystemClass.equals(that.fileSystemClass)) 72 { 73 return false; 74 } 75 if (!name.equals(that.name)) 76 { 77 return false; 78 } 79 80 return true; 81 } 82 83 public int hashCode() 84 { 85 int result; 86 result = fileSystemClass.hashCode(); 87 result = 29 * result + name.hashCode(); 88 return result; 89 } 90 } 91 92 public FileSystemOptions() 93 { 94 } 95 96 void setOption(Class fileSystemClass, String name, Object value) 97 { 98 options.put(new FileSystemOptionKey(fileSystemClass, name), value); 99 } 100 101 Object getOption(Class fileSystemClass, String name) 102 { 103 FileSystemOptionKey key = new FileSystemOptionKey(fileSystemClass, name); 104 return options.get(key); 105 } 106 107 boolean hasOption(Class fileSystemClass, String name) 108 { 109 FileSystemOptionKey key = new FileSystemOptionKey(fileSystemClass, name); 110 return options.containsKey(key); 111 } 112 113 public int compareTo(FileSystemOptions other) 114 { 115 if (this == other) 116 { 117 return 0; 119 } 120 121 int propsSz = options == null ? 0 : options.size(); 122 int propsFkSz = other.options == null ? 0 : other.options.size(); 123 if (propsSz < propsFkSz) 124 { 125 return -1; 126 } 127 if (propsSz > propsFkSz) 128 { 129 return 1; 130 } 131 if (propsSz == 0) 132 { 133 return 0; 135 } 136 137 int hash = options.hashCode(); 138 int hashFk = other.options.hashCode(); 139 if (hash < hashFk) 140 { 141 return -1; 142 } 143 if (hash > hashFk) 144 { 145 return 1; 146 } 147 148 return 0; 151 } 152 } 153 | Popular Tags |