public abstract class UserDB
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
UserDB.SE1 |
class |
UserDB.SE2 |
Modifier and Type | Field and Description |
---|---|
(package private) java.util.Collection<UserRecord> |
data
The collection of user data records.
|
(package private) GroupDB |
groupDB
Reference to GroupDB needed for change and delete methods.
|
Constructor and Description |
---|
UserDB() |
Modifier and Type | Method and Description |
---|---|
(package private) abstract void |
add(UserRecord ur)
Add the given UserRecord to the given UserDB.
|
(package private) abstract void |
change(UserRecord old_ur,
UserRecord new_ur)
Change the given old UserRecord to the given new record.
|
(package private) abstract LeaderlessGroupsWarning |
delete(UserRecord ur)
Delete the given user record from the given UserDB.
|
(package private) abstract UserRecord |
findById(java.lang.String id)
Find a user by unique id.
|
(package private) abstract java.util.List<UserRecord> |
findByName(java.lang.String name)
Find a user or users by real-world name.
|
java.util.Collection<UserRecord> data
GroupDB groupDB
abstract void add(UserRecord ur)
pre: // // There is no user record in the input UserDB with the same id as the // record to be added. // (! exists (UserRecord ur_other ; data.contains(ur_other) ; ur_other.id.equals(ur.id))) && // // The id of the given user record is not empty and 8 characters or // less. // (ur.id != null) && (ur.id.length() > 0) && (ur.id.length() <= 8) && // // The email address is not empty. // (ur.email != null) && (ur.email.length() > 0) && // // If the phone area code and number are present, they must be 3 digits // and 7 digits respectively. // ((ur.phone.area != 0) ==> Integer.toString(ur.phone.area).length() == 3) && ((ur.phone.number != 0) ==> Integer.toString(ur.phone.number).length() == 7); post: // // A user record is in the output data if and only if it is the new // record to be added or it is in the input data. // forall (UserRecord ur_other ; (data'.contains(ur_other)) iff ur_other.equals(ur) || data.contains(ur_other));
abstract UserRecord findById(java.lang.String id)
post: // // If there is a record with the given id in the input data, then the // output record is equal to that record, otherwise the output record // is null. // exists (UserRecord ur_found ; data.contains(ur_found) ; ur_found.id.equals(id) && ur_found.equals(return)) || !exists (UserRecord ur_found ; data.contains(ur_found) ; ur_found.id.equals(id)) && return == null;
abstract java.util.List<UserRecord> findByName(java.lang.String name)
post: // // The output list consists of all records of the given name in the // input data. // forall (UserRecord ur ; return.contains(ur) ; data.contains(ur) && ur.name.equals(name)) && // // The output list is sorted lexicographically by id, according to the // semantics of java.lang.String.compareTo(). // forall (int i ; (i >= 0) && (i < return.size() - 1) ; return.get(i).id.compareTo(return.get(i+1).id) < 0);
abstract void change(UserRecord old_ur, UserRecord new_ur)
pre: // // The old and new user records are not the same. // !old_ur.equals(new_ur) && // // The old record is in this.data. // data.contains(old_ur) && // // There is no user record in the input UserDB with the same id as the // new record to be added. // (! exists (UserRecord ur_other ; data.contains(ur_other) ; ur_other.id.equals(new_ur.id))) && // // The id of the new record is not empty and 8 characters or less. // (new_ur.id != null) && (new_ur.id.length() > 0) && (new_ur.id.length() <= 8) && // // The email address is not empty. // (new_ur.email != null) && (new_ur.email.length() > 0) && // // If the phone area code and number are present, they must be 3 digits // and 7 digits respectively. // ((new_ur.phone.area != 0) ==> Integer.toString(new_ur.phone.area).length() == 3) && ((new_ur.phone.number != 0) ==> Integer.toString(new_ur.phone.number).length() == 7); post: // // A user record is in the output data if and only if it is the new // record to be added or it is in the input data, and it is not the old // record. // forall (UserRecord ur_other ; data'.contains(ur_other) iff ur_other.equals(new_ur) || (data.contains(ur_other) && !ur_other.equals(old_ur))) && // // If new id is different than old id, then all occurrences of old id // in the GroupDB are replaced by new id. // !old_ur.id.equals(new_ur.id) ==> true // Logic left as exercise for the reader ;
abstract LeaderlessGroupsWarning delete(UserRecord ur)
pre: // // The given user record is in this.data. // data.contains(ur); post: // // A user record is in the output data if and only if it is not the // existing record to be deleted and it is in the input data. // forall (UserRecord ur_other ; data'.contains(ur_other) iff !ur_other.equals(ur) && data.contains(ur_other)) && // // The id of the deleted user is not in the leader or member lists of // any group in the output GroupDB. (NOTE: This clause is not as // strong as a complete "no junk, no confusion" spec. Why not? Should // it be?) // forall (GroupRecord gr ; groupDB.data.contains(gr) ; !gr.leaders.contains(ur.id) && !gr.members.contains(ur.id)) && // // The LeaderlessGroupsWarning list contains the ids of all groups // whose only leader was the user who has just been deleted. // forall (GroupRecord gr ; groupDB.data.contains(gr) ; \forall String id ; (return.groupNames.contains(id) iff gr.leaders.size() == 1) && (gr.leaders.get(0).equals(ur.id)));