Minor: a serialisation related fix and an additional explainer comment in SerializedBytes

This commit is contained in:
Mike Hearn 2016-03-01 15:23:47 +01:00
parent 42cd9a14cb
commit c52f1e096f
2 changed files with 8 additions and 2 deletions

View File

@ -68,6 +68,7 @@ val THREAD_LOCAL_KRYO = ThreadLocal.withInitial { createKryo() }
* to get the original object back.
*/
class SerializedBytes<T : Any>(bits: ByteArray) : OpaqueBytes(bits) {
// It's OK to use lazy here because SerializedBytes is configured to use the ImmutableClassSerializer.
val hash: SecureHash by lazy { bits.sha256() }
fun writeToFile(path: Path) = Files.write(path, bits)

View File

@ -65,8 +65,13 @@ class ProgressTracker(vararg steps: Step) {
override val label: String get() = currentLabel
}
object UNSTARTED : Step("Unstarted")
object DONE : Step("Done")
// Sentinel objects. Overrides equals() to survive process restarts and serialization.
object UNSTARTED : Step("Unstarted") {
override fun equals(other: Any?) = other is UNSTARTED
}
object DONE : Step("Done") {
override fun equals(other: Any?) = other is DONE
}
/** The steps in this tracker, same as the steps passed to the constructor but with UNSTARTED and DONE inserted. */
val steps = arrayOf(UNSTARTED, *steps, DONE)