Search in sources :

Example 1 with List

use of com.scratchdisk.list.List in project scriptographer by scriptographer.

the class ListWrapper method coerceComponentType.

private Object coerceComponentType(Object value) {
    Object unwrapped = value;
    if (unwrapped instanceof Wrapper)
        unwrapped = ((Wrapper) unwrapped).unwrap();
    Class type = ((List) javaObject).getComponentType();
    // Use WrapFactory to coerce type if not compatible
    return type.isInstance(unwrapped) ? unwrapped : Context.getCurrentContext().getWrapFactory().coerceType(type, value, unwrapped);
}
Also used : Wrapper(org.mozilla.javascript.Wrapper) ScriptableObject(org.mozilla.javascript.ScriptableObject) List(com.scratchdisk.list.List) ReadOnlyStringIndexList(com.scratchdisk.list.ReadOnlyStringIndexList) StringIndexList(com.scratchdisk.list.StringIndexList) ReadOnlyList(com.scratchdisk.list.ReadOnlyList)

Example 2 with List

use of com.scratchdisk.list.List in project scriptographer by scriptographer.

the class ListWrapper method put.

@SuppressWarnings("unchecked")
public void put(int index, Scriptable start, Object value) {
    if (javaObject != null && javaObject instanceof List) {
        List list = ((List) javaObject);
        int size = list.size();
        value = coerceComponentType(value);
        if (index >= size) {
            for (int i = size; i < index; i++) list.add(i, null);
            list.add(index, value);
        } else {
            list.set(index, value);
        }
        if (changeReceiver != null)
            updateChangeReceiver();
    }
}
Also used : List(com.scratchdisk.list.List) ReadOnlyStringIndexList(com.scratchdisk.list.ReadOnlyStringIndexList) StringIndexList(com.scratchdisk.list.StringIndexList) ReadOnlyList(com.scratchdisk.list.ReadOnlyList)

Aggregations

List (com.scratchdisk.list.List)2 ReadOnlyList (com.scratchdisk.list.ReadOnlyList)2 ReadOnlyStringIndexList (com.scratchdisk.list.ReadOnlyStringIndexList)2 StringIndexList (com.scratchdisk.list.StringIndexList)2 ScriptableObject (org.mozilla.javascript.ScriptableObject)1 Wrapper (org.mozilla.javascript.Wrapper)1