net.kolls.railworld.car
Class AbstractCar

java.lang.Object
  extended by net.kolls.railworld.car.AbstractCar
All Implemented Interfaces:
Car, SaveLoad
Direct Known Subclasses:
Autorack, Boxcar, Caboose, Coveredhopper, Engine, Flatcar, Intermodal, Openhopper, Passenger, Stockcar, Tankcar

public abstract class AbstractCar
extends java.lang.Object
implements Car

AbstractCar contains some reasonable defaults to avoid repetition in creating standard cargo car types.

Author:
Steve Kollmansberger

Field Summary
protected  boolean isLoaded
          Indicates if the Car is currently loaded (with cargo) or not.
 
Fields inherited from interface net.kolls.railworld.Car
CAR_WIDTH, DIST_BETWEEN_CARS
 
Constructor Summary
AbstractCar()
          Constructs a new Car.
 
Method Summary
 boolean canUserCreate()
          Indicates if this car should appear in any user creation selection window.
 boolean equals(java.lang.Object o)
           
 boolean isEngine()
          Indicates if this car provides power.
 boolean isLoadable()
          Determine if the current Car can be loaded and unloaded; that is, does it carry cargo.
 void load()
          Loads the current Car.
 void load(java.util.Map<java.lang.String,java.lang.String> m)
          Default implementation only loads whether or not the car is loaded.
 boolean loaded()
          Indicates if the Car is currently loaded.
 java.awt.Color midColor()
          By default, if the car is not loaded, or not loadable, show a solid car.
 java.lang.Object newInstance()
          like getClass().newInstance().
 java.util.Map<java.lang.String,java.lang.String> save()
          Default implementation saves only whether or not the car is loaded.
 java.util.Set<RailSegment> segs()
          For the current Car, returns the segments that the Car occupies, if any.
 java.lang.String toString()
           
 void unload()
          Unloads the current Car.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.kolls.railworld.Car
color, length, show, weight
 

Field Detail

isLoaded

protected boolean isLoaded
Indicates if the Car is currently loaded (with cargo) or not. Should be false if the Car is not loadable.

Constructor Detail

AbstractCar

public AbstractCar()
Constructs a new Car. Parameters of a Car are set using inheritance.

Method Detail

loaded

public boolean loaded()
Description copied from interface: Car
Indicates if the Car is currently loaded.

Specified by:
loaded in interface Car
Returns:
true if the car is loadable and is currently loaded.

load

public void load()
Description copied from interface: Car
Loads the current Car. Do not call on a Car you have specified as not loadable.

Specified by:
load in interface Car

unload

public void unload()
Description copied from interface: Car
Unloads the current Car. Do not call on a Car you have specified as not loadable.

Specified by:
unload in interface Car

isLoadable

public boolean isLoadable()
Description copied from interface: Car
Determine if the current Car can be loaded and unloaded; that is, does it carry cargo.

Specified by:
isLoadable in interface Car
Returns:
true if the Car may be loaded and unloaded. Defaults to true.

segs

public final java.util.Set<RailSegment> segs()
Description copied from interface: Car
For the current Car, returns the segments that the Car occupies, if any. This should be considered read-only.

Specified by:
segs in interface Car
Returns:
Set of RailSegments.

equals

public final boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

midColor

public java.awt.Color midColor()
By default, if the car is not loaded, or not loadable, show a solid car. Otherwise, show a white mid line.

Specified by:
midColor in interface Car
Returns:
The Color of the middle line in the car

toString

public java.lang.String toString()
Specified by:
toString in interface SaveLoad
Overrides:
toString in class java.lang.Object
Returns:
Give the name of this type so it can be reconstructed by the factory.

save

public java.util.Map<java.lang.String,java.lang.String> save()
Default implementation saves only whether or not the car is loaded.

Specified by:
save in interface SaveLoad
Returns:
A list of key-value pairs to be saved.

load

public void load(java.util.Map<java.lang.String,java.lang.String> m)
Default implementation only loads whether or not the car is loaded.

Specified by:
load in interface SaveLoad
Parameters:
m - Key value pairs saved by an instance of this class

canUserCreate

public boolean canUserCreate()
Description copied from interface: Car
Indicates if this car should appear in any user creation selection window.

Specified by:
canUserCreate in interface Car
Returns:
true if the car is user creatable

newInstance

public java.lang.Object newInstance()
Description copied from interface: SaveLoad
like getClass().newInstance(). Allows script objects to also be copied.

Specified by:
newInstance in interface SaveLoad
Returns:
A new instance of this class

isEngine

public boolean isEngine()
Description copied from interface: Car
Indicates if this car provides power.

Specified by:
isEngine in interface Car
Returns:
true if the car provides power (is a working engine)