-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: use readers only unless writers are necessary
When writers are necessary, they are attempted to be opened lazily, and cached. H5 backend has slightly different behavior.
- Loading branch information
Showing
6 changed files
with
33 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 8 additions & 24 deletions
32
src/main/kotlin/org/janelia/saalfeldlab/paintera/state/metadata/N5ContainerState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,25 @@ | ||
package org.janelia.saalfeldlab.paintera.state.metadata | ||
|
||
import javafx.beans.property.SimpleObjectProperty | ||
import javafx.beans.value.ObservableValue | ||
import org.apache.commons.lang.builder.HashCodeBuilder | ||
import org.janelia.saalfeldlab.fx.extensions.nonnullVal | ||
import org.janelia.saalfeldlab.fx.extensions.nullableVal | ||
import org.janelia.saalfeldlab.n5.N5Reader | ||
import org.janelia.saalfeldlab.n5.N5Writer | ||
import java.net.URI | ||
import org.janelia.saalfeldlab.paintera.Paintera | ||
|
||
data class N5ContainerState(private val n5Container: N5Reader) { | ||
data class N5ContainerState(val reader: N5Reader) { | ||
|
||
private val readerProperty: ObservableValue<N5Reader> by lazy { SimpleObjectProperty(n5Container) } | ||
val reader by readerProperty.nonnullVal() | ||
|
||
private val writerProperty: ObservableValue<N5Writer?> by lazy { SimpleObjectProperty(n5Container as? N5Writer) } | ||
val writer by writerProperty.nullableVal() | ||
|
||
val uri : URI | ||
get() = reader.uri | ||
val writer by lazy { | ||
(reader as? N5Writer) ?: Paintera.n5Factory.openWriterOrNull(uri.toString()) | ||
} | ||
|
||
val isReadOnly: Boolean | ||
get() = writer == null | ||
val uri by lazy { reader.uri!! } | ||
|
||
override fun equals(other: Any?): Boolean { | ||
return if (other is N5ContainerState) { | ||
/* Equal if we are the same url, and we both either have a writer, or have no writer. */ | ||
uri == other.uri && ((writer == null) == (other.writer == null)) | ||
uri == other.uri | ||
} else { | ||
super.equals(other) | ||
} | ||
} | ||
|
||
override fun hashCode(): Int { | ||
val builder = HashCodeBuilder() | ||
.append(reader.uri) | ||
.append(writer?.uri ?: 0) | ||
return builder.toHashCode() | ||
} | ||
override fun hashCode() = HashCodeBuilder().append(uri).toHashCode() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters