Class CourseDB

  • All Implemented Interfaces:
    DB<Integer,​Course>

    public class CourseDB
    extends Object
    implements DB<Integer,​Course>
    Storage of all courses where the key is the unique course id and the value is the associated Course object.
    • Constructor Detail

      • CourseDB

        public CourseDB()
        Create the course database.
    • Method Detail

      • addValue

        public Course addValue​(Course course)
        Description copied from interface: DB
        Add a value entry to the database in constant time. The database will determine the key based on the value type.
        Specified by:
        addValue in interface DB<Integer,​Course>
        Parameters:
        course - the value to add
        Returns:
        the previous value associated with the key, otherwise null
      • getValue

        public Course getValue​(Integer id)
        Description copied from interface: DB
        Get the value for an associated key in constant time.
        Specified by:
        getValue in interface DB<Integer,​Course>
        Parameters:
        id - the key
        Returns:
        the value that is associated with the key, or null if not present
      • hasKey

        public boolean hasKey​(Integer id)
        Description copied from interface: DB
        Indicates whether a key is in the database or not, in constant time.
        Specified by:
        hasKey in interface DB<Integer,​Course>
        Parameters:
        id - the key to search for
        Returns:
        whether the key is present or not
      • getAllValues

        public Collection<Course> getAllValues()
        Description copied from interface: DB
        Get all the values in the database in linearithmic, O(nlogn), time, where the elements are naturally ordered.
        Specified by:
        getAllValues in interface DB<Integer,​Course>
        Returns:
        all the values