package admin; import java.util.Collection; /** * GroupDB is the repository of user group information. */ public abstract class GroupDB { /** * The collection of group data records. */ Collection data; /** * Reference to GroupDB needed for change and delete methods. */ UserDB userDB; /** * Add the given GroupRecord to the given GroupDB. The name of the given * group must not be the same as a group already in the GroupDB. All * group members must be registered users. The leader(s) of the group * must be members of it. *
      pre:
        //
        // All group members are registered users.
        //
        forall (String id ; gr.members.contains(id) ;
                exists(UserRecord ur ; userDB.data.contains(ur) ;
                    ur.id.equals(id)))

            &&

        //
        // All group leaders are members of the group.
        //
        forall (String id ; gr.leaders.contains(id) ;
            gr.members.contains(id));

      post:
        //
        // A group record is in the output db if and only if it is the new
        // record to be added or it is in the input db.
        //
        forall (GroupRecord gr_other ;
            data'.contains(gr_other) iff
                gr_other.equals(gr) || data.contains(gr_other));
     *
     */
    abstract void add(GroupRecord gr);

    /**
     * Delete the given group record from the given GroupDB.  The given record
     * must already be in the input db.  Typically the user runs the FindGroup
     * operation prior to Delete to locate an existing record to delete.
     *                                                                     
      pre:
        //
        // The given GroupRecord is in the given GroupDB.
        //
        data.contains(gr);

      post:
        //
        // A group record is in the output db if and only if it is not the
        // existing record to be deleted and it is in the input db.
        //
        forall (GroupRecord gr_other ;
            data'.contains(gr_other) iff
                !gr_other.equals(gr) && data.contains(gr_other));
     *
     */
    abstract void delete(GroupRecord gr);

    /**
     * Change the given old GroupRecord to the given new record.  The old and
     * new records must not be the same.  The old record must already be in
     * the input db.  The new record must meet the same conditions as for the
     * input to the AddGroup operation.  Typically the user runs the FindGroup
     * operation prior to Change to locate an existing record to be changed.
     *                                                                     
      pre:
        //
        // The old and new group records are not the same.
        //
        !old_gr.equals(new_gr)

            &&

        //
        // All group members are registered users.
        //
        forall (String id ; new_gr.members.contains(id) ;
                exists(UserRecord ur ; userDB.data.contains(ur) &&
                     ur.id.equals(id)))

            &&

        //
        // All group leaders are members of the group.
        //
        forall (String id ; new_gr.leaders.contains(id) ;
            new_gr.members.contains(id));

      post:
        //
        // A group record is in the output db if and only if it is the new
        // record to be added or it is in the input db, and it is not the old
        // record.
        //
        forall (GroupRecord gr_other ;
            data'.contains(gr_other) iff
                gr_other.equals(new_gr) ||
                    data.contains(gr_other) &&
                        !gr_other.equals(old_gr));
     *
     */
    abstract void change(GroupRecord old_gr, GroupRecord new_gr);

    /**
     * Find a group by unique name.
     *                                                                     
      post:
        //
        // If there is a record with the given name in the input db, then the
        // output record is equal to that record, otherwise the output record
        // is empty.
        //
        exists(GroupRecord gr_found ; data.contains(gr_found) ;
                gr_found.name.equals(id) && gr_found.equals(return))
            ||
        !exists(GroupRecord gr_found ; data.contains(gr_found) ;
                gr_found.name.equals(id)) && return == null;
     *
     */
    abstract GroupRecord findById(String id);

}