|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--mvp.Model | +--rolodex.Rolodex
Class Rolodex is the model class for the basic rolodex object, including the operations to add, delete, change, and find rolodex entries.
Field Summary | |
protected AddInputErrors |
aie
Error messages for the Add function |
protected ChangeInputErrors |
cie
Error messages for the Change function |
protected CardList |
cl
Simple list rep'n of the card list |
protected DeleteInputError |
die
Error message for the Delerte function |
Fields inherited from class mvp.Model |
view |
Constructor Summary | |
Rolodex(mvp.View v)
Construct an initially empty rolodex. |
Method Summary | |
void |
add(Card c)
Add the given card to this if a card of the same id is not already there and there is room for another card. |
void |
change(Id id,
Card c)
Change the card of the given id in this to the given new card. |
void |
delete(Id id)
Delete the card of the given id from this. |
java.lang.String |
dump()
Dump this to stdout by dumping each card, in List.iterator order. |
protected Card |
find(Id id)
Find the card of the given id. |
CardList |
find(Name n)
Find all of the cards of the given name in this. |
java.util.Iterator |
getIterator()
Provide an abstract iterator that will enumerate the cards of this. |
void |
print()
Print this to stdout. |
protected AddInputErrors |
validateAddInput(Card c)
Validate the given card per the precondition of Add. |
Methods inherited from class mvp.Model |
exit, getView, setView |
Methods inherited from class java.util.Observable |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected CardList cl
protected AddInputErrors aie
protected DeleteInputError die
protected ChangeInputErrors cie
Constructor Detail |
public Rolodex(mvp.View v)
post: (exists (CardList cl) (this'.cl == cl) and (cl.Len() == 0)) and (exists (AddInputErrors aie) (this'.aie == aie)); and (exists (DeleteInputError die) (this'.die == die)); and (exists (ChangeInputErrors cie) (this'.cie == cie));
Method Detail |
public void add(Card c) throws AddInputErrors
pre: // There is no card in the input this with the same id as the given // input card. not CardAlreadyThere(c) and // The values of the given card fields are valid. CardIsValid(c) and // There is room for another card. (cl.Len() < MAXCARDS) post: // If none of the preconditions is violated, then a normal // postcondition holds, else an exception is thrown. if (not addPrecondViolated(c)) ( // A card is in the output this iff it is in the input this or // it's the new card to be added. forall (Card c') this'.In(c') iff (In(c') or (c' == c)) and // The size of this is increased by 1. (cl'.Length() == cl.Length() + 1) and // This has changed (as an observable object). this'.hasChanged() == true; ) else ( // An AddInputException is thrown if any of the preconditions // is violated. The value of the exception flag is set for // each violated precondition via the ValidataAddInput // function. (throw == aie) and (aie == ValidateAddInput(c)) and
AddInputErrors
public void delete(Id id) throws DeleteInputError
pre: // There is a card of the given id in the input this. exists (Card c' | In(c')) c'.getId() == id; post: // If the precondition is not violated, then a normal postcondition // holds, else an exception is thrown. if (deletePrecondViolated(c)) then ( // A card is in the output this iff it is in the input this and // its id is different than the given id. forall (Card c') this'.In(c') iff (In(c') and (c'.id != id)); and // This has changed (as an observable object). this'.hasChanged() == true; ) else // A DeleteInputException is thrown if the precondition is // violated. throw == die;
DeleteInputError
public void change(Id id, Card c) throws AddInputErrors, ChangeInputErrors, DeleteInputError
pre: // There is a card of the given id in the input this and that card // is not identical with the given input card, and the given card // is valid. exists (Card c' | In(c') (c'.getId() == id) and (c' != c) and CardIsValid(c); post: // If the precondition is not violated, then a normal postcondition // holds, else an exception is thrown. if (changePrecondViolated(c)) then ( // A card is in the output this iff it is in the input this and // is not the card with the given id in the input this, or it's // the given input card. forall (Card c') this'.In(c') iff (In(c') and (not exists (Card c'' | In(c'')) (c''.getId() == id) and (c'' == c')) or (c' == c)) and // This has changed (as an observable object). this'.hasChanged() == true; ) else // A ChangeInputException is thrown if the precondition is // violated. throw == cie;
AddInputErrors
ChangeInputErrors
DeleteInputError
public CardList find(Name n)
post: // Cards in the output list consist of those in the input this with // the given name. forall (Card c) (cl.In(c) iff (In(c) and (c.getName() == n)) and // The output card list is sorted by ascending order of card id. forall (int i, int j | (i >= 1) and (i <= cl.Length()) and (j >= 1) and (j <= cl.Length())) if i < j then cl.get(i).getId() < cl.get(j).getId();
public java.util.Iterator getIterator()
public void print()
public java.lang.String dump()
dump
in class mvp.Model
protected Card find(Id id)
protected AddInputErrors validateAddInput(Card c)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |