com.avian.birds.addbirds
Class MathBird
java.lang.Object
javax.swing.SwingWorker<java.lang.String,java.lang.String>
com.avian.birds.basebirds.AbstractBasicBird
com.avian.birds.basebirds.StdBird
com.avian.birds.addbirds.MathBird
- All Implemented Interfaces:
- java.lang.Runnable, java.util.concurrent.Future<java.lang.String>, java.util.concurrent.RunnableFuture<java.lang.String>
public class MathBird
- extends StdBird
Concrete implementation of the AbstractBasicBird. The StdBird eats (gets) and
stores (puts) every food packet (tuple) in a TupleTree (tuple space) so it is
very Linda-like. The details of retrieving a food packet are contained in the
eatFood method. The food packet is processed in the digest method. The food packet
is put back into the TupleTree using the storeFood method. After storing the food,
the bird needs a nap. This same cycle repeats (eating, digesting, storing, and napping)
in the run method until it is told to stopNow, either because it's lifeTime has
been exceeded or it has exceeded the length of time that it can live without eating,
at which time it Returns to Egg (death being so ugly and final). One can also use
the setStopNow method to terminate when desired the next time the run method
gets to the statement where it test to see if it should continue running.
Nested classes/interfaces inherited from class javax.swing.SwingWorker |
javax.swing.SwingWorker.StateValue |
Field Summary |
java.lang.String |
mathAmt
Defines the numeric value (as a string) to use with this math operation. |
java.lang.String |
mathOp
Defines the type of math operation to perform. |
Fields inherited from class com.avian.birds.basebirds.StdBird |
foodFromTree, healthStatus, jbRefStart, jlRefLastAte, jtaRefHistory, jtfRefHealth, mts, myTupleTree, nts, sampleXmv, startButtonText |
Fields inherited from class com.avian.birds.basebirds.AbstractBasicBird |
bhf, bif, birdDesc, birdHistory, birdName, bof, eatsFood, hatchTime, historyFileName, inputFileName, lastAte, levelOfInfo, lifeTime, napLength, outputFileName, stamina, stopNow, storesFood |
Method Summary |
void |
digest()
Digests the contents of the food object by performing the math operation
specified in the Xmv mathOp using the amount specified in the Xmv mathAmt. |
void |
eatFood()
This bird eats from the TupleTree/file and applies the math operation specified
in it's Xmv mathOp variable using the value specified in the Xmv mathAmt. |
void |
setMathAmt(java.lang.String mathAmt)
Setter that takes the String parameter and applies it the mathAmt variable. |
void |
setMathOp(java.lang.String mathOp)
Setter that takes the String parameter and applies it the mathOp variable. |
Methods inherited from class com.avian.birds.basebirds.AbstractBasicBird |
addToBirdHistory, doInBackground, getAuxFood, getBirdDescription, getBirdHistory, getBirdName, getEatsFood, getHatchTime, getHistoryFileName, getInputFileName, getLastAte, getLevelOfInfo, getLifeTime, getNameOfFoodToStore, getNapLength, getOutputFileName, getStamina, isStopNow, setBhf, setBif, setBirdDesc, setBirdHistory, setBirdName, setBof, setEatsFood, setHatchTime, setHistoryFileName, setInputFileName, setLevelOfInfo, setLevelOfInfo, setLifeTime, setNapLength, setOutputFileName, setStamina, setStopNow, setStoresFood |
Methods inherited from class javax.swing.SwingWorker |
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, process, publish, removePropertyChangeListener, run, setProgress |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
mathOp
public java.lang.String mathOp
- Defines the type of math operation to perform. Currently, only "add", "subtract",
"multiply" and "divide" are allowed and must be spelled exactly that way.
This is annotated as an Xmv variable, so it requires a matching setter.
mathAmt
public java.lang.String mathAmt
- Defines the numeric value (as a string) to use with this math operation.
This is annotated as an Xmv variable, so it requires a matching setter.
MathBird
public MathBird()
setMathAmt
public void setMathAmt(java.lang.String mathAmt)
- Setter that takes the String parameter and applies it the mathAmt variable.
This setter is required for the Xmv annotated variable of the same name.
- Parameters:
mathAmt
- is value to use in this operation. If mathAmt is "5" then
the numeric value of 5 will be used in whatever math operation is requested.
setMathOp
public void setMathOp(java.lang.String mathOp)
- Setter that takes the String parameter and applies it the mathOp variable.
This setter is required for the Xmv annotated variable of the same name.
- Parameters:
mathOp
- is type of operation to perform. Currently, only "add", "subtract",
"multiply" and "divide" are allowed and must be spelled exactly that way. If
a non-matching operation is requested, the digest method converts it to an
add operation instead of crashing and burning.
eatFood
public void eatFood()
- This bird eats from the TupleTree/file and applies the math operation specified
in it's Xmv mathOp variable using the value specified in the Xmv mathAmt. Any
one of the four basic math ops can be applied using any int value.
- Overrides:
eatFood
in class StdBird
digest
public void digest()
- Digests the contents of the food object by performing the math operation
specified in the Xmv mathOp using the amount specified in the Xmv mathAmt.
Unlike the AddxBirds, this digestion doesn't do any napping.
- Overrides:
digest
in class StdBird