2014-06-01から1ヶ月間の記事一覧

ストップウォッチ

/** * 時間計測用クラス */ public class StopWatch { static { // JITコンパイルでも走るのか、最初の1回目は遅いので適当に動かしておく StopWatch s = new StopWatch(2, TimeUnit.NANOSECONDS); s.start(); s.phase(""); s.split(""); s.stop(); s.phases…

変更の可/不可を切り替えられるコレクション

public class ConditionalModifiableCollection<T> implements Collection<T> { private class ConditionalModifiableIterator implements Iterator<T> { private Iterator<T> it = baseCollection.iterator(); @Override public boolean hasNext() { return it.hasNext(</t></t></t></t>…

後始末のできるThreadLocal

/** * GCでインスタンスが解放される前に任意の処理を行うためのThreadLocal。<br/> * 必要な解放処理は{@link Closeable#close()}に実装する。<br/> * 注意点:<br/> * <ul> * <li>このThreadLocal以外でインスタンスの強い参照を持っていても、スレッドがなくなると{@link Closeabl</li></ul></br/></br/></br/>…