Class UserDB

  • All Implemented Interfaces:
    DB<String,​User>

    public class UserDB
    extends Object
    implements DB<String,​User>
    Storage of all users where the key is the unique username and the value is the associated User object.
    • Constructor Detail

      • UserDB

        public UserDB()
        Create the user database.
    • Method Detail

      • addValue

        public User addValue​(User user)
        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<String,​User>
        Parameters:
        user - the value to add
        Returns:
        the previous value associated with the key, otherwise null
      • getValue

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

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

        public Collection<User> 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<String,​User>
        Returns:
        all the values