[LIB-13] Add PGN entities
[chesshog-scanner.git] / src / main / java / org / hedgecode / chess / scanner / entity / PGNTournament.java
1 /*
2  * Copyright (c) 2019-2020. 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.scanner.entity;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22
23 import org.hedgecode.chess.scanner.ChessHogScannerConstants;
24
25 /**
26  * PGNTournament
27  *
28  * @author Dmitry Samoshin aka gotty
29  */
30 public class PGNTournament implements PGNEntity {
31
32     private String tournamentId;
33     private String tournamentName;
34
35     private List<PGNGame> tournamentGames = new ArrayList<>();
36
37     public PGNTournament(String tournamentId) {
38         this.tournamentId = tournamentId;
39     }
40
41     public PGNTournament(String tournamentId, String tournamentName) {
42         this.tournamentId = tournamentId;
43         this.tournamentName = tournamentName;
44     }
45
46     public void addGame(PGNGame game) {
47         tournamentGames.add(game);
48     }
49
50     public void addGames(Collection<PGNGame> games) {
51         tournamentGames.addAll(games);
52     }
53
54     public void clearGames() {
55         tournamentGames.clear();
56     }
57
58     public List<PGNGame> games() {
59        return tournamentGames;
60     }
61
62     @Override
63     public String id() {
64         return tournamentId;
65     }
66
67     public String name() {
68         return tournamentName;
69     }
70
71     public void setName(String name) {
72         tournamentName = name;
73     }
74
75     @Override
76     public String pgn() {
77         StringBuilder sb = new StringBuilder();
78         for (PGNGame game : tournamentGames) {
79             sb.append(
80                     game.pgn()
81             ).append(
82                     ChessHogScannerConstants.CRLF
83             );
84         }
85         return sb.toString();
86     }
87
88 }