Class SimpleDB


public class SimpleDB extends Object
SimpleDB is a basic key-value database using a HashMap for in-memory storage. It supports basic CRUD operations and can persist/load data to/from a file using serialization.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, empty SimpleDB.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all key-value pairs from the database.
    boolean
    Checks if the database contains the given key.
    void
    Removes the key-value pair for the given key from the database.
    get(String key)
    Retrieves the value associated with the given key.
    void
    Loads the database from a file using deserialization.
    void
    Serializes and saves the database to a file.
    void
    put(String key, String value)
    Adds or updates a key-value pair in the database.
    int
    Returns the number of key-value pairs in the database.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SimpleDB

      public SimpleDB()
      Constructs a new, empty SimpleDB.
  • Method Details

    • put

      public void put(String key, String value)
      Adds or updates a key-value pair in the database.
      Parameters:
      key - the key to add or update
      value - the value to associate with the key
    • get

      public String get(String key)
      Retrieves the value associated with the given key.
      Parameters:
      key - the key to look up
      Returns:
      the value associated with the key, or null if not found
    • delete

      public void delete(String key)
      Removes the key-value pair for the given key from the database.
      Parameters:
      key - the key to remove
    • containsKey

      public boolean containsKey(String key)
      Checks if the database contains the given key.
      Parameters:
      key - the key to check
      Returns:
      true if the key exists, false otherwise
    • size

      public int size()
      Returns the number of key-value pairs in the database.
      Returns:
      the size of the database
    • clear

      public void clear()
      Removes all key-value pairs from the database.
    • persist

      public void persist()
      Serializes and saves the database to a file.
    • load

      public void load()
      Loads the database from a file using deserialization. Suppresses unchecked cast warning.