KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > example > modularity > player > PlayerFactory


1 package net.innig.macker.example.modularity.player;
2
3 import net.innig.macker.example.modularity.player.impl.*;
4 import java.util.*;
5
6 public class PlayerFactory
7     {
8     public static Set getPlayerNames()
9         {
10         Set games = new TreeSet();
11         games.add("(R)andom");
12         games.add("(T)it for Tat");
13         return Collections.unmodifiableSet(games);
14         }
15     
16     public static Player createPlayer(String JavaDoc name)
17         {
18         name = name.trim().toLowerCase();
19         if("random".startsWith(name))
20             return new RandomPlayer();
21         if("tit for tat".startsWith(name))
22             return new TitForTatPlayer();
23         if("cyclic".startsWith(name))
24             return new CyclicPlayer();
25         throw new IllegalArgumentException JavaDoc("Unknown player: " + name);
26         }
27     }
28
Popular Tags