001/**
002 * This class is part of the "Pere-noel" application. 
003 * "Pere Noel" is a very simple, text based adventure game.
004 *
005 * This class holds information about a command that was issued by the user.
006 * A command currently consists of two strings: a command word and a second
007 * word (for example, if the command was "take map", then the two strings
008 * obviously are "take" and "map").
009 * 
010 * The way this is used is: Commands are already checked for being valid
011 * command words. If the user entered an invalid command (a word that is not
012 * known) then the command word is <null>.
013 *
014 * If the command had only one word, then the second word is <null>.
015 * 
016 * @author  Célia PRIOL & Benoît CHAUVEAU
017 */
018
019public class Command
020{
021    private CommandWord commandWord;
022    private String secondWord;
023
024    /**
025     * Create a command object. First and second word must be supplied, but
026     * either one (or both) can be null.
027     * @param firstWord The first word of the command. Null if the command
028     *                  was not recognised.
029     * @param secondWord The second word of the command.
030     */
031    public Command(CommandWord firstWord, String secondWord)
032    {
033        commandWord = firstWord;
034        this.secondWord = secondWord;
035    }
036
037    /**
038     * Return the command word (the first word) of this command. If the
039     * command was not understood, the result is null.
040     * @return The command word.
041     */
042    public CommandWord getCommandWord()
043    {
044        return commandWord;
045    }
046
047    /**
048     * See "Returns" comment.
049     * @return The second word of this command. Returns null if there was no
050     * second word.
051     */
052    public String getSecondWord()
053    {
054        return secondWord;
055    }
056
057    /**
058     * See "Returns" comment.
059     * @return true if this command was not understood.
060     */
061    public boolean isUnknown()
062    {
063        return (commandWord == CommandWord.UNKNOWN);
064    }
065
066    /**
067     * See "Returns" comment.
068     * @return true if the command has a second word.
069     */
070    public boolean hasSecondWord()
071    {
072        return (secondWord != null);
073    }
074}