Last modification: 06/12/16
The Direction
enumeration
Create en enumeration which includes a LEFT
and a RIGHT
value.
Override the toString()
method such as it returns left
and right
accordingly.
The ZipList
data structure
Create a new class named ZipList
which can store arbitary elements (it is a generic data structure). A ZipList
represents a regular list with a focus on a given element. We can move the focus to the left or right one step using the Direction
enumeration.
Create a constructor which takes a List<A>
as argument and inicializes two lists: a list with elements left and right of the focus. The first element of the right list is at the focus.
Add a move()
method which takes a Direction
as argument and moves the focus in the given direction.
Add a get()
method which retrieves the element in the focus.
Add a put()
element which takes a new element as argument an places it in the focus.
The NoMoreElementException
unchecked exception
Create an unchecked exception NoMoreElementException
(it inherits from RuntimeException
).
Modify your move()
method such as it throws an exception when we want to step out of the list with the focus.
The EmptyFocusException
checked exception
Create a checked exception EmptyFocusException
(it inherits from Exception
).
Modify your get()
method such as it throws an exception when we want to get an element from an empty list.