16
16
import java .util .List ;
17
17
import java .util .zip .GZIPInputStream ;
18
18
19
- public class GameLoader implements IHistoryListener {
19
+ public class GameLoader < T > implements IHistoryListener {
20
20
private static final Logger logger = LoggerFactory .getLogger (GameLoader .class );
21
21
private volatile boolean finished ;
22
- private Object obj = null ;
23
- private List <Class <? >> clazzes ;
22
+ private T obj = null ;
23
+ private List <Class <T >> clazzes ;
24
24
private GameLoaderClient client ;
25
25
26
- public GameLoader (List <Class <? >> clazzes ) {
26
+ public GameLoader (List <Class <T >> clazzes ) {
27
27
this .finished = false ;
28
28
this .clazzes = clazzes ;
29
29
}
30
30
31
- public GameLoader (Class <? >... clazz ) {
31
+ public GameLoader (Class <T >... clazz ) {
32
32
this (Arrays .asList (clazz ));
33
33
}
34
34
35
- public Object loadGame (String filename ) {
35
+ public T loadGame (String filename ) {
36
36
try {
37
37
return loadGame (new File (filename ));
38
38
} catch (IOException e ) {
@@ -41,19 +41,19 @@ public Object loadGame(String filename) {
41
41
}
42
42
}
43
43
44
- public Object loadGame (File file ) throws IOException {
44
+ public T loadGame (File file ) throws IOException {
45
45
return loadGame (new FileInputStream (file ), file .getName ().endsWith (".gz" ));
46
46
}
47
47
48
- public Object loadGame (FileInputStream stream , boolean gzip ) throws IOException {
48
+ public T loadGame (FileInputStream stream , boolean gzip ) throws IOException {
49
49
if (gzip ) {
50
50
return loadGame (new GZIPInputStream (stream ));
51
51
} else {
52
52
return loadGame (stream );
53
53
}
54
54
}
55
55
56
- public Object loadGame (InputStream file ) throws IOException {
56
+ public T loadGame (InputStream file ) throws IOException {
57
57
client = new GameLoaderClient (file );
58
58
client .addListener (this );
59
59
client .start ();
@@ -80,7 +80,7 @@ public void onGameOver(String roomId, GameResult result) {
80
80
public void onNewState (String roomId , IGameState state ) {
81
81
logger .debug ("Received new state" );
82
82
if (!this .finished ) {
83
- for (Class <? > clazz : this .clazzes ) {
83
+ for (Class <T > clazz : this .clazzes ) {
84
84
if (clazz .isInstance (state )) {
85
85
logger .debug ("Received game info of type {}" , clazz .getName ());
86
86
this .obj = clazz .cast (state );
0 commit comments