diff --git a/app/src/androidTest/java/org/bspeice/minimalbible/test/FinalDelegateTest.java b/app/src/androidTest/java/org/bspeice/minimalbible/test/SafeValDelegateTest.java similarity index 80% rename from app/src/androidTest/java/org/bspeice/minimalbible/test/FinalDelegateTest.java rename to app/src/androidTest/java/org/bspeice/minimalbible/test/SafeValDelegateTest.java index a766a74..c4addcf 100644 --- a/app/src/androidTest/java/org/bspeice/minimalbible/test/FinalDelegateTest.java +++ b/app/src/androidTest/java/org/bspeice/minimalbible/test/SafeValDelegateTest.java @@ -1,19 +1,19 @@ package org.bspeice.minimalbible.test; -import org.bspeice.minimalbible.FinalDelegate; import org.bspeice.minimalbible.MBTestCase; +import org.bspeice.minimalbible.SafeValDelegate; import kotlin.PropertyMetadataImpl; /** * Test that the FinalDelegate actually obeys its contract */ -public class FinalDelegateTest extends MBTestCase { +public class SafeValDelegateTest extends MBTestCase { - FinalDelegate delegate; + SafeValDelegate delegate; public void setUp() { - delegate = new FinalDelegate(); + delegate = new SafeValDelegate(); } public void testDelegateNullSafety() { diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/FinalDelegate.kt b/app/src/main/kotlin/org/bspeice/minimalbible/SafeValDelegate.kt similarity index 70% rename from app/src/main/kotlin/org/bspeice/minimalbible/FinalDelegate.kt rename to app/src/main/kotlin/org/bspeice/minimalbible/SafeValDelegate.kt index d8c69dc..67ecced 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/FinalDelegate.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/SafeValDelegate.kt @@ -1,20 +1,22 @@ package org.bspeice.minimalbible +import kotlin.properties.ReadWriteProperty + /** * The purpose of this delegate is to guarantee null-safety, while * also ensuring a pseudo-val type. If you try to read before use, error. * If you try to set multiple times, error. */ -public class FinalDelegate() { +public class SafeValDelegate() : ReadWriteProperty { private var value: T? = null private var didAssign: Boolean = false - public fun get(thisRef: Any?, desc: PropertyMetadata): T { + public override fun get(thisRef: Any?, desc: PropertyMetadata): T { return value ?: throw IllegalStateException("Property ${desc.name} should be initialized before get") } - public fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { + public override fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { if (!didAssign) { this.value = value this.didAssign = true diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt b/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt index 274d4cf..655d5e3 100644 --- a/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt +++ b/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt @@ -5,7 +5,7 @@ import org.crosswire.jsword.passage.Verse import java.util.ArrayDeque import org.xml.sax.Attributes import org.crosswire.jsword.book.OSISUtil -import org.bspeice.minimalbible.FinalDelegate +import org.bspeice.minimalbible.SafeValDelegate /** * Created by bspeice on 9/10/14. @@ -15,7 +15,7 @@ class OsisParser() : DefaultHandler() { // Don't pass a verse as part of the constructor, but still guarantee // that it will exist - public var verse: Verse by FinalDelegate() + public var verse: Verse by SafeValDelegate() val verseContent: VerseContent get() = VerseContent(verse)