In ISO9660Directory, are names really not-case-sensitives ?

It will give me some problem, as I would like to use a Map (entryName-> entry) in an AbstractFSDirectory.

Perhaps modify the filename first

Maybe for filesystems such as FAT and ISO9660 the "key" for the map could be converted to lower case. Perhaps the FS interface could supply a method like public boolean isCaseSensitive(). If the filesystem returns true, simply lowercase the filename and use that as the key.

Just a suggestion.

Matt.

I found the solution

As often, I have found the solution in the jakarta commons-collections library.

They have a class named CaseInsensitiveMap that is exactly what I wanted.

now I know what you mean

yea..that is a good idea..sry I thought you mean the name of the class..

finally I don't need CaseInsensitiveMap

Isantha in his post convinced me that's better avoid using a new external library.

And, in fact, I have necessity to use this library just for one class that I need to be more specialized.

The best CaseInsensitiveMap !

This one is much more flexible than jakartas and it only took me 10 minutes to implement:

ENJOY.

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
* This class wraps a Map and makes the key of type String case-insensitive.
*

 * Map map = new CaseInsensitiveMap(new HashMap());
 * map.put("XYZ", new Integer(1);
 * map.get("Xyz").equals(map.get("xZY");
 * 

*
* @author robertg
*/
public class CaseInsensitiveMap implements Map {

public static void main(String[] args) {
Map map = new CaseInsensitiveMap(new HashMap());
map.put("xyz", "some value");
map.put(new Integer(666), new Object());

System.out.println(map.containsKey("XYZ"));
System.out.println(map.get("XYZ"));
System.out.println(map.get("xYz").equals(map.get("XyZ")));
System.out.println(map.remove("XYZ"));
System.out.println(map.containsKey("XYZ"));
System.out.println(map.containsKey(new Integer(666)));
}

private Map map;

/**
*
* @param map
*/
public CaseInsensitiveMap(Map map) {
if (map == null) {
throw new IllegalArgumentException("The attribute: map cannot be null.");
}
this.map = map;
}

/**
*
*/
public void clear() {
map.clear();
}
private boolean containsKeyInse(Object key) {
Object o = getActualKey(key);
return o != null;
}

private Object getActualKey(Object key) {
if (key instanceof String) {
Set set = map.keySet();
for (Iterator i = set.iterator(); i.hasNext()Eye-wink {
Object o = (Object) i.next();
if (o instanceof String) {
if (((String) o).equalsIgnoreCase((String) key)) {
return o;
}
}
}

return null;
} else {
return key;
}
}

/**
* @param key
* @return
*/
public boolean containsKey(Object key) {
return containsKeyInse(key);
}
/**
* @param value
* @return
*/
public boolean containsValue(Object value) {
return map.containsValue(value);
}
/**
* @return
*/
public Set entrySet() {
return map.entrySet();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
return map.equals(obj);
}
/**
* @param key
* @return
*/
public Object get(Object key) {
Object realKey = getActualKey(key);

return map.get(realKey);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return map.hashCode();
}
/**
* @return
*/
public boolean isEmpty() {
return map.isEmpty();
}
/**
* @return
*/
public Set keySet() {
return map.keySet();
}
/**
* @param key
* @param value
* @return
*/
public Object put(Object key, Object value) {
return map.put(key, value);
}
/**
* @param t
*/
public void putAll(Map t) {
map.putAll(t);
}
/**
* @param key
* @return
*/
public Object remove(Object key) {
return map.remove(getActualKey(key));
}
/**
* @return
*/
public int size() {
return map.size();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
return map.toString();
}
/**
* @return
*/
public Collection values() {
return map.values();
}
}

slow

Hi,
The problem with this implementation is that if the key is a String, then you iterate through all the keys in the Map. I.e. even if the underlying Map is HashMap, a search in this CaseInsensitiveMap will be O(n) compared to O(1) with the HashMap. So you lose the reason why you would use a HashMap.

Instead, I would write a wrapper around Map which converts any keys to lowercase in the put() and get() (and use whatever Map implementation is used to construct the CaseInsensitiveMap). And probably also store the original keys to be able to return them in the keySet() as they were.

Andras

Case Sensitivity

I have not really been following this conversation, so please forgive me if I speak in ignorence. Would it not be possible for the keys of the fs map to use ingnoreCaseEquals() in their equals() methods? So long as those euals() methods allowed Strings, would that not provide case insensitivity?

the key is a String

because the key is a String, I can't modify its equals method (as String is final, I can't inherit).

Perhaps, we can have a class FSEntryKey that is a wrapper to a String.

Or use the FSEntry as its own key. And in FSEntry.equals, we can compare
with the given Object (another FSEntry or a String) in the way we want (which depend on the FSEntry implementation).
Of course, FSEntry.hashCode will return the hashCode of the name.

I named it CDFS first

I named it CDFS first but epr said I should rename is iso9660. I agree with epr tha CDFS is no good name..if you have better ideas pls change them