A light pool of objects that can be resused to avoid allocation. : Location « Hardware « Android






A light pool of objects that can be resused to avoid allocation.

 



import java.util.ArrayList;

/**
 * A light pool of objects that can be resused to avoid allocation.
 * Based on Nathan Sweet pool implementation
 */
 abstract class Pool<T> {
  private final ArrayList<T> objects;

  public Pool (int initCapacity) {
    objects = new ArrayList<T>(initCapacity);
  }

  protected abstract T getNew();

  public T get() {
    return objects.isEmpty() ? getNew() : objects.remove(objects.size()-1);
  }

  public void free(T obj) {
    if (!objects.contains(obj))
      objects.add(obj);
  }

  public void clear() {
    objects.clear();
  }

  public int size() {
    return objects.size();
  }
}

   
  








Related examples in the same category

1.Location service and LocationManager
2.Location service
3.Using LocationManager
4.My location
5.Display GEO location
6.Using location service for the weather
7.Using Intent to go to a geo location
8.Location based service
9.My location and Google Map
10.Custom Location Overlay
11.Get my location
12.Geo location and Google Map
13.Location Tracking
14.extends android.location.Location
15.Geo Location Util
16.C:\Java_Dev\WEB\dev\android\weatherforecastsystem-read-only\com\hci\pwf\LocationUtil.java
17.upload Data with Geo location
18.Copy a file from one location to another.
19.LocationManager.GPS_PROVIDER
20.Location util