Class DbData<T>

java.lang.Object
com.renomad.minum.database.DbData<T>
Direct Known Subclasses:
Inmate

public abstract class DbData<T> extends Object
An abstract data type meant to be used with the database

The Minum database is very plain - data is stored in a strongly-typed Java data collection in memory, and also written to disk.

Each database is responsible for one type of data. For example, you might create a database for Person information, such as name, age, and favorite ice cream flavor. To do so, you would design a class representing the Person, which would include those properties.

Users must supply an implementation of the serialize() and deserialize(String) methods.

  • Constructor Details

    • DbData

      public DbData()
  • Method Details

    • serialize

      protected abstract String serialize()
      Serializes this object into a string representation.

      An example:

              public String serialize() {
                  return serializeHelper(index, a, b);
              }
      
      Returns:
      this type serialized to a string - use SerializationUtils.serializeHelper(Object[])
      See Also:
    • deserialize

      protected abstract T deserialize(String serializedText)
      Deserialize the string into a strongly-typed object. See helper method SerializationUtils.deserializeHelper(String) to split a serialized string into tokens for rebuilding the object. See also serialize()

      An example:

      public Foo deserialize(String serializedText) {
          final var tokens = deserializeHelper(serializedText);
          return new Foo(
              Integer.parseInt(tokens.get(0)),
              Integer.parseInt(tokens.get(1)),
              tokens.get(2)
              );
      }
      
      Parameters:
      serializedText - the serialized string
      Returns:
      this type deserialized from a string
      See Also:
    • getIndex

      protected abstract long getIndex()
      Each piece of data is made unique by having its own index value
    • setIndex

      protected abstract void setIndex(long index)