Merge pull request #51 from mipt-npm/dev

0.1.8-dev-4
This commit is contained in:
Alexander Nozik 2020-06-06 21:28:42 +03:00 committed by GitHub
commit f5b2b4c9e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 14 deletions

View File

@ -7,7 +7,7 @@ plugins {
id("org.jetbrains.dokka") version "0.10.1"
}
val dataforgeVersion by extra("0.1.8-dev-2")
val dataforgeVersion by extra("0.1.8-dev-4")
val bintrayRepo by extra("dataforge")
val githubProject by extra("dataforge-core")

View File

@ -16,8 +16,12 @@ import kotlinx.serialization.*
@Serializable
sealed class MetaItem<out M : Meta> {
abstract override fun equals(other: Any?): Boolean
abstract override fun hashCode(): Int
@Serializable
data class ValueItem(val value: Value) : MetaItem<Nothing>() {
class ValueItem(val value: Value) : MetaItem<Nothing>() {
override fun toString(): String = value.toString()
@Serializer(ValueItem::class)
@ -30,10 +34,18 @@ sealed class MetaItem<out M : Meta> {
ValueSerializer.serialize(encoder, value.value)
}
}
override fun equals(other: Any?): Boolean {
return this.value == (other as? ValueItem)?.value
}
override fun hashCode(): Int {
return value.hashCode()
}
}
@Serializable
data class NodeItem<M : Meta>(@Serializable(MetaSerializer::class) val node: M) : MetaItem<M>() {
class NodeItem<M : Meta>(@Serializable(MetaSerializer::class) val node: M) : MetaItem<M>() {
//Fixing serializer for node could cause class cast problems, but it should not since Meta descendants are not serializeable
override fun toString(): String = node.toString()
@ -47,6 +59,10 @@ sealed class MetaItem<out M : Meta> {
MetaSerializer.serialize(encoder, value.node)
}
}
override fun equals(other: Any?): Boolean = node == (other as? NodeItem<*>)?.node
override fun hashCode(): Int = node.hashCode()
}
companion object {

View File

@ -4,7 +4,7 @@ package hep.dataforge.meta.descriptors
* An object which provides its descriptor
*/
interface Described {
val descriptor: NodeDescriptor?
val descriptor: ItemDescriptor?
companion object {
const val DESCRIPTOR_NODE = "@descriptor"

View File

@ -9,13 +9,18 @@ import hep.dataforge.values.*
/**
* A converter of generic object to and from [MetaItem]
*/
interface MetaCaster<T : Any> {
interface MetaConverter<T : Any> {
fun itemToObject(item: MetaItem<*>): T
fun objectToMetaItem(obj: T): MetaItem<*>
companion object {
val meta = object : MetaCaster<Meta> {
val item = object :MetaConverter<MetaItem<*>>{
override fun itemToObject(item: MetaItem<*>): MetaItem<*> = item
override fun objectToMetaItem(obj: MetaItem<*>): MetaItem<*> = obj
}
val meta = object : MetaConverter<Meta> {
override fun itemToObject(item: MetaItem<*>): Meta = when (item) {
is MetaItem.NodeItem -> item.node
is MetaItem.ValueItem -> item.value.toMeta()
@ -24,7 +29,7 @@ interface MetaCaster<T : Any> {
override fun objectToMetaItem(obj: Meta): MetaItem<*> = MetaItem.NodeItem(obj)
}
val value = object : MetaCaster<Value> {
val value = object : MetaConverter<Value> {
override fun itemToObject(item: MetaItem<*>): Value = when (item) {
is MetaItem.NodeItem -> item.node[Meta.VALUE_KEY].value ?: error("Can't convert node to a value")
is MetaItem.ValueItem -> item.value
@ -33,7 +38,7 @@ interface MetaCaster<T : Any> {
override fun objectToMetaItem(obj: Value): MetaItem<*> = MetaItem.ValueItem(obj)
}
val string = object : MetaCaster<String> {
val string = object : MetaConverter<String> {
override fun itemToObject(item: MetaItem<*>): String = when (item) {
is MetaItem.NodeItem -> item.node[Meta.VALUE_KEY].value ?: error("Can't convert node to a value")
is MetaItem.ValueItem -> item.value
@ -42,7 +47,7 @@ interface MetaCaster<T : Any> {
override fun objectToMetaItem(obj: String): MetaItem<*> = MetaItem.ValueItem(obj.asValue())
}
val boolean = object : MetaCaster<Boolean> {
val boolean = object : MetaConverter<Boolean> {
override fun itemToObject(item: MetaItem<*>): Boolean = when (item) {
is MetaItem.NodeItem -> item.node[Meta.VALUE_KEY].value ?: error("Can't convert node to a value")
is MetaItem.ValueItem -> item.value
@ -51,7 +56,7 @@ interface MetaCaster<T : Any> {
override fun objectToMetaItem(obj: Boolean): MetaItem<*> = MetaItem.ValueItem(obj.asValue())
}
val double = object : MetaCaster<Double> {
val double = object : MetaConverter<Double> {
override fun itemToObject(item: MetaItem<*>): Double = when (item) {
is MetaItem.NodeItem -> item.node[Meta.VALUE_KEY].value ?: error("Can't convert node to a value")
is MetaItem.ValueItem -> item.value
@ -60,7 +65,7 @@ interface MetaCaster<T : Any> {
override fun objectToMetaItem(obj: Double): MetaItem<*> = MetaItem.ValueItem(obj.asValue())
}
val int = object : MetaCaster<Int> {
val int = object : MetaConverter<Int> {
override fun itemToObject(item: MetaItem<*>): Int = when (item) {
is MetaItem.NodeItem -> item.node[Meta.VALUE_KEY].value ?: error("Can't convert node to a value")
is MetaItem.ValueItem -> item.value
@ -71,5 +76,5 @@ interface MetaCaster<T : Any> {
}
}
fun <T : Any> MetaCaster<T>.metaToObject(meta: Meta): T = itemToObject(MetaItem.NodeItem(meta))
fun <T : Any> MetaCaster<T>.valueToObject(value: Value): T = itemToObject(MetaItem.ValueItem(value))
fun <T : Any> MetaConverter<T>.metaToObject(meta: Meta): T = itemToObject(MetaItem.NodeItem(meta))
fun <T : Any> MetaConverter<T>.valueToObject(value: Value): T = itemToObject(MetaItem.ValueItem(value))

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2
gradlew vendored
View File

@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath

1
gradlew.bat vendored
View File

@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%