Removed inline from Name due to problems with equality and serialization.

This commit is contained in:
Alexander Nozik 2019-08-17 10:32:58 +03:00
parent 578b4ede21
commit 27c510f5d0

View File

@ -6,10 +6,9 @@ package hep.dataforge.names
* The name is a dot separated list of strings like `token1.token2.token3`. * The name is a dot separated list of strings like `token1.token2.token3`.
* Each token could contain additional index in square brackets. * Each token could contain additional index in square brackets.
*/ */
inline class Name constructor(val tokens: List<NameToken>) { class Name(val tokens: List<NameToken>) {
val length val length get() = tokens.size
get() = tokens.size
/** /**
* First token of the name or null if it is empty * First token of the name or null if it is empty
@ -35,6 +34,23 @@ inline class Name constructor(val tokens: List<NameToken>) {
override fun toString(): String = tokens.joinToString(separator = NAME_SEPARATOR) { it.toString() } override fun toString(): String = tokens.joinToString(separator = NAME_SEPARATOR) { it.toString() }
override fun equals(other: Any?): Boolean {
return when (other) {
is Name -> this.tokens == other.tokens
is NameToken -> this.length == 1 && this.tokens.first() == other
else -> false
}
}
override fun hashCode(): Int {
return if (tokens.size == 1) {
tokens.first().hashCode()
} else {
tokens.hashCode()
}
}
companion object { companion object {
const val NAME_SEPARATOR = "." const val NAME_SEPARATOR = "."
} }