|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jp.comp.calculator.Calculator
Performs calculator's computing. The set of operations performed by the calculator can be changed.
If there is a need to calclulate x^y a new operation should be created implementing
CaclulatorOperation
and added to the Calculator
by
addOperation
method
CalculatorPanel
Field Summary | |
protected CalculatorEvent |
fCalculatorEvent
|
protected java.util.Vector |
fCalculatorListeners
|
protected java.util.HashMap |
fCalculatorOperations
|
protected CalculatorResult |
fCalculatorResult
|
protected CalculatorOperation |
fDefaultClearOperation
|
protected boolean |
fProcessingError
|
protected java.util.HashMap |
fStateMap
|
static CalculatorOperation |
MEMORY_ADDITION
Default memory addition operation |
static java.lang.String |
MEMORY_ADDITION_KEY
Memory addition operation's key |
static CalculatorOperation |
MEMORY_CLEAR
Default memory clear operation |
static java.lang.String |
MEMORY_CLEAR_KEY
Memory clear operation's key |
static CalculatorOperation |
MEMORY_RECALL
Default memory recall operation |
static java.lang.String |
MEMORY_RECALL_KEY
Memory recall operation's key |
static CalculatorOperation |
MEMORY_STORE
Default memory store operation |
static java.lang.String |
MEMORY_STORE_KEY
Memory store operation's key |
static CalculatorOperation |
MEMORY_SUBTRACTION
Default memory subtaction operation |
static java.lang.String |
MEMORY_SUBTRACTION_KEY
Memory subtraction operation's key |
static java.lang.String |
PROPERTY_DEFAULT_CLEAR_OPERATION
Property name for the default clear operation |
static java.lang.String |
PROPERTY_HASHED_OPERATION
Property name for the hashed operations |
static java.lang.String |
PROPERTY_MEMORY
Property name for the memory |
static java.lang.String |
PROPERTY_RESULT
Property name for the result |
protected java.util.Vector |
propertyChangeListeners
|
static CalculatorOperation |
RESULT_ADDITION
Default addition operation |
static java.lang.String |
RESULT_ADDITION_KEY
Addition operation's key |
static CalculatorOperation |
RESULT_CLEAR
Default clear operation |
static java.lang.String |
RESULT_CLEAR_KEY
Clear operation's key |
static CalculatorOperation |
RESULT_DIVISION
Default division operation |
static java.lang.String |
RESULT_DIVISION_KEY
Division operation's key |
static CalculatorOperation |
RESULT_EQUAL
Default equal operation |
static java.lang.String |
RESULT_EQUAL_KEY
Equal operation's key |
static CalculatorOperation |
RESULT_MULTIPLICATION
Default multiplication operation |
static java.lang.String |
RESULT_MULTIPLICATION_KEY
Multiplication operation's key |
static CalculatorOperation |
RESULT_PERCENT
Default percent operation |
static java.lang.String |
RESULT_PERCENT_KEY
Percent operation's key |
static CalculatorOperation |
RESULT_RECIPROCAL
Default reciprocal operation |
static java.lang.String |
RESULT_RECIPROCAL_KEY
Reciprocal operation's key |
static CalculatorOperation |
RESULT_SQRT
Default sqrt operation |
static java.lang.String |
RESULT_SQRT_KEY
Sqrt operation's key |
static CalculatorOperation |
RESULT_SUBTRACTION
Default subtaction operation |
static java.lang.String |
RESULT_SUBTRACTION_KEY
Subtraction operation's key |
static java.math.BigDecimal |
VALUE_0
Default zero value |
Constructor Summary | |
Calculator()
Creates the class instance |
Method Summary | |
void |
addCalculatorListener(CalculatorListener aListener)
Adds Calculator's listener |
void |
addOperation(java.lang.String anOperationKey,
CalculatorOperation anOperation)
Adds a new operation to the calculator. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener aListener)
Adds state map property change listener |
protected void |
firePropertyChange(java.beans.PropertyChangeEvent anEvent)
Fired by the calculator when state map property is changed |
protected void |
fireResultChanged()
Fired by the calculator when the result is changed |
CalculatorOperation |
getDefaultClearOperation()
Returns default clear operation. |
protected java.math.BigDecimal |
getResult()
Returns last caclulator's result sitting in the state map |
java.lang.Object |
getStateMapProperty(java.lang.String aKey)
Returns state map property value specified by aKey |
boolean |
isOperationExist(java.lang.String anOperationKey)
Returns true if operation, specified by anOperationKey , exist |
protected void |
performNonStandaloneOperation(java.math.BigDecimal aValue,
CalculatorOperation anOperation,
boolean aValueChanged)
Performs nonstandalone operation. |
CalculatorResult |
performOperation(double aValue,
java.lang.String anOperationKey,
boolean aValueChanged)
Seeks and performs operation specified by anOperationKey . |
protected void |
performStandaloneOperation(java.math.BigDecimal aValue,
CalculatorOperation anOperation,
boolean aValueChanged)
Performs standalone operation. |
void |
removeCalculatorListener(CalculatorListener aListener)
Removes Calculator's listener |
void |
removeOperation(java.lang.String anOperationKey)
Removes the operation, specified by anOperationKey , from the calculator |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener aListener)
Removes state map property change listener |
void |
setDefaultClearOperation(CalculatorOperation aDefaultClearOperation)
Sets default clear operation. |
void |
setStateMapProperty(java.lang.String aKey,
java.lang.Object aValue)
Sets a new state map property value |
void |
updateOperation(java.lang.String anOperationKey,
CalculatorOperation anOperation)
Updates an existing operation in the calculator. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String PROPERTY_MEMORY
public static final java.lang.String PROPERTY_RESULT
public static final java.lang.String PROPERTY_HASHED_OPERATION
public static final java.lang.String PROPERTY_DEFAULT_CLEAR_OPERATION
public static final java.lang.String MEMORY_CLEAR_KEY
public static final java.lang.String MEMORY_STORE_KEY
public static final java.lang.String MEMORY_RECALL_KEY
public static final java.lang.String MEMORY_ADDITION_KEY
public static final java.lang.String MEMORY_SUBTRACTION_KEY
public static final java.lang.String RESULT_ADDITION_KEY
public static final java.lang.String RESULT_SUBTRACTION_KEY
public static final java.lang.String RESULT_MULTIPLICATION_KEY
public static final java.lang.String RESULT_DIVISION_KEY
public static final java.lang.String RESULT_SQRT_KEY
public static final java.lang.String RESULT_PERCENT_KEY
public static final java.lang.String RESULT_RECIPROCAL_KEY
public static final java.lang.String RESULT_EQUAL_KEY
public static final java.lang.String RESULT_CLEAR_KEY
public static final CalculatorOperation MEMORY_CLEAR
public static final CalculatorOperation MEMORY_STORE
public static final CalculatorOperation MEMORY_RECALL
public static final CalculatorOperation MEMORY_ADDITION
public static final CalculatorOperation MEMORY_SUBTRACTION
public static final CalculatorOperation RESULT_ADDITION
public static final CalculatorOperation RESULT_SUBTRACTION
public static final CalculatorOperation RESULT_MULTIPLICATION
public static final CalculatorOperation RESULT_DIVISION
public static final CalculatorOperation RESULT_SQRT
public static final CalculatorOperation RESULT_PERCENT
public static final CalculatorOperation RESULT_RECIPROCAL
public static final CalculatorOperation RESULT_EQUAL
public static final CalculatorOperation RESULT_CLEAR
public static final java.math.BigDecimal VALUE_0
protected CalculatorOperation fDefaultClearOperation
protected java.util.HashMap fCalculatorOperations
protected java.util.HashMap fStateMap
protected boolean fProcessingError
protected CalculatorResult fCalculatorResult
protected CalculatorEvent fCalculatorEvent
protected transient java.util.Vector fCalculatorListeners
protected transient java.util.Vector propertyChangeListeners
Constructor Detail |
public Calculator()
Method Detail |
public CalculatorResult performOperation(double aValue, java.lang.String anOperationKey, boolean aValueChanged)
anOperationKey
.
Invoked by CalculatorPanel
to perform an operation associated with the particular button
aValue
- the value to perform operation onanOperationKey
- the operation keyaValueChanged
- if true the value was changed in CalculatorPanel
- Returns:
- computing's result
protected void performStandaloneOperation(java.math.BigDecimal aValue, CalculatorOperation anOperation, boolean aValueChanged)
CalculatorPanel
to be shown on the display
aValue
- the value to perform operation onanOperation
- the operation keyaValueChanged
- if true the value was changed in CalculatorPanel
- See Also:
CalculatorOperation.isStandalone()
protected void performNonStandaloneOperation(java.math.BigDecimal aValue, CalculatorOperation anOperation, boolean aValueChanged)
CalculatorPanel
to be shown on the display
aValue
- the value to perform operation onanOperation
- the operation keyaValueChanged
- if true the value was changed in CalculatorPanel
- See Also:
CalculatorOperation.isStandalone()
protected java.math.BigDecimal getResult()
public java.lang.Object getStateMapProperty(java.lang.String aKey)
aKey
aKey
- property key
public void setStateMapProperty(java.lang.String aKey, java.lang.Object aValue)
aKey
- property keyaValue
- property valuepublic void addOperation(java.lang.String anOperationKey, CalculatorOperation anOperation)
anOperationKey
already exist
IllegalArgumentException
will be thrown
anOperationKey
- operation keyanOperation
- operation
java.lang.IllegalArgumentException
public void updateOperation(java.lang.String anOperationKey, CalculatorOperation anOperation)
anOperationKey
doesn't exist
IllegalArgumentException
will be thrown
anOperationKey
- operation keyanOperation
- operation
java.lang.IllegalArgumentException
public void removeOperation(java.lang.String anOperationKey)
anOperationKey
, from the calculator
anOperationKey
- operation keypublic boolean isOperationExist(java.lang.String anOperationKey)
true
if operation, specified by anOperationKey
, exist
anOperationKey
- operation key
true
if operation existpublic CalculatorOperation getDefaultClearOperation()
public void setDefaultClearOperation(CalculatorOperation aDefaultClearOperation)
aDefaultClearOperation
- default clear operationprotected void fireResultChanged()
protected void firePropertyChange(java.beans.PropertyChangeEvent anEvent)
anEvent
- property change eventpublic void addCalculatorListener(CalculatorListener aListener)
aListener
- Calculator's listenerpublic void removeCalculatorListener(CalculatorListener aListener)
aListener
- Calculator's listenerpublic void addPropertyChangeListener(java.beans.PropertyChangeListener aListener)
aListener
- state map property change listenerpublic void removePropertyChangeListener(java.beans.PropertyChangeListener aListener)
aListener
- state map property change listener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |