Consider the List interface in the java.util package for ordered collections of objects. Write preconditions and post conditions in OCL for the following operations:
The constraints below assume that an ordered association between the list and its contained elements is called
elements.
a. int size() returns the number of elements in the list.
b. void add(Object e) adds an object at the end of the list.
c. void remove(Object e) removes an object from the end of the list.
d. boolean contains(Object e) returns true if the object is contained in the list.
e. Object get(int idx) returns the object located at index idx, 0 being the index of the first object in the
list.
a. context List::size() post: result = elements->size
b. context List::add(e) post: contains(e) and size() = @pre.size() + 1
c. context List::remove(e) post:
(@pre.contains(e) implies size() = @pre.size() - 1) and
(not @pre.contains(e) implies size() = @pre.size()) and
result = @pre.contains(e)
d. context List::contains(e) post: result = elements->includes(e)e.
context List::get(idx) pre: idx >= 0 and idx < size()
context List::get(idx) post: result = elements->at(idx+1)
You might also like to view...
Which of the following is referred to as the guest operating system when using virtualization software?
A. OS running on the physical machine B. OS that is available through multiboot installations C. OS running on the virtual machine D. OS that is accessed remotely
Which of the following statements is true of the Minimize button?
A. ?It summarizes the commands applied on a window. B. ?It restores a window to its previous size. C. ?It resizes a window to fill the screen. D. ?Itshrinks a window to its button on the taskbar.
When an image is used on a Web page, within the text of a document, it is known as a(n):
A) imported image. B) local image. C) document image. D) inline image.
Buying a collection of programs in a software suite usually costs significantly more than purchasing them individually.
Answer the following statement true (T) or false (F)