public final class CurrentPortfolio extends Observable
Portfolio
).
CurrentPortfolio may be used as an example implementation for any application which edits one item at a time.
The isUntitled()
and getNeedsSave()
properties are particularly
significant. They influence the file menu actions. For example, a
CurrentPortfolio for which isUntitled()
is true cannot be deleted.
CurrentPortfolio is an Observable
. To minimize spurious
updates, related Observer
objects need to call
Observable.notifyObservers()
explicitly. This is important in this
application, since quotes are fetched from the web each time the current portfolio is
updated, and this is a relatively expensive operation.
Modifier and Type | Class and Description |
---|---|
static class |
CurrentPortfolio.NeedsSave
Enumeration for the two states of aNeedsSave passed to the constructor.
|
Constructor and Description |
---|
CurrentPortfolio(Portfolio aPortfolio,
CurrentPortfolio.NeedsSave aNeedsSave)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Revert to an untitled Portfolio which does not need a save.
|
String |
getName()
Return the name of this CurrentPortfolio.
|
boolean |
getNeedsSave()
Return true only if this CurrentPortfolio has unsaved
edits.
|
Portfolio |
getPortfolio()
Return the
Portfolio of current interest to the user. |
Set<Stock> |
getStocks()
Return the
Stock objects in this
CurrentPortfolio. |
boolean |
isUntitled()
Return true only if the current Portfolio has never been
saved under a user-specified name, neither in this session, nor in any other.
|
void |
setName(String aName)
Change the name of this CurrentPortfolio.
|
void |
setNeedsSave(boolean aNeedsSave)
Indicate that this CurrentPortfolio either does or does not have any
unsaved edits.
|
void |
setPortfolio(Portfolio aPortfolio)
Change the
Portfolio of current interest to the user. |
void |
setStocks(Set<Stock> aStocks)
Change the stocks in this CurrentPortfolio.
|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
public CurrentPortfolio(Portfolio aPortfolio, CurrentPortfolio.NeedsSave aNeedsSave)
aPortfolio
- is the set of stocks of current interest to the user; no
defensive copy is made of aPortfolio.aNeedsSave
- is true only if this CurrentPortfolio
has been edited by the end user, and these edits have not yet been saved.public void clear()
public boolean isUntitled()
public Portfolio getPortfolio()
Portfolio
of current interest to the user.public void setPortfolio(Portfolio aPortfolio)
Portfolio
of current interest to the user.public void setName(String aName)
aName
- has the same conditions as
Portfolio.setName(String)
.public void setStocks(Set<Stock> aStocks)
aStocks
- has the same conditions as
Portfolio.setStocks(Set)
public boolean getNeedsSave()
public void setNeedsSave(boolean aNeedsSave)
Copyright Hirondelle Systems - License - Generated 2013Sep20.10.58