net.sourceforge.worldsaver.rp
Class RpBase

java.lang.Object
  |
  +--net.sourceforge.worldsaver.rp.RpBase
All Implemented Interfaces:
MiscUtils, Saveable
Direct Known Subclasses:
Action, Area, Armor, Item, Person

public abstract class RpBase
extends java.lang.Object
implements MiscUtils, Saveable

Almost everything in this package extends this superclass.

Version:
Feb 17 2001
Author:
Andreas Schmitz

Fields inherited from interface net.sourceforge.worldsaver.util.MiscUtils
CONSOLE_WIDTH, NEWLINE, RANDOM
 
Constructor Summary
RpBase(java.util.HashMap loaded)
          Reconstructs the object by a loaded String.
RpBase(RpBase father, java.lang.String name)
          Constructs a new object with a given name and a given father.
 
Method Summary
 void addChild(RpBase val)
          Adds the given object to the childs.
 void addDescription(java.lang.String val)
          Appends the given String to the descrption of this object.
abstract  RpBase copy(boolean childs, boolean full)
          Returns a new object with the same values as this object.
 java.util.Iterator getChilds()
          Returns an iterator with the childs of this object.
 java.lang.String getDescription(boolean returnChilds, boolean full)
          Returns the description of this object.
 RpBase getFather()
          Returns the father of this object.
 long getID()
          Returns the unique ID of this instance.
 java.lang.String getName()
          Returns the name of the object.
 void getReferencesRight(java.util.HashMap pool, IDGenerator gen)
          Gets the references right by getting them out of the pool.
 java.lang.String getSaveableString()
          Returns the String describing this object.
 void setDescription(java.lang.String val)
          Sets the description of the object.
 void setFather(RpBase val)
          Uses the given value as new father.
 void setName(java.lang.String val)
          Changes the name of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RpBase

public RpBase(RpBase father,
              java.lang.String name)
Constructs a new object with a given name and a given father.
Parameters:
father - the father object, may be null
name - the name

RpBase

public RpBase(java.util.HashMap loaded)
Reconstructs the object by a loaded String. Caution: the references are not set right by this method! You have to call the getReferencesRight() method after reconstructing all the objects (or better use the Loader class in this package). You must also know which IDs are already used, create a new IDGenerator with this information and use it as parameter for every object you have loaded.
Parameters:
loaded - the String which contains all the information
gen - the IDGenerator that is already initialized with the used values
Method Detail

getReferencesRight

public void getReferencesRight(java.util.HashMap pool,
                               IDGenerator gen)
Gets the references right by getting them out of the pool. This method has to be called after loading the whole thing.
Specified by:
getReferencesRight in interface Saveable
Parameters:
pool - the HashMap with all objects of the current session

getID

public long getID()
Returns the unique ID of this instance.
Returns:
the ID

getName

public java.lang.String getName()
Returns the name of the object.
Returns:
the name

getDescription

public java.lang.String getDescription(boolean returnChilds,
                                       boolean full)
Returns the description of this object. You can choose whether the child descriptions should be returned as well. You can also choose whether the complete child description (including their childs etc) should be returned, too.
Parameters:
returnChilds - true means to return the child descriptions, too.
full - true means return also the child's description etc.
Returns:
the description as String

getChilds

public java.util.Iterator getChilds()
Returns an iterator with the childs of this object.
Returns:
the iterator

getFather

public RpBase getFather()
Returns the father of this object.
Returns:
the father

setName

public void setName(java.lang.String val)
Changes the name of this object.
Parameters:
val - the new name

setDescription

public void setDescription(java.lang.String val)
Sets the description of the object.
Parameters:
val - the description

addDescription

public void addDescription(java.lang.String val)
Appends the given String to the descrption of this object.
Parameters:
val - the String to append

addChild

public void addChild(RpBase val)
Adds the given object to the childs.
Parameters:
val - the object to add

setFather

public void setFather(RpBase val)
Uses the given value as new father.
Parameters:
val - the new father

getSaveableString

public java.lang.String getSaveableString()
                                   throws java.io.IOException
Returns the String describing this object. The String which is actually returned by some non-abstract subclass of this class is ready to save.
Specified by:
getSaveableString in interface Saveable
Returns:
the ready-to-save String describing the object
Throws:
java.io.IOException - if the objects are not valid

copy

public abstract RpBase copy(boolean childs,
                            boolean full)
Returns a new object with the same values as this object. This method copies the fields of the object and all childs, but not the father. Also, every object is created new and a new IDGenerator is created (there are also made new IDs for every object). Note that only every non-abstract subclass should write this method. Like the getDescription method, you can choose whether and how the childs are treated.
Parameters:
childs - true means copy the childs, too
full - true means copy the childs of the childs etc., too
Returns:
the new object (the father of all childs)