Clover coverage report -
Coverage timestamp: Sun Oct 12 2003 22:57:21 PDT
file stats: LOC: 110   Methods: 1
NCLOC: 42   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InstructionFactory.java 100% 100% 100% 100%
coverage
 1   
 /*
 2   
 
 3   
 VRMoo Server - Virtual Reality Object Oriented MUD Server
 4   
 Copyright (C) 2001 - 2003  VRMoo Development Team
 5   
 
 6   
 
 7   
 This program is free software; you can redistribute it and/or modify
 8   
 it under the terms of the GNU General Public License as published by
 9   
 the Free Software Foundation; either version 2 of the License, or
 10   
 (at your option) any later version.
 11   
 
 12   
 This program is distributed in the hope that it will be useful,
 13   
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 14   
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15   
 GNU General Public License for more details.
 16   
 
 17   
 You should have received a copy of the GNU General Public License
 18   
 along with this program; if not, write to the Free Software
 19   
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 20   
 
 21   
 
 22   
 For information about VRMoo and its authors, please visit the website:
 23   
 http://www.vrmoo.org/
 24   
 
 25   
 */
 26   
 
 27   
 package org.vrmoo.server.vrmoopl;
 28   
 
 29   
 import org.vrmoo.common.exception.VRMooParseException;
 30   
 
 31   
 /**
 32   
  * Factory class for creating an <code>Instruction</code> based upon a passed in
 33   
  * string representing the instruction.
 34   
  *
 35   
  * @author Jeff Weston
 36   
  */
 37   
 public class InstructionFactory
 38   
 {
 39   
     /**
 40   
      * Text representing the rotx instruction.
 41   
      */
 42   
     private static final String INSTRUCTION_ROTX = "rotx ";
 43   
 
 44   
     /**
 45   
      * Text representing the roty instruction.
 46   
      */
 47   
     private static final String INSTRUCTION_ROTY = "roty ";
 48   
 
 49   
     /**
 50   
      * Text representing the rotz instruction.
 51   
      */
 52   
     private static final String INSTRUCTION_ROTZ = "rotz ";
 53   
 
 54   
     /**
 55   
      * Text representing the timer instruction.
 56   
      */
 57   
     private static final String INSTRUCTION_TIMER = "timer ";
 58   
 
 59   
     ///CLOVER:OFF
 60   
     /**
 61   
      * This class is not meant to be instantiated, so make the constructor
 62   
      * private.
 63   
      */
 64   
     private InstructionFactory( )
 65   
     {
 66   
     }
 67   
     ///CLOVER:ON
 68   
 
 69   
     /**
 70   
      * Construct an appropriate instruction based upon the passed in text.
 71   
      *
 72   
      * @param text   the text with which to construct an instruction from
 73   
      *
 74   
      * @return the constructed instruction
 75   
      *
 76   
      * @throws VRMooParseException   for any parsing errors that occur
 77   
      */
 78  6
     public static Instruction createInstruction( String text )
 79   
             throws VRMooParseException
 80   
     {
 81  6
         text = text.trim( );
 82   
 
 83  6
         if ( text.indexOf( INSTRUCTION_ROTX ) == 0 )
 84   
         {
 85  1
             return new RotxInstruction(
 86   
                     text.substring( INSTRUCTION_ROTX.length( ) ).trim( ) );
 87   
         }
 88  5
         else if ( text.indexOf( INSTRUCTION_ROTY ) == 0 )
 89   
         {
 90  1
             return new RotyInstruction(
 91   
                     text.substring( INSTRUCTION_ROTY.length( ) ).trim( ) );
 92   
         }
 93  4
         else if ( text.indexOf( INSTRUCTION_ROTZ ) == 0 )
 94   
         {
 95  1
             return new RotzInstruction(
 96   
                     text.substring( INSTRUCTION_ROTZ.length( ) ).trim( ) );
 97   
         }
 98  3
         else if ( text.indexOf( INSTRUCTION_TIMER ) == 0 )
 99   
         {
 100  2
             return new TimerInstruction(
 101   
                     text.substring( INSTRUCTION_TIMER.length( ) ).trim( ) );
 102   
         }
 103   
         else
 104   
         {
 105  1
             throw new VRMooParseException(
 106   
                     "Unrecognized instruction: " + text );
 107   
         }
 108   
     }
 109   
 }
 110