Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.cooliris.media;
     18 
     19 public final class Pool<E extends Object> {
     20     private final E[] mFreeList;
     21     private int mFreeListIndex;
     22 
     23     public Pool(E[] objects) {
     24         mFreeList = objects;
     25         mFreeListIndex = objects.length;
     26     }
     27 
     28     public E create() {
     29         int index = --mFreeListIndex;
     30         if (index >= 0 && index < mFreeList.length) {
     31             E object = mFreeList[index];
     32             mFreeList[index] = null;
     33             return object;
     34         }
     35         return null;
     36     }
     37 
     38     public void delete(E object) {
     39         int index = mFreeListIndex;
     40         if (index >= 0 && index < mFreeList.length) {
     41             mFreeList[index] = object;
     42             mFreeListIndex++;
     43         }
     44     }
     45 }
     46