DynamicTLArray.java :  » Graphics-3D-2D-OpenGL » android-opengl-box2d-basics » org » jbox2d » pooling » arrays » Android Open Source

Android Open Source » Graphics 3D 2D OpenGL » android opengl box2d basics 
android opengl box2d basics » org » jbox2d » pooling » arrays » DynamicTLArray.java
package org.jbox2d.pooling.arrays;

import java.util.HashMap;

public abstract class DynamicTLArray<I> {
  
  private static class TLHashMap<K, V> extends ThreadLocal<HashMap<K, V>>{
    protected HashMap<K, V> initialValue(){
      return new HashMap<K, V>();
    }
  }
  
  private final TLHashMap<Integer, I[]> tlMap = new TLHashMap<Integer, I[]>();
  
  public I[] get( int argLength){
    assert(argLength > 0);
    
    HashMap<Integer, I[]> map = tlMap.get();
    
    if(!map.containsKey(argLength)){
      map.put(argLength, getInitializedArray(argLength));
    }
    
    assert(map.get(argLength).length == argLength) : "Array not built of correct length";
    return map.get(argLength);
  }
  
  public void recycle( I[] argArray){
    
  }
  
  protected abstract I[] getInitializedArray(int argLength);
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.