-
Notifications
You must be signed in to change notification settings - Fork 0
/
Recycle.java
31 lines (28 loc) · 904 Bytes
/
Recycle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package kr.ac.tukorea.sgp22.nerverendingjump.framework;
import java.util.ArrayList;
import java.util.HashMap;
public class Recycle
{
private static HashMap<Class, ArrayList<GameObject>> recycle = new HashMap<>();
public static void init() { recycle.clear(); }
public static GameObject get (Class clazz)
{
ArrayList<GameObject> bin = recycle.get(clazz);
if (bin == null) return null;
if (bin.size() == 0) return null;
return bin.remove(0);
}
public static void add(GameObject object) {
Class clazz = object.getClass();
ArrayList<GameObject> bin = recycle.get(clazz);
if (bin == null) {
bin = new ArrayList<>();
recycle.put(clazz, bin);
}
if (bin.indexOf(object) >= 0) {
// already exists in the recycle bin
return;
}
bin.add(object);
}
}