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.solver; |
22 | |
23 | import net.sourceforge.pseudoq.model.Puzzle; |
24 | |
25 | /** |
26 | * Factory class for Solver instances. |
27 | * @author <a href="http://sourceforge.net/users/stevensa">Andrew Stevens</a> |
28 | */ |
29 | public class SolverFactory { |
30 | /** Prevent instantiation as all methods are static. */ |
31 | private SolverFactory() { |
32 | } |
33 | |
34 | /** |
35 | * Create a new Solver instance for the specified puzzle. The actual |
36 | * implementation class returned will depend on the puzzle's type. |
37 | * @param puzzle The puzzle to be solved. |
38 | * @return An initialised solver, or null if the puzzle's type is unknown |
39 | * to the factory. |
40 | */ |
41 | public static Solver newInstance(Puzzle puzzle) { |
42 | Solver solver = null; |
43 | |
44 | switch (puzzle.getType()) { |
45 | case TINY: |
46 | solver = new TinySolver(puzzle); |
47 | break; |
48 | case MINI: |
49 | solver = new MiniSolver(puzzle); |
50 | break; |
51 | case MINI_X: |
52 | solver = new MiniXSolver(puzzle); |
53 | break; |
54 | case SMALL_X: |
55 | solver = new SmallXSolver(puzzle); |
56 | break; |
57 | case STANDARD: |
58 | solver = new StandardSolver(puzzle); |
59 | break; |
60 | case SUPER: |
61 | solver = new SuperSolver(puzzle); |
62 | break; |
63 | case LARGE: |
64 | solver = new LargeSolver(puzzle); |
65 | break; |
66 | case STANDARD_SAMURAI: |
67 | solver = new SamuraiSolver(puzzle); |
68 | break; |
69 | default: |
70 | // return null |
71 | break; |
72 | } |
73 | |
74 | return solver; |
75 | } |
76 | |
77 | } |