//This file is part of SECONDO. //Copyright (C) 2004, University in Hagen, Department of Computer Science, //Database Systems for New Applications. //SECONDO is free software; you can redistribute it and/or modify //it under the terms of the GNU General Public License as published by //the Free Software Foundation; either version 2 of the License, or //(at your option) any later version. //SECONDO is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU General Public License for more details. //You should have received a copy of the GNU General Public License //along with SECONDO; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package viewer.chess; import sj.lang.*; import java.util.*; /** * this class provides method to check is a ListExpr contains a chessgame or a chessgame within a relation. Furthermore methods which parse a chessgame to a GameData object are provided */ public class ChessListParser { /** method to check whether the ListExpr contains an attribute of type chessgame or is of type chessgame */ public boolean containsChessGame(ListExpr list) { return (isChessRelation(list) || isChessGame(list)); } /** method to check whether the ListExpr is a relation which contains a chessgame */ public boolean isChessRelation(ListExpr list) { ListExpr attributeTypes, values; if (isRelation(list)) //check if list is a relation { attributeTypes = list.first().second().second(); // if list is relation the attribute types are this values = list.second(); // extract the values from the relation if (containsChessAttribute(attributeTypes, values)) return true; } return false; } /** method to check whether the ListExpr is a relation**/ private boolean isRelation(ListExpr list) { if (list.listLength()!=2) return false; ListExpr type = list.first(); if (type.isAtom()) return false; ListExpr mainType = type.first(); if(type.listLength()!=2 || !mainType.isAtom() || mainType.atomType()!= ListExpr.SYMBOL_ATOM || !(mainType.symbolValue().equals(ChessToolKit.RELATION_TYPE_STRING))) return false; ListExpr tupletype = type.second(); ListExpr tupleAtom = tupletype.first(); if(tupletype.listLength()!=2 || !tupleAtom.isAtom() || tupleAtom.atomType() != ListExpr.SYMBOL_ATOM || !(tupleAtom.symbolValue().equals(ChessToolKit.TUPLE_TYPE_STRING))) return false; return true; } /** * checks whether the attribute types contain a type of chessgame */ private boolean containsChessAttribute(ListExpr attributeTypes, ListExpr values) { boolean valueExists = true; boolean chessFound = false; int position = 0; String[] types = new String[attributeTypes.listLength()]; ListExpr attributeType; while (!attributeTypes.isEmpty()&&valueExists&&position