[LIB-9] Add original chesshog source files
[chesshog.git] / src / main / java / org / hedgecode / chess / position / Positions.java
1 /*
2  * Copyright (c) 2018. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.chess.position;
18
19 /**
20  *
21  *
22  * @author Dmitry Samoshin aka gotty
23  */
24 public enum Positions {
25
26     INITIAL {
27         @Override
28         public Position getPosition() {
29             Position position = FACTORY.create();
30             position.initial();
31             return position;
32         }
33     },
34
35     EMPTY {
36         @Override
37         public Position getPosition() {
38             Position position = FACTORY.create();
39             position.clear();
40             return position;
41         }
42     };
43
44     public abstract Position getPosition();
45
46     static class Factory {
47
48         private Factory() {
49         }
50
51         Position create() {
52             return create(
53                     PositionType.GAME
54             );
55         }
56
57         Position create(PositionType type) {
58             Position position;
59             switch (type) {
60                 case DIAGRAM:
61                     position = new DiagramPosition();
62                     break;
63                 case GAME:
64                 default:
65                     position = new GamePosition();
66             }
67             return position;
68         }
69
70     }
71
72     private static final Factory FACTORY = new Factory();
73
74 }