001/* Copyright (C) 2013 TU Dortmund
002 * This file is part of AutomataLib, http://www.automatalib.net/.
003 * 
004 * AutomataLib is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Lesser General Public
006 * License version 3.0 as published by the Free Software Foundation.
007 * 
008 * AutomataLib is distributed in the hope that it will be useful,
009 * but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011 * Lesser General Public License for more details.
012 * 
013 * You should have received a copy of the GNU Lesser General Public
014 * License along with AutomataLib; if not, see
015 * http://www.gnu.de/documents/lgpl.en.html.
016 */
017package net.automatalib.words;
018
019import java.util.Collection;
020import java.util.Comparator;
021
022import net.automatalib.commons.util.array.ArrayWritable;
023
024/**
025 * Class implementing an (indexed) alphabet. An alphabet is a collection of symbols, where
026 * each symbol has a (unique) index. Apart from serving as a collection, this class also provides
027 * a one-to-one mapping between symbols and indices.
028 * 
029 * @param <I> symbol class.
030 * 
031 * @author Malte Isberner <malte.isberner@gmail.com>
032 */
033public interface Alphabet<I> extends ArrayWritable<I>, Collection<I>, Comparator<I> {
034
035    /**
036     * Returns the symbol with the given index in this alphabet.
037     * @param index the index of the requested symbol.
038     * @return symbol with the given index. 
039     * @throws IllegalArgumentException if there is no symbol with this index.
040     */
041    public abstract I getSymbol(int index) throws IllegalArgumentException;
042    
043    /**
044     * Returns the index of the given symbol in the alphabet. 
045     * @param symbol
046     * @return
047     * @throws IllegalArgumentException if the provided symbol does not belong to the alphabet.
048     */
049    public abstract int getSymbolIndex(I symbol) throws IllegalArgumentException;
050}