Class BasicDrinkMachine

java.lang.Object
  extended byBasicDrinkMachine
All Implemented Interfaces:
DrinkMachineSpec
Direct Known Subclasses:
FakeDrinkMachine, LittleDrinkMachine, TINIDrinkMachine

public abstract class BasicDrinkMachine
extends Object
implements DrinkMachineSpec

A class to handle most of the basic, common functions and requirements of the DrinkMachineSpec classes.
This class mostly handles slot data management & printing, and config management.

The intended use for this class is as such:
A class that wishes to be a DrinkMachineSpec class extends this class and finishes implementing the DrinkMachineSpec interface.

Author:
Kevin Thompson [antiduh@csh.rit.edu]

Field Summary
protected  ConfigMgr configMgr
          The object to use to manipulate the config database.
protected  int numSlots
          The number of slots this machine contains.
protected  Slot[] slotArray
          The slot array that slot information is served out of.
protected  String slotDataFileName
          The name of the file that contains the binary-format slot data.
protected  SlotDataMgr slotMgr
          The SlotDataMgr that manages the slot data.
 
Constructor Summary
BasicDrinkMachine(ConfigMgr _configMgr)
          Initializes the class.
 
Method Summary
abstract  void addDrinkButtonListener(DrinkButtonListener dbl)
          Add a listener to the list of objects requesting callbacks from the buttons
abstract  void delDrinkButtonListener(DrinkButtonListener dbl)
          Removes a listener from the list of objects requesting callbacks from the buttons.
 int drinksDropped(int slot)
          Returns the number of drinks that have come out of a slot If the slot is invalid, zero is returned.
 int drinksLeft(int slot)
          Returns the number of drinks left in a slot.
abstract  String drop(int slot)
          Drops a drink on the specified slot index.
static String formatSlotLine(String slot, String drink, String price, String count, String served)
          Formats the given parameters into specific width columns.
 Vector getDrinkNames()
          Returns a Vector of String objects specifying the names of the slots.
 String getName(int slot)
          Returns the name of a the drink specified by the index.
 int getNumSlots()
          Returns the number of slots this machine has.
 int getPrice(int slot)
          Returns the price of a drink in credits (cents).
 Slot getSlot(int slot)
          Returns a Slot object containing the information for the given slot index.
 Slot[] getSlotArray()
          Returns an array of Slot objects containing the information for all of the slots.
 String getSlotPrintout()
          Generates a preformatted printout of all the slot information.
abstract  Float getTempKey(String key)
          Returns the temperature from the sensor with the given name (key).
 boolean isEnabled(int slot)
          Determines if a given slot is enabled or disabled.
abstract  void lightOff(int slot)
          Turns the (empty) light of for the specified slot.
abstract  void lightOn(int slot)
          Turns the (empty) light on for the specified slot.
 void setSlot(int slotIndex, Slot slot)
          Sets the information for a given slot index to the given Slot object
abstract  void shutdown(boolean reboot)
          Shuts down the server and the hardware it is running on.
abstract  Vector slotTemp(int slot)
          Returns a Vector of Float objects representing the temperatures of all the temperature sensors for the slot.
abstract  float slotTempAvg(int slot)
          Returns the average temperature of all the temperature sensors for the given slot.
abstract  long uptime()
          Returns the amount of time the system has been up for, in milliseconds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configMgr

protected ConfigMgr configMgr
The object to use to manipulate the config database.


slotDataFileName

protected String slotDataFileName
The name of the file that contains the binary-format slot data.


slotMgr

protected SlotDataMgr slotMgr
The SlotDataMgr that manages the slot data.


slotArray

protected Slot[] slotArray
The slot array that slot information is served out of.


numSlots

protected int numSlots
The number of slots this machine contains.

Constructor Detail

BasicDrinkMachine

public BasicDrinkMachine(ConfigMgr _configMgr)
Initializes the class. The params are saved to local variables, and the slot management class is initialized.

Parameters:
_configMgr - The object to use manipulate the config db.
Method Detail

getSlotArray

public Slot[] getSlotArray()
Returns an array of Slot objects containing the information for all of the slots.

Specified by:
getSlotArray in interface DrinkMachineSpec
Returns:
A Slot array.

getSlot

public Slot getSlot(int slot)
Returns a Slot object containing the information for the given slot index.

Specified by:
getSlot in interface DrinkMachineSpec
Parameters:
slot - The slot index to retrieve the information for.
Returns:
A slot object containing all the slot information.

getNumSlots

public int getNumSlots()
Returns the number of slots this machine has.

Specified by:
getNumSlots in interface DrinkMachineSpec

getDrinkNames

public Vector getDrinkNames()
Description copied from interface: DrinkMachineSpec
Returns a Vector of String objects specifying the names of the slots.

Specified by:
getDrinkNames in interface DrinkMachineSpec
Returns:
A vector of names of all the slots

getName

public String getName(int slot)
Returns the name of a the drink specified by the index.

Specified by:
getName in interface DrinkMachineSpec

getPrice

public int getPrice(int slot)
Returns the price of a drink in credits (cents). If the price of the slot cannot be found in the config, then 50 is returned.

Specified by:
getPrice in interface DrinkMachineSpec
Parameters:
slot - The index of the slot for which the price is desired.
Returns:
The price of the drink, or 50 if the price cannot be determined.

drinksLeft

public int drinksLeft(int slot)
Returns the number of drinks left in a slot. If the slot index is invalid, 0 is returned. The number of cans left is determined from the config object

Specified by:
drinksLeft in interface DrinkMachineSpec
Parameters:
slot - The slot to query.
Returns:
The number of cans left.

drinksDropped

public int drinksDropped(int slot)
Returns the number of drinks that have come out of a slot If the slot is invalid, zero is returned.

Specified by:
drinksDropped in interface DrinkMachineSpec
Parameters:
slot - The slot to query.
Returns:
The number of drinks dropped.

isEnabled

public boolean isEnabled(int slot)
Determines if a given slot is enabled or disabled.

Specified by:
isEnabled in interface DrinkMachineSpec
Parameters:
slot - The slot to check
Returns:
True if the slot is enabled, false otherwise.

setSlot

public void setSlot(int slotIndex,
                    Slot slot)
Sets the information for a given slot index to the given Slot object

Specified by:
setSlot in interface DrinkMachineSpec
Parameters:
slotIndex - The index of the slot to change
slot - The slot objec to associate with the index.

getSlotPrintout

public String getSlotPrintout()
Generates a preformatted printout of all the slot information. This printout would be suitable for display directly to command line for the user.

Specified by:
getSlotPrintout in interface DrinkMachineSpec
Returns:
A preformatted printout of the slot information.

formatSlotLine

public static String formatSlotLine(String slot,
                                    String drink,
                                    String price,
                                    String count,
                                    String served)
Formats the given parameters into specific width columns. This uses a fixed char array of spaces for adding padding. Most often used with getSlotPrintout.

Parameters:
slot - the slot number ( or the text to put in the slot column)
drink - The name of the drink
price - The price of the drink
count - The number of soda's left in the column
served - The number of drinks that have already been dropped
Returns:
The formatted string.

uptime

public abstract long uptime()
Returns the amount of time the system has been up for, in milliseconds

Specified by:
uptime in interface DrinkMachineSpec
Returns:
The system uptime.

getTempKey

public abstract Float getTempKey(String key)
Returns the temperature from the sensor with the given name (key).

Specified by:
getTempKey in interface DrinkMachineSpec
Parameters:
key - The name (not the address) of the temperature sensor
Returns:
A Float object representing the temperature of the slot, in celsius

slotTemp

public abstract Vector slotTemp(int slot)
Returns a Vector of Float objects representing the temperatures of all the temperature sensors for the slot. If there is no data, the vector will be empty.

Specified by:
slotTemp in interface DrinkMachineSpec
Parameters:
slot - The slot to retrieve the temperatures for.
Returns:
A Vector of Float objects of all the temperatures.

slotTempAvg

public abstract float slotTempAvg(int slot)
Returns the average temperature of all the temperature sensors for the given slot. Note that the result is a float primitive, not an object, and that if no data is available, the result is -2^7 - 1, (-127).

Specified by:
slotTempAvg in interface DrinkMachineSpec
Parameters:
slot - The slot to retrieve the average temperature for.
Returns:
The average temperature of the slot, or -127.

shutdown

public abstract void shutdown(boolean reboot)
Shuts down the server and the hardware it is running on. If reboot is true, then the hardware is rebooted instead of being shut down.

Specified by:
shutdown in interface DrinkMachineSpec
Parameters:
reboot - Whether or not to reboot the hardware.

drop

public abstract String drop(int slot)
Drops a drink on the specified slot index. If the method is successful, then the return is null. Otherwise, the return is the error message.

Specified by:
drop in interface DrinkMachineSpec
Parameters:
slot - The slot to drop.
Returns:
'null' if successful, or an error message.

lightOn

public abstract void lightOn(int slot)
Turns the (empty) light on for the specified slot.

Specified by:
lightOn in interface DrinkMachineSpec
Parameters:
slot - The slot whose light to activate
See Also:
(int)

lightOff

public abstract void lightOff(int slot)
Turns the (empty) light of for the specified slot.

Specified by:
lightOff in interface DrinkMachineSpec
Parameters:
slot - The slot whose light to deactivate.
See Also:
lightOn(int)

addDrinkButtonListener

public abstract void addDrinkButtonListener(DrinkButtonListener dbl)
Add a listener to the list of objects requesting callbacks from the buttons

Specified by:
addDrinkButtonListener in interface DrinkMachineSpec
Parameters:
dbl - The DrinkButtonListener to add.

delDrinkButtonListener

public abstract void delDrinkButtonListener(DrinkButtonListener dbl)
Removes a listener from the list of objects requesting callbacks from the buttons.

Specified by:
delDrinkButtonListener in interface DrinkMachineSpec
Parameters:
dbl - The DrinkButtonListener to remove.