001 package java.util; 002 003 import railo.runtime.exp.ExpressionException; 004 import railo.runtime.exp.PageException; 005 import railo.runtime.type.Collection.Key; 006 007 public class HashMapNullSensitive extends HashMap<Key, Object> { 008 009 010 public Object gib(Key key) throws PageException { 011 int hash = hash(key.hashCode()); 012 Key k; 013 for (Entry<Key,Object> e = table[indexFor(hash, table.length)]; e != null; e = e.next) { 014 if (e.hash == hash && ((k = e.key) == key || key.equalsIgnoreCase(k))) 015 return e.value; 016 } 017 throw invalidKey(this,key); 018 } 019 020 021 public Object gib(Key key, Object defaultValue) { 022 int hash = hash(key.hashCode()); 023 Key k; 024 for (Entry<Key,Object> e = table[indexFor(hash, table.length)]; e != null; e = e.next) { 025 if (e.hash == hash && ((k = e.key) == key || key.equalsIgnoreCase(k))) 026 return e.value; 027 } 028 return defaultValue; 029 } 030 031 public Object haeb(Key key, Object value) { 032 int hash = hash(key.hashCode()); 033 int i = indexFor(hash, table.length); 034 for (Entry<Key,Object> e = table[i]; e != null; e = e.next) { 035 Key k; 036 if (e.hash == hash && ((k = e.key) == key || key.equalsIgnoreCase(k))) { 037 Object oldValue = e.value; 038 e.value = value; 039 e.recordAccess(this); 040 return oldValue; 041 } 042 } 043 044 modCount++; 045 addEntry(hash, key, value, i); 046 return null; 047 } 048 049 050 public static ExpressionException invalidKey(Map map,Key key) { 051 052 StringBuilder sb=new StringBuilder(); 053 Iterator<Key> it = map.keySet().iterator(); 054 Key k; 055 056 while(it.hasNext()){ 057 k = it.next(); 058 if( k.equals( key ) ) 059 return new ExpressionException( "the value from key [" + key.getString() + "] is NULL, which is the same as not existing in CFML" ); 060 if(sb.length()>0)sb.append(','); 061 sb.append(k.getString()); 062 } 063 064 return new ExpressionException( "key [" + key.getString() + "] doesn't exist (existing keys:" + sb.toString() + ")" ); 065 } 066 }