Consider the Set interface in the java.util package. Write preconditions and post conditions in OCL for the following operations:
The constraints below assume that the association between the list and its contained elements is called elements.
a. int size() returns the number of elements in the set.
b. void add(Object e) adds an object to the set. If the object is already in the set, does nothing.
c. void remove(Object e) removes an object from the set
d. boolean contains(Object e) returns true if the object is contained in the set.
a. context Set::size() post: result = elements->size()
b. context Set::add(e) post:
contains(e) and
(@pre.contains(e) implies size() = @pre.size()) and
(not @pre.contains(e) implies size() = @pre.size()+1)
c. context Set::remove(e) post:
not contains(e) and
(@pre.contains(e) implies size() = @pre.size() - 1) and
(not @pre.contains(e) implies size() = @pre.size())
d. context Set::contains(e) post: elements->includes(e)
You might also like to view...
________ occurs when an infinite loop prevents progress in a multithreaded application.
a) Lockstep synchronization b) Deadlock c) Busy waiting d) Indefinite postponement
An Impress presentation is made up of a series of slides
Indicate whether the statement is true or false
To recall the most recently deleted text, which button would you click?
A) Undo B) Insert C) Enter D) Delete
Why is practice so important when preparing a presentation? Provide a specific example from your own experience.
What will be an ideal response?