Clover coverage report -
Coverage timestamp: Sun Oct 12 2003 22:54:40 PDT
file stats: LOC: 396   Methods: 23
NCLOC: 160   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
VisibleObject.java 50% 56.2% 26.1% 48.4%
coverage coverage
 1   
 /*
 2   
 
 3   
 VRMoo Common - Virtual Reality Object Oriented MUD Common Code
 4   
 Copyright (C) 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.common.data;
 28   
 
 29   
 import org.vrmoo.common.exception.VRMooParseException;
 30   
 import org.vrmoo.common.util.ParserUtility;
 31   
 
 32   
 /**
 33   
  * Stores the information for an object that is visible within the virtual
 34   
  * world.
 35   
  *
 36   
  * @author Jeff Weston
 37   
  */
 38   
 public class VisibleObject extends BrokerableObject
 39   
 {
 40   
     /**
 41   
      * The name of the <code>ObjectData</code> for this visible object.
 42   
      */
 43   
     private String objectDataName;
 44   
 
 45   
     /**
 46   
      * The name of the vrmoopl program attached to this object.
 47   
      */
 48   
     private String programName;
 49   
 
 50   
     /**
 51   
      * The angle of rotation around the X axis for this visible object.
 52   
      */
 53   
     private float rotationX;
 54   
 
 55   
     /**
 56   
      * The angle of rotation around the Y axis for this visible object.
 57   
      */
 58   
     private float rotationY;
 59   
 
 60   
     /**
 61   
      * The angle of rotation around the Z axis for this visible object.
 62   
      */
 63   
     private float rotationZ;
 64   
 
 65   
     /**
 66   
      * The X component of the location of this visible object.
 67   
      */
 68   
     private float locationX;
 69   
 
 70   
     /**
 71   
      * The Y component of the location of this visible object.
 72   
      */
 73   
     private float locationY;
 74   
 
 75   
     /**
 76   
      * The Z component of the location of this visible object.
 77   
      */
 78   
     private float locationZ;
 79   
 
 80   
     /**
 81   
      * The unique identifier of this visible object.
 82   
      */
 83   
     private int id;
 84   
 
 85   
     /**
 86   
      * Construct this object using the given <code>ObjectData<code> name,
 87   
      * <code>Program</code> name, rotation angles, and location values.
 88   
      *
 89   
      * @param objectDataName  the name of the <code>ObjectData</code>
 90   
      * @param programName     the name of the <code>Program</code>
 91   
      * @param rotationX       the angle of rotation around the X axis
 92   
      * @param rotationY       the angle of rotation around the Y axis
 93   
      * @param rotationZ       the angle of rotation around the Z axis
 94   
      * @param locationX       the X component of the location
 95   
      * @param locationY       the Y component of the location
 96   
      * @param locationZ       the Z component of the location
 97   
      */
 98  9
     public VisibleObject( String objectDataName, String programName,
 99   
             float rotationX, float rotationY, float rotationZ,
 100   
             float locationX, float locationY, float locationZ )
 101   
     {
 102  9
         this.objectDataName = objectDataName;
 103  9
         this.programName    = programName;
 104   
 
 105  9
         this.rotationX = rotationX;
 106  9
         this.rotationY = rotationY;
 107  9
         this.rotationZ = rotationZ;
 108   
 
 109  9
         this.locationX = locationX;
 110  9
         this.locationY = locationY;
 111  9
         this.locationZ = locationZ;
 112   
 
 113  9
         id = 0;
 114   
     }
 115   
 
 116   
     /**
 117   
      * Construct an instance of this class using text representing encoded
 118   
      * visible object data.
 119   
      *
 120   
      * @param data                     the encoded visible object data
 121   
      *
 122   
      * @exception VRMooParseException  Description of the Exception
 123   
      *
 124   
      * @throws VRMooParseException     for any parsing errors that occur
 125   
      */
 126  1
     public VisibleObject( String data ) throws VRMooParseException
 127   
     {
 128  1
         int nameStart = data.indexOf( "\"" );
 129  1
         int nameEnd = data.indexOf( "\"", nameStart + 1 );
 130   
 
 131  1
         if ( ( nameStart != -1 ) &&
 132   
                 ( nameEnd != -1 ) )
 133   
         {
 134  1
             String name = data.substring( nameStart + 1, nameEnd );
 135  1
             id = ParserUtility.parseInt( name );
 136   
         }
 137   
         else
 138   
         {
 139  0
             throw new VRMooParseException(
 140   
                     "Unable to parse visible object ID." );
 141   
         }
 142   
 
 143  1
         int start = data.indexOf( "(" );
 144  1
         int end = data.indexOf( ")", start );
 145   
 
 146  1
         if ( ( start != -1 ) &&
 147   
                 ( end != -1 ) )
 148   
         {
 149  1
             String visibleObject = data.substring( start + 1, end );
 150   
 
 151  1
             int objectDataNameEnd = visibleObject.indexOf( "," );
 152  1
             objectDataName =
 153   
                     visibleObject.substring( 0, objectDataNameEnd ).trim( );
 154   
 
 155  1
             int programNameEnd =
 156   
                     visibleObject.indexOf( ",", objectDataNameEnd + 1 );
 157  1
             programName = visibleObject.substring( objectDataNameEnd + 1,
 158   
                                                    programNameEnd ).trim( );
 159   
 
 160  1
             String values =
 161   
                     visibleObject.substring( programNameEnd + 1 ).trim( );
 162  1
             float f[ ] = ParserUtility.parseFloatArray( values, 6 );
 163   
 
 164  1
             rotationX = f[ 0 ];
 165  1
             rotationY = f[ 1 ];
 166  1
             rotationZ = f[ 2 ];
 167   
 
 168  1
             locationX = f[ 3 ];
 169  1
             locationY = f[ 4 ];
 170  1
             locationZ = f[ 5 ];
 171   
         }
 172   
         else
 173   
         {
 174  0
             throw new VRMooParseException(
 175   
                     "Unable to parse visible object data." );
 176   
         }
 177   
     }
 178   
 
 179   
     /**
 180   
      * Get a copy of this <code>VisibleObject</code>. This object can be
 181   
      * manipulated without affecting the object broker.
 182   
      *
 183   
      * @return   a copy of the visible object that can be manipulated
 184   
      *             independently
 185   
      */
 186  0
     public VisibleObject cloneVisibleObject( )
 187   
     {
 188  0
         VisibleObject object = new VisibleObject(
 189   
                 getObjectDataName( ), getProgramName( ),
 190   
                 getRotationX( ), getRotationY( ), getRotationZ( ),
 191   
                 getLocationX( ), getLocationY( ), getLocationZ( ) );
 192  0
         object.setID( getID( ) );
 193  0
         return object;
 194   
     }
 195   
 
 196   
     /**
 197   
      * Getter for the name of the <code>ObjectData</code> for this class.
 198   
      *
 199   
      * @return   the name of the <code>ObjectData</code> for this class
 200   
      */
 201  0
     public String getObjectDataName() {
 202  0
         return objectDataName;
 203   
     }
 204   
 
 205   
     /**
 206   
      * Getter for the name of the <code>Program</code> for this class.
 207   
      *
 208   
      * @return   the name of the <code>Program</code> for this class
 209   
      */
 210  0
     public String getProgramName() {
 211  0
         return programName;
 212   
     }
 213   
 
 214   
     /**
 215   
      * Getter for the angle of rotation around the X axis for this class.
 216   
      *
 217   
      * @return   the angle of rotation around the X axis for this class
 218   
      */
 219  0
     public float getRotationX() {
 220  0
         return rotationX;
 221   
     }
 222   
 
 223   
     /**
 224   
      * Getter for the angle of rotation around the Y axis for this class.
 225   
      *
 226   
      * @return   the angle of rotation around the Y axis for this class
 227   
      */
 228  0
     public float getRotationY() {
 229  0
         return rotationY;
 230   
     }
 231   
 
 232   
     /**
 233   
      * Getter for the angle of rotation around the Z axis for this class.
 234   
      *
 235   
      * @return   the angle of rotation around the Z axis for this class
 236   
      */
 237  0
     public float getRotationZ() {
 238  0
         return rotationZ;
 239   
     }
 240   
 
 241   
     /**
 242   
      * Getter for the X component of the location for this class.
 243   
      *
 244   
      * @return   the X component of the location for this class
 245   
      */
 246  0
     public float getLocationX() {
 247  0
         return locationX;
 248   
     }
 249   
 
 250   
     /**
 251   
      * Getter for the Y component of the location for this class.
 252   
      *
 253   
      * @return   the Y component of the location for this class
 254   
      */
 255  0
     public float getLocationY() {
 256  0
         return locationY;
 257   
     }
 258   
 
 259   
     /**
 260   
      * Getter for the Z component of the location for this class.
 261   
      *
 262   
      * @return   the Z component of the location for this class
 263   
      */
 264  0
     public float getLocationZ() {
 265  0
         return locationZ;
 266   
     }
 267   
 
 268   
     /**
 269   
      * Setter for the name of the <code>ObjectData</code> for this class.
 270   
      *
 271   
      * @param objectDataName  the name of the <code>ObjectData</code> for this
 272   
      *      class
 273   
      */
 274  2
     public void setObjectDataName( String objectDataName ) {
 275  2
         this.objectDataName = objectDataName;
 276  2
         fireBrokerableObjectChanged();
 277   
     }
 278   
 
 279   
     /**
 280   
      * Setter for the name of the <code>Program</code> for this class.
 281   
      *
 282   
      * @param programName  the name of the <code>Program</code> for this class
 283   
      */
 284  0
     public void setProgramName( String programName ) {
 285  0
         this.programName = programName;
 286  0
         fireBrokerableObjectChanged();
 287   
     }
 288   
 
 289   
     /**
 290   
      * Setter for the angle of rotation around the X axis for this class.
 291   
      *
 292   
      * @param rotationX  the angle of rotation around the X axis for this class
 293   
      */
 294  0
     public void setRotationX( float rotationX ) {
 295  0
         this.rotationX = rotationX;
 296  0
         fireBrokerableObjectChanged();
 297   
     }
 298   
 
 299   
     /**
 300   
      * Setter for the angle of rotation around the Y axis for this class.
 301   
      *
 302   
      * @param rotationY  the angle of rotation around the Y axis for this class
 303   
      */
 304  0
     public void setRotationY( float rotationY ) {
 305  0
         this.rotationY = rotationY;
 306  0
         fireBrokerableObjectChanged();
 307   
     }
 308   
 
 309   
     /**
 310   
      * Setter for the angle of rotation around the Z axis for this class.
 311   
      *
 312   
      * @param rotationZ  the angle of rotation around the Z axis for this class
 313   
      */
 314  0
     public void setRotationZ( float rotationZ ) {
 315  0
         this.rotationZ = rotationZ;
 316  0
         fireBrokerableObjectChanged();
 317   
     }
 318   
 
 319   
     /**
 320   
      * Setter for the X component of the location for this class.
 321   
      *
 322   
      * @param locationX  the X component of the location for this class
 323   
      */
 324  0
     public void setLocationX( float locationX ) {
 325  0
         this.locationX = locationX;
 326  0
         fireBrokerableObjectChanged();
 327   
     }
 328   
 
 329   
     /**
 330   
      * Setter for the Y component of the location for this class.
 331   
      *
 332   
      * @param locationY  the Y component of the location for this class
 333   
      */
 334  0
     public void setLocationY( float locationY ) {
 335  0
         this.locationY = locationY;
 336  0
         fireBrokerableObjectChanged();
 337   
     }
 338   
 
 339   
     /**
 340   
      * Setter for the Z component of the location for this class.
 341   
      *
 342   
      * @param locationZ  the Z component of the location for this class
 343   
      */
 344  0
     public void setLocationZ( float locationZ ) {
 345  0
         this.locationZ = locationZ;
 346  0
         fireBrokerableObjectChanged();
 347   
     }
 348   
 
 349   
     /**
 350   
      * Set the unique identifier of this visible object.
 351   
      *
 352   
      * @param id  the unique identifier for this visible object
 353   
      */
 354  8
     public void setID( int id ) {
 355  8
         if ( this.id == 0 ) {
 356  8
             this.id = id;
 357   
         }
 358   
     }
 359   
 
 360   
     /**
 361   
      * Get the integer ID for this visible object
 362   
      *
 363   
      * @return   the unique identifier for this visible object
 364   
      */
 365  0
     public int getID() {
 366  0
         return id;
 367   
     }
 368   
 
 369   
     /**
 370   
      * Get the name for this visible object.
 371   
      *
 372   
      * @return   the name for this visible object
 373   
      */
 374  31
     public String getName() {
 375  31
         return "" + id;
 376   
     }
 377   
 
 378   
     /**
 379   
      * Convert this visible object to its encoded <code>String</code>
 380   
      * representation.
 381   
      *
 382   
      * @return   the encoded <code>String</code>
 383   
      */
 384  9
     public String toEncodedString() {
 385  9
         return "\"" + id + "\", " + "( " +
 386   
                 objectDataName + ", " +
 387   
                 programName + ", " +
 388   
                 rotationX + ", " +
 389   
                 rotationY + ", " +
 390   
                 rotationZ + ", " +
 391   
                 locationX + ", " +
 392   
                 locationY + ", " +
 393   
                 locationZ + " )";
 394   
     }
 395   
 }
 396