001 // This file is part of AceWiki. 002 // Copyright 2008-2012, AceWiki developers. 003 // 004 // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU 005 // Lesser General Public License as published by the Free Software Foundation, either version 3 of 006 // the License, or (at your option) any later version. 007 // 008 // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 010 // Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If 013 // not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.base; 016 017 import java.util.HashSet; 018 import java.util.Set; 019 020 /** 021 * This is a simple implementation of NextTokenOptions. 022 * 023 * @author Tobias Kuhn 024 */ 025 public class SimpleNextTokenOptions implements NextTokenOptions { 026 027 private Set<ConcreteOption> cOptions = new HashSet<ConcreteOption>(); 028 private Set<AbstractOption> aOptions = new HashSet<AbstractOption>(); 029 private Set<String> tokens = new HashSet<String>(); 030 private Set<String> categories = new HashSet<String>(); 031 032 /** 033 * Creates a new object for the given concrete and abstract options. 034 * 035 * @param cOptions The concrete options. 036 * @param aOptions The abstract options. 037 */ 038 public SimpleNextTokenOptions(Set<ConcreteOption> cOptions, Set<AbstractOption> aOptions) { 039 if (cOptions != null) { 040 this.cOptions = cOptions; 041 for (ConcreteOption o : cOptions) { 042 tokens.add(o.getWord()); 043 } 044 } 045 if (aOptions != null) { 046 this.aOptions = aOptions; 047 for (AbstractOption o : aOptions) { 048 categories.add(o.getCategoryName()); 049 } 050 } 051 } 052 053 /** 054 * Creates a new object for the given concrete, without any abstract options. 055 * 056 * @param cOptions The concrete options. 057 */ 058 public SimpleNextTokenOptions(Set<ConcreteOption> cOptions) { 059 this(cOptions, null); 060 } 061 062 public Set<AbstractOption> getAbstractOptions() { 063 return aOptions; 064 } 065 066 public Set<ConcreteOption> getConcreteOptions() { 067 return cOptions; 068 } 069 070 public boolean containsToken(String token) { 071 return tokens.contains(token); 072 } 073 074 public boolean containsCategory(String categoryName) { 075 return categories.contains(categoryName); 076 } 077 078 }