Represents an inmate in our "jail". If someone does something we don't like, they do their time here.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondeserialize
(String serializedText) deserializes the text back into an object.boolean
long
getIndex()
We need an index so that each piece of data is distinct, even if it has the same data.int
hashCode()
Serializes this object into a string representation.void
setIndex
(long index) It is necessary for this method to exist because it is used by theDb
code to add the new index into this data.toString()
-
Field Details
-
EMPTY
Builds an empty version of this class, except that it has a current Context object
-
-
Constructor Details
-
Inmate
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. -
setIndex
public void setIndex(long index) Description copied from class:DbData
It is necessary for this method to exist because it is used by theDb
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.
-
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 classDbData<Inmate>
- Returns:
- this type serialized to a string - use
SerializationUtils.serializeHelper(Object[])
- See Also:
-
deserialize
Description copied from class:DbData
deserializes the text back into an object. See helper methodSerializationUtils.deserializeHelper(String)
to split a serialized string into tokens for rebuilding the object. See alsoDbData.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 classDbData<Inmate>
- Parameters:
serializedText
- the serialized string- Returns:
- this type deserialized from a string
- See Also:
-
getClientId
-
getReleaseTime
-
equals
-
hashCode
public int hashCode() -
toString
-