Class Inmate

java.lang.Object
com.renomad.minum.database.DbData<Inmate>
com.renomad.minum.security.Inmate

public final class Inmate extends DbData<Inmate>
Represents an inmate in our "jail". If someone does something we don't like, they do their time here.
  • Field Details

    • EMPTY

      public static final Inmate EMPTY
      Builds an empty version of this class, except that it has a current Context object
  • Constructor Details

    • Inmate

      public Inmate(Long index, String clientId, Long releaseTime)
      Represents an inmate in our "jail". If someone does something we don't like, they do their time here.
      Parameters:
      clientId - a string representation of the client address plus a string representing the offense, for example, "1.2.3.4_vuln_seeking" - 1.2.3.4 was seeking out vulnerabilities.
      releaseTime - the time, in milliseconds from the epoch, at which this inmate will be released from the brig.
  • Method Details

    • getIndex

      public long getIndex()
      Description copied from class: DbData
      We need an index so that each piece of data is distinct, even if it has the same data.
      Specified by:
      getIndex in class DbData<Inmate>
      Returns:
      an index for this data, used to name a file for this particular instance of data
    • setIndex

      public void setIndex(long index)
      Description copied from class: DbData
      It is necessary for this method to exist because it is used by the Db code to add the new index into this data.

      Let me unpack that a bit.

      The way our database works, it's expected that when you are creating a new instance of data, you won't know its index yet, because that is something the database manages for you.

      The index is an AtomicLong value that allows us to create new data without worrying about race conditions between threads (that is, we don't have to worry about two threads accidentally adding the same index value to two different datas).

      This value is also used as the name for the file of this data stored on disk.

      Specified by:
      setIndex in class DbData<Inmate>
    • serialize

      public String serialize()
      Description copied from class: DbData
      Serializes this object into a string representation. It will be the values of this object as strings, encoded with URL encoding, separated by pipe symbols.

      An example:

              import static com.renomad.minum.utils.SerializationUtils.serializeHelper;
      
              public String serialize() {
                  return serializeHelper(index, a, b);
              }
      
      Specified by:
      serialize in class DbData<Inmate>
      Returns:
      this type serialized to a string - use SerializationUtils.serializeHelper(Object[])
      See Also:
    • deserialize

      public Inmate deserialize(String serializedText)
      Description copied from class: DbData
      deserializes the text back into an object. See helper method SerializationUtils.deserializeHelper(String) to split a serialized string into tokens for rebuilding the object. See also DbData.serialize()

      An example:

              import static com.renomad.minum.utils.SerializationUtils.deserializeHelper;
      
              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)
                          );
              }
      
      Specified by:
      deserialize in class DbData<Inmate>
      Parameters:
      serializedText - the serialized string
      Returns:
      this type deserialized from a string
      See Also:
    • getClientId

      public String getClientId()
    • getReleaseTime

      public Long getReleaseTime()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object