ScriptableHashMap fixed to support integer indexing as an associative javascript array - AR-712

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3496 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-08-14 15:11:41 +00:00
parent 50ab6661c4
commit 8246e38dcd

View File

@@ -16,17 +16,19 @@
*/ */
package org.alfresco.repo.jscript; package org.alfresco.repo.jscript;
import java.util.HashMap; import java.util.Iterator;
import java.util.LinkedHashMap;
import org.alfresco.service.namespace.NamespacePrefixResolver;
import org.alfresco.service.namespace.QNameMap;
import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Scriptable;
/** /**
* @author Kevin Roast * @author Kevin Roast
*/ */
public class ScriptableHashMap<K,V> extends HashMap implements Scriptable public class ScriptableHashMap<K,V> extends LinkedHashMap implements Scriptable
{ {
private Scriptable parentScope;
private Scriptable prototype;
/** /**
* @see org.mozilla.javascript.Scriptable#getClassName() * @see org.mozilla.javascript.Scriptable#getClassName()
*/ */
@@ -56,7 +58,14 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public Object get(int index, Scriptable start) public Object get(int index, Scriptable start)
{ {
return null; Object value = null;
int i=0;
Iterator itrValues = this.values().iterator();
while (i++ <= index && itrValues.hasNext())
{
value = itrValues.next();
}
return value;
} }
/** /**
@@ -73,7 +82,7 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public boolean has(int index, Scriptable start) public boolean has(int index, Scriptable start)
{ {
return false; return (index >= 0 && this.values().size() > index);
} }
/** /**
@@ -90,6 +99,7 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public void put(int index, Scriptable start, Object value) public void put(int index, Scriptable start, Object value)
{ {
// TODO: implement?
} }
/** /**
@@ -106,6 +116,17 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public void delete(int index) public void delete(int index)
{ {
int i=0;
Iterator itrKeys = this.keySet().iterator();
while (i <= index && itrKeys.hasNext())
{
Object key = itrKeys.next();
if (i == index)
{
remove(key);
break;
}
}
} }
/** /**
@@ -113,7 +134,7 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public Scriptable getPrototype() public Scriptable getPrototype()
{ {
return null; return this.prototype;
} }
/** /**
@@ -121,6 +142,7 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public void setPrototype(Scriptable prototype) public void setPrototype(Scriptable prototype)
{ {
this.prototype = prototype;
} }
/** /**
@@ -128,7 +150,7 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public Scriptable getParentScope() public Scriptable getParentScope()
{ {
return null; return this.parentScope;
} }
/** /**
@@ -136,6 +158,7 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public void setParentScope(Scriptable parent) public void setParentScope(Scriptable parent)
{ {
this.parentScope = parent;
} }
/** /**
@@ -143,7 +166,7 @@ public class ScriptableHashMap<K,V> extends HashMap implements Scriptable
*/ */
public Object[] getIds() public Object[] getIds()
{ {
return null; return keySet().toArray();
} }
/** /**