From d562352a03eb5cbe4c5b7818f99fa19f0ab4a4e5 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 18 Mar 2019 20:23:52 +0300 Subject: [PATCH] query in Name renamed to index --- .gitignore | 4 ++-- build.gradle.kts | 2 +- .../commonMain/kotlin/hep/dataforge/meta/Meta.kt | 4 ++-- .../kotlin/hep/dataforge/meta/MutableMeta.kt | 2 +- .../commonMain/kotlin/hep/dataforge/names/Name.kt | 14 +++++++------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 94cef066..89cc712a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ .idea/ *.iws -*/out/** +out/ .gradle -*/build/** +build/ !gradle-wrapper.jar diff --git a/build.gradle.kts b/build.gradle.kts index 71c5da82..22b2e8d8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,7 +40,7 @@ allprojects { } group = "hep.dataforge" - version = "0.1.1-dev-5" + version = "0.1.2-dev-1" // apply bintray configuration apply(from = "${rootProject.rootDir}/gradle/bintray.gradle") diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt index 08b1ba09..a2a158c1 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt @@ -80,8 +80,8 @@ fun Meta.getAll(name: Name): Map> { val (body, query) = name.last()!! val regex = query.toRegex() return (this[name.cutLast()] as? NodeItem<*>)?.node?.items - ?.filter { it.key.body == body && (query.isEmpty() || regex.matches(it.key.query)) } - ?.mapKeys { it.key.query } + ?.filter { it.key.body == body && (query.isEmpty() || regex.matches(it.key.index)) } + ?.mapKeys { it.key.index } ?: emptyMap() } diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt index 788758fa..2e7f452f 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt @@ -154,7 +154,7 @@ fun > M.setIndexed( val tokens = name.tokens.toMutableList() val last = tokens.last() items.forEachIndexed { index, meta -> - val indexedToken = NameToken(last.body, last.query + queryFactory(index)) + val indexedToken = NameToken(last.body, last.index + queryFactory(index)) tokens[tokens.lastIndex] = indexedToken set(Name(tokens), meta) } diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt index 78dba871..d9121af5 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt @@ -4,7 +4,7 @@ package hep.dataforge.names /** * The general interface for working with names. * The name is a dot separated list of strings like `token1.token2.token3`. - * Each token could contain additional query in square brackets. + * Each token could contain additional index in square brackets. */ inline class Name constructor(val tokens: List) { @@ -43,21 +43,21 @@ inline class Name constructor(val tokens: List) { /** * A single name token. Body is not allowed to be empty. * Following symbols are prohibited in name tokens: `{}.:\`. - * A name token could have appendix in square brackets called *query* + * A name token could have appendix in square brackets called *index* */ -data class NameToken(val body: String, val query: String = "") { +data class NameToken(val body: String, val index: String = "") { init { if (body.isEmpty()) error("Syntax error: Name token body is empty") } - override fun toString(): String = if (hasQuery()) { - "$body[$query]" + override fun toString(): String = if (hasIndex()) { + "$body[$index]" } else { body } - fun hasQuery() = query.isNotEmpty() + fun hasIndex() = index.isNotEmpty() } fun String.toName(): Name { @@ -84,7 +84,7 @@ fun String.toName(): Name { '[' -> bracketCount++ ']' -> error("Syntax error: closing bracket ] not have not matching open bracket") else -> { - if (queryBuilder.isNotEmpty()) error("Syntax error: only name end and name separator are allowed after query") + if (queryBuilder.isNotEmpty()) error("Syntax error: only name end and name separator are allowed after index") bodyBuilder.append(it) } }