1 | /* |
2 | * Copyright (c) 2005 The PseudoQ Project. |
3 | * |
4 | * This file is part of PseudoQ. |
5 | * |
6 | * PseudoQ is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as published by |
8 | * the Free Software Foundation; either version 2.1 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * PseudoQ is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public License |
17 | * along with PseudoQ; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | */ |
20 | |
21 | package net.sourceforge.pseudoq.model; |
22 | |
23 | /** |
24 | * Factory class that creates Puzzle implementation instances. |
25 | * @author <a href="http://sourceforge.net/users/stevensa">Andrew Stevens</a> |
26 | */ |
27 | public class PuzzleFactory { |
28 | |
29 | /** Prevent creating instances as all methods are static */ |
30 | private PuzzleFactory() { |
31 | } |
32 | |
33 | /** |
34 | * Factory method to create Puzzle instances according to the supplied |
35 | * type. |
36 | * @param type Desired puzzle type. |
37 | */ |
38 | public static Puzzle newInstance(PuzzleTypeEnum type) { |
39 | Puzzle puzzle = null; |
40 | |
41 | if (type == null) { |
42 | throw new IllegalArgumentException("No puzzle type supplied"); |
43 | } |
44 | |
45 | switch (type) { |
46 | case TINY: |
47 | puzzle = TinyPuzzle.create(); |
48 | break; |
49 | case MINI: |
50 | puzzle = MiniPuzzle.create(); |
51 | break; |
52 | case MINI_X: |
53 | puzzle = MiniXPuzzle.create(); |
54 | break; |
55 | case SMALL_X: |
56 | puzzle = SmallXPuzzle.create(); |
57 | break; |
58 | case STANDARD: |
59 | puzzle = StandardPuzzle.create(); |
60 | break; |
61 | case SUPER: |
62 | puzzle = SuperPuzzle.create(); |
63 | break; |
64 | case LARGE: |
65 | puzzle = LargePuzzle.create(); |
66 | break; |
67 | case STANDARD_SAMURAI: |
68 | puzzle = SamuraiPuzzle.create(); |
69 | break; |
70 | default: |
71 | assert false : "Should have covered all possibilities"; |
72 | // return null |
73 | break; |
74 | } |
75 | |
76 | return puzzle; |
77 | } |
78 | |
79 | } |