Thursday, April 5, 2007

The ThreeKeyCache needs to be strongly typed

While working on the Java 5 upgrade, I found that the ThreeKeyCache is not strongly typed. To work around this problem, I had to add four lines of code to copy the data to a new strongly typed set.

public Set getFileTypes(FilePattern filePattern, boolean removeWildCard) {
if (containsFilePattern(filePattern)) {
Set keySet = this.cache.getKey2Set(filePattern);
if (removeWildCard) {
Set newKeySet = new HashSet();
for (Iterator i = keySet.iterator(); i.hasNext(); ) {
String fileType = (String)i.next();
if (!("*".equals(fileType))) {
newKeySet.add(fileType);
}
}
return newKeySet;
}
else {
Set newKeySet = new HashSet();
for (Object fileType : keySet) {
newKeySet.add((String) fileType);
}
return newKeySet;
}
}
else {
return new HashSet();
}
}