2 * Copyright (c) 2018-2019. Developed by Hedgecode.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.hedgecode.chess.qrcode;
19 import org.hedgecode.chess.Parsers;
20 import org.hedgecode.chess.game.Game;
21 import org.hedgecode.chess.position.ParseException;
22 import org.hedgecode.chess.position.Parser;
23 import org.hedgecode.chess.position.Position;
26 * Result storage for Chess-specific QR Codes data.
28 * @author Dmitry Samoshin aka gotty
30 public class ChessQRResult {
32 private ChessQRCodeMode mode;
33 private String contents;
34 private Position position;
37 ChessQRResult(ChessQRCodeMode mode, String contents) {
39 this.contents = contents;
42 ChessQRResult(Position position) {
43 this.position = position;
46 ChessQRResult(Game game) {
50 public ChessQRCodeMode getMode() {
54 public String getContents() {
58 public Position getPosition() throws ChessQRCodeException {
59 if (position == null) {
60 if (mode != null && mode.isPosition()) {
62 position = getPositionParser().parse(contents);
63 } catch (ParseException e) {
64 throw new ChessQRCodeException(
65 ChessQRCodeException.Type.PARSE, null, e.getMessage()
73 public Game getGame() {
78 private Parser getPositionParser() throws ChessQRCodeException {
81 return Parsers.FEN.parser();
83 return Parsers.TCD.parser();
85 throw new ChessQRCodeException(
86 ChessQRCodeException.Type.PARSE, "parse.unknown.position.format"