xref: /aosp_15_r20/external/replicaisland/src/com/replica/replicaisland/GameComponentPool.java (revision 5eae8ebb3c5756e41e77a1f7201fcf94b0eade1f)
1*5eae8ebbSCole Faust /*
2*5eae8ebbSCole Faust  * Copyright (C) 2010 The Android Open Source Project
3*5eae8ebbSCole Faust  *
4*5eae8ebbSCole Faust  * Licensed under the Apache License, Version 2.0 (the "License");
5*5eae8ebbSCole Faust  * you may not use this file except in compliance with the License.
6*5eae8ebbSCole Faust  * You may obtain a copy of the License at
7*5eae8ebbSCole Faust  *
8*5eae8ebbSCole Faust  *      http://www.apache.org/licenses/LICENSE-2.0
9*5eae8ebbSCole Faust  *
10*5eae8ebbSCole Faust  * Unless required by applicable law or agreed to in writing, software
11*5eae8ebbSCole Faust  * distributed under the License is distributed on an "AS IS" BASIS,
12*5eae8ebbSCole Faust  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*5eae8ebbSCole Faust  * See the License for the specific language governing permissions and
14*5eae8ebbSCole Faust  * limitations under the License.
15*5eae8ebbSCole Faust  */
16*5eae8ebbSCole Faust 
17*5eae8ebbSCole Faust package com.replica.replicaisland;
18*5eae8ebbSCole Faust 
19*5eae8ebbSCole Faust public class GameComponentPool extends TObjectPool<GameComponent> {
20*5eae8ebbSCole Faust     public Class<?> objectClass;
21*5eae8ebbSCole Faust 
GameComponentPool(Class<?> type)22*5eae8ebbSCole Faust     public GameComponentPool(Class<?> type) {
23*5eae8ebbSCole Faust         super();
24*5eae8ebbSCole Faust         objectClass = type;
25*5eae8ebbSCole Faust         fill();
26*5eae8ebbSCole Faust     }
27*5eae8ebbSCole Faust 
GameComponentPool(Class<?> type, int size)28*5eae8ebbSCole Faust     public GameComponentPool(Class<?> type, int size) {
29*5eae8ebbSCole Faust         super(size);
30*5eae8ebbSCole Faust         objectClass = type;
31*5eae8ebbSCole Faust         fill();
32*5eae8ebbSCole Faust     }
33*5eae8ebbSCole Faust 
34*5eae8ebbSCole Faust     @Override
fill()35*5eae8ebbSCole Faust     protected void fill() {
36*5eae8ebbSCole Faust         if (objectClass != null) {
37*5eae8ebbSCole Faust             for (int x = 0; x < getSize(); x++) {
38*5eae8ebbSCole Faust                 try {
39*5eae8ebbSCole Faust                     getAvailable().add(objectClass.newInstance());
40*5eae8ebbSCole Faust                 } catch (IllegalAccessException e) {
41*5eae8ebbSCole Faust                     // TODO Auto-generated catch block
42*5eae8ebbSCole Faust                     e.printStackTrace();
43*5eae8ebbSCole Faust                 } catch (InstantiationException e) {
44*5eae8ebbSCole Faust                     // TODO Auto-generated catch block
45*5eae8ebbSCole Faust                     e.printStackTrace();
46*5eae8ebbSCole Faust                 }
47*5eae8ebbSCole Faust             }
48*5eae8ebbSCole Faust         }
49*5eae8ebbSCole Faust     }
50*5eae8ebbSCole Faust 
51*5eae8ebbSCole Faust }
52*5eae8ebbSCole Faust 
53*5eae8ebbSCole Faust 
54*5eae8ebbSCole Faust 
55