2010年03月

Rhinoで"missing variable name"と出た場合とりあえず確認するところ

本来javascriptで予約語のハズだが
許容されていると思われる変数名がいくつかあるようだ

Rhinoで実行した場合内部で変数がインスタンス化してると思うが
予約語の制限でExceptionが発生する
本来は予約語なので使うんじゃねーよと思うけども
現実に許容されているわけだ。
org.mozilla.javascript.Context
になんか許容レベル設定みたいな物あるのかな?と探してみたがなんかないように思える。

そこでjavaの予約語なんだけど実際のブラウザ許容されている可能性が高い予約語をまとめてみた。

■javascriptの予約語だが許容されてると思われる物
abstract
boolean
byte
class
double
extends
final
float
goto
implements
import
int
interface
long
native
package
private
protected
public
short
super
synchornized
static
throws
transient

■javaの予約語だがjavascriptの予約語ではないもの
strictfp
enum
assert
volatile
unsigned


解決策->置換である 笑

FireFoxで許容してしまうjavascriptの予約語一覧

ブラウザバージョン : FireFox 3.58

本来javascriptの予約語のはずだが、
変数として定義した場合許容されている物

abstract
boolean
byte
class
char
double
extends
final
float
goto
implements
import
int
interface
long
native
package
private
protected
public
short
super
synchronized
static
throws
transient

javaで並行処理 とりあえずスレッドセーフなListを作る

Map関連だとConcurrentHashMapなりがあって
そこそこ恩恵を受けるのだがMapほどリソースを食いたくない且つとりあえずスレッドセーフなListが必要なときはこんな感じにすればいいと思う。


ConcurrentArrayList.java

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class ConcurrentArrayList<V> implements List<V>,Cloneable {

    private ArrayList<V> list;
    private final ReentrantReadWriteLock lock;
   
    public ConcurrentArrayList() {
        list = new ArrayList<V>();
        lock = new ReentrantReadWriteLock();
    }
   
    public ConcurrentArrayList(int n) {
        list = new ArrayList<V>(n);
        lock = new ReentrantReadWriteLock();
    }
   
    public int size() {
        int response = 0;
        try {
            lock.readLock().lock();
            response=  list.size();
        } finally {
            lock.readLock().unlock();
        }
        return response;
    }

    public boolean isEmpty() {
        boolean response= false;
        try {
            lock.readLock().lock();
            response = list.isEmpty();
        } finally {
            lock.readLock().unlock();
        }       
        return response;
    }

    public boolean contains(Object arg0) {
        boolean response = false;
        try {
            lock.readLock().lock();
            response = list.contains(arg0);           
        } finally {
            lock.readLock().unlock();
        }       
        return response;
    }

    public Iterator<V> iterator() {
        Iterator<V> response = null;
        try {
            lock.writeLock().lock();
            response = list.iterator();           
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public Object[] toArray() {
        Object[] response = null;
        try {
            lock.writeLock().lock();
           
            response = list.toArray();
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public Object[] toArray(Object[] arg0) {
        Object[] response = null;
        try {
            lock.writeLock().lock();
            response= list.toArray(arg0);
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public boolean add(V arg0) {
        boolean response = false;
        try {
            lock.writeLock().lock();
            response = list.add(arg0);
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public boolean remove(Object arg0) {
        boolean response = false;
        try {
            lock.writeLock().lock();
            response = list.remove(arg0);
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public boolean containsAll(Collection arg0) {
        boolean response= false;
        try {
            lock.readLock().lock();
            response = list.containsAll(arg0);
           
        } finally {
            lock.readLock().unlock();
        }       
        return response;
    }

    public boolean addAll(Collection<? extends V> arg0) {
        boolean response = false;
        try {
            lock.writeLock().lock();
            response = list.addAll(arg0);
        } finally {
            lock.writeLock().unlock();
        }
        return response;
    }

    public boolean addAll(int arg0, Collection<? extends V> arg1) {
        boolean response = false;
        try  {
            lock.writeLock().lock();
            response = list.addAll(arg0, arg1);
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public boolean removeAll(Collection arg0) {
        boolean response = false;
        try {
            lock.writeLock().lock();
            response = list.removeAll(arg0);
        } finally {
            lock.writeLock().unlock();
        }
        return response;
    }

    public boolean retainAll(Collection arg0) {
        boolean response = false;
        try {
            lock.writeLock().lock();
           
            response = list.retainAll(arg0);
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public void clear() {
        try {
            lock.writeLock().lock();
            list.clear();
        } finally {
            lock.writeLock().unlock();
        }
    }

    public V get(int arg0) {
        V response = null;
        try {
            lock.readLock().lock();
            response = list.get(arg0);
        } finally {
            lock.readLock().unlock();
        }       
        return response;
    }

    public V set(int arg0, V arg1) {
        V response = null;
        try {
            lock.writeLock().lock();
            response = list.set(arg0, arg1);
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public void add(int arg0, V arg1) {
        try {
            lock.writeLock().lock();
            list.add(arg0,arg1);
        } finally {
            lock.writeLock().unlock();
        }       
    }

    public V remove(int arg0) {
        V response = null;
        try {
            lock.writeLock().lock();
            response = list.remove(arg0);
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public int indexOf(Object arg0) {
        int response = 0;
        try {
            lock.readLock().lock();
            response = list.indexOf(arg0);
        } finally {
            lock.readLock().unlock();
        }
       
        return response;
    }

    public int lastIndexOf(Object arg0) {
        int response = 0;
        try {
            lock.readLock().lock();
            response = list.lastIndexOf(arg0);
        } finally {
            lock.readLock().unlock();
        }
        return response;
    }

    public ListIterator<V> listIterator() {
        ListIterator<V> response = null;
        try {
            lock.writeLock().lock();
            response = list.listIterator();
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }

    public ListIterator<V> listIterator(int arg0) {
        ListIterator<V> response = null;
        try {
            lock.writeLock().lock();
            response = list.listIterator(arg0);
        } finally {
            lock.writeLock().unlock();
        }
        return response;
    }

    public List<V> subList(int arg0, int arg1) {
        List<V> response = null;
        try {
            lock.writeLock().lock();
            response = list.subList(arg0,arg1);
        } finally {
            lock.writeLock().unlock();
        }       
        return response;
    }
   
    public void removeAll() {
        while(list.size()!=0)
            for(int i=0; i<list.size();i++) {
                list.remove(i);
            }       
    }
   
    private void setList(ArrayList<V> list) {       
        this.list = list;
    }
   
    public ConcurrentArrayList clone() throws CloneNotSupportedException {
        ConcurrentArrayList obj = (ConcurrentArrayList)super.clone();
        obj.setList((ArrayList)list.clone());
        return obj;       
    }

}

えへっ

ブログなんかかかねーよ!

って思ってたけど

何か書きます

基本的に技術関連の豆知識になるのかな?
プロフィール

uhouhho

カテゴリ別アーカイブ
タグクラウド
QRコード
QRコード
  • ライブドアブログ