Interface DB<K,​V>

  • Type Parameters:
    K - key type
    V - value type
    All Known Implementing Classes:
    CourseDB, UserDB

    public interface DB<K,​V>
    A generic interface used by the Backend, CourseDB and UserDB.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      V addValue​(V value)
      Add a value entry to the database in constant time.
      Collection<V> getAllValues()
      Get all the values in the database in linearithmic, O(nlogn), time, where the elements are naturally ordered.
      V getValue​(K key)
      Get the value for an associated key in constant time.
      boolean hasKey​(K key)
      Indicates whether a key is in the database or not, in constant time.
    • Method Detail

      • addValue

        V addValue​(V value)
        Add a value entry to the database in constant time. The database will determine the key based on the value type.
        Parameters:
        value - the value to add
        Returns:
        the previous value associated with the key, otherwise null
      • getValue

        V getValue​(K key)
        Get the value for an associated key in constant time.
        Parameters:
        key - the key
        Returns:
        the value that is associated with the key, or null if not present
      • hasKey

        boolean hasKey​(K key)
        Indicates whether a key is in the database or not, in constant time.
        Parameters:
        key - the key to search for
        Returns:
        whether the key is present or not
      • getAllValues

        Collection<V> getAllValues()
        Get all the values in the database in linearithmic, O(nlogn), time, where the elements are naturally ordered.
        Returns:
        all the values