public class ContactList
extends java.lang.Object
ContactList.xml
specification. It models a table of names, where names may be entered,
selected and removed. This example was developed to mimic the behaviour
of many GUIs, where the selected row can be either transferred or dropped,
when a row is deleted. This leads to three different kinds of behaviour
upon deletion, which are triggered by the filled-state and selection-state
of the table, rather than by any condition on the inputs.
This uses the State Pattern (a Design Pattern from Gamma, et al.) for its implementation. All requests are delegated to an abstract State, which has concrete subclasses EmptyTable, NonEmptyTable and RowSelected, which respond to certain requests in different ways. Otherwise, the table is implemented as a List of SimpleEntry pairs, where each pair contains two Strings for the forename and surname. Pairs in the specification language are implemented as SimpleEntry in the Java code. We provide a top-level public type with this name, shadowing the inner class AbstractMap.SimpleEntry, which causes problems for SOAP and REST web service frameworks that cannot pass nested classes as parameters.
Indexing in the specification language runs from 1..n; this is observed in the values assigned to indicate the selected row, but indices are converted into the range 0..n-1 when accessing the underlying Java Lists.
Suggestions are given for how to modify the source code to seed faults deliberately, which will be detected during testing.
Constructor and Description |
---|
ContactList()
Creates a ContactList.
|
Modifier and Type | Method and Description |
---|---|
void |
addEntry(java.lang.String forename,
java.lang.String surname)
Attempts to add a new entry to this ContactList.
|
java.lang.String |
getScenario()
Returns the last scenario that was enacted.
|
java.lang.String |
getState()
Returns the last state that was entered.
|
void |
removeEntry()
Attempts to remove an entry from this ContactList.
|
void |
selectRow(int index)
Attempts to select a row in this ContactList.
|
void |
unselectRow()
Attempts to unselect a row in this ContactList.
|
public ContactList()
public java.lang.String getScenario()
public java.lang.String getState()
public void addEntry(java.lang.String forename, java.lang.String surname)
forename
- a forename.surname
- a surname.public void selectRow(int index)
index
- the row selection index.public void unselectRow()
public void removeEntry()