From c41dfd0a6b94264903204067a03c504cbd498bc4 Mon Sep 17 00:00:00 2001 From: max-tab Date: Tue, 11 Jul 2017 15:57:53 +0700 Subject: [PATCH 01/29] Add Lenght --- src/main/kotlin/nectec/thai/unit/Length.kt | 26 +++++++++++++++++++ .../nectec/thai/unit/LenghtJavaTest.java | 17 ++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/main/kotlin/nectec/thai/unit/Length.kt create mode 100644 src/test/kotlin/nectec/thai/unit/LenghtJavaTest.java diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt new file mode 100644 index 0000000..8c5a325 --- /dev/null +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -0,0 +1,26 @@ +package nectec.thai.unit + +import javafx.beans.binding.Bindings +import java.lang.StringBuilder + +/** + * Created by user on 11/7/2560. + */ +data class Length (val cm: Double) { + + + val sok: Int + + init { + var sok=cm/50 + + this.sok=sok.toInt() + } + + fun cmtoSok(): String { + + val stringBuilder = StringBuilder() + return stringBuilder.append(sok).append(" ศอก").toString().trim() + } + +} diff --git a/src/test/kotlin/nectec/thai/unit/LenghtJavaTest.java b/src/test/kotlin/nectec/thai/unit/LenghtJavaTest.java new file mode 100644 index 0000000..5cbc264 --- /dev/null +++ b/src/test/kotlin/nectec/thai/unit/LenghtJavaTest.java @@ -0,0 +1,17 @@ +package nectec.thai.unit; + +/** + * Created by user on 11/7/2560. + */ + +import org.junit.Assert; +import org.junit.Test; + +public class LenghtJavaTest { + @Test + public void name() throws Exception { + Length length = new Length(50).copy(100).copy(50); + Assert.assertEquals(1,length.getSok()); + } + +} From 39931500affd30ad3ac5b1acb09e3fe114429f38 Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Wed, 12 Jul 2017 10:49:44 +0700 Subject: [PATCH 02/29] Lenght Be1 --- src/main/kotlin/nectec/thai/unit/Length.kt | 47 +++++++++++++++++-- .../kotlin/nectec/thai/unit/LenghtTest.kt | 25 ++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 src/test/kotlin/nectec/thai/unit/LenghtTest.kt diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 8c5a325..5c21ef1 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -9,18 +9,57 @@ import java.lang.StringBuilder data class Length (val cm: Double) { + val krabiat: Int + val nio: Int + val khuep: Int val sok: Int + val wa: Int + val sen: Int + val yot: Int init { - var sok=cm/50 + var tmp :Double + this.yot=(cm/CENTIMETRE_PER_YOT).toInt() + tmp=(cm%CENTIMETRE_PER_YOT) + this.sen=(tmp/CENTIMETRE_PER_SEN).toInt() + tmp=(tmp%CENTIMETRE_PER_SEN) + this.wa=(tmp/CENTIMETRE_PER_WA).toInt() + tmp=(tmp%CENTIMETRE_PER_WA) + this.sok=(tmp/CENTIMETRE_PER_SOK).toInt() + tmp=(tmp%CENTIMETRE_PER_SOK) + this.khuep=(tmp/CENTIMETRE_PER_KHUEP).toInt() + tmp=(tmp%CENTIMETRE_PER_KHUEP) + this.nio=(tmp/CENTIMETRE_PER_NIO).toInt() + tmp=(tmp%CENTIMETRE_PER_NIO) + this.krabiat=(tmp/CENTIMETRE_PER_KRABIAT).toInt() + tmp=(tmp%CENTIMETRE_PER_KRABIAT) - this.sok=sok.toInt() } - fun cmtoSok(): String { + companion object { + + @JvmField val CENTIMETRE_PER_KRABIAT = 0.5208 + @JvmField val CENTIMETRE_PER_NIO = 2.083 + @JvmField val CENTIMETRE_PER_KHUEP = 25 + @JvmField val CENTIMETRE_PER_SOK = 50 + @JvmField val CENTIMETRE_PER_WA = 200 + @JvmField val CENTIMETRE_PER_SEN = 4000 + @JvmField val CENTIMETRE_PER_YOT = 1600000 + + @JvmField val KRABIAT = " กระเบียด " + @JvmField val NIO = " นิ้ว " + @JvmField val KHUEP = " คืบ " + @JvmField val SOK = " ศอก " + @JvmField val WA = " วา " + @JvmField val SEN = " เส้น " + @JvmField val YOT = " โยชน์ " + + } + + fun prtAll(): String { val stringBuilder = StringBuilder() - return stringBuilder.append(sok).append(" ศอก").toString().trim() + return stringBuilder.append(krabiat).append(KRABIAT).append(nio).append(NIO).append(khuep).append(KHUEP).append(sok).append(SOK).append(wa).append(WA).append(sen).append(SEN).append(yot).append(YOT).toString().trim() } } diff --git a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt new file mode 100644 index 0000000..e69df19 --- /dev/null +++ b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt @@ -0,0 +1,25 @@ +package nectec.thai.unit + +/** + * Created by Max on 12/7/2560. + */ + +import org.junit.Test +import kotlin.test.assertEquals +class LenghtTest { + + val lenght = Length(1200.0) + + + @Test fun getsok() { + assertEquals(0, lenght.sok) + } + + @Test fun getkhup() { + assertEquals(0, lenght.khuep) + } + + @Test fun prtAll() { + assertEquals("dd", lenght.prtAll()) + } +} From cfc682f191d54bb640ac76c24b9bff681511094b Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Wed, 12 Jul 2017 11:16:52 +0700 Subject: [PATCH 03/29] Add Multi Convert... --- src/main/kotlin/nectec/thai/unit/Length.kt | 38 ++++++++++++++++++- .../kotlin/nectec/thai/unit/LenghtTest.kt | 10 ++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 5c21ef1..d244d83 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -1,14 +1,17 @@ package nectec.thai.unit -import javafx.beans.binding.Bindings import java.lang.StringBuilder /** * Created by user on 11/7/2560. */ data class Length (val cm: Double) { + constructor(cm: Number) : this(cm.toDouble()) + //Auto Gen \($1.toDouble\(\)*CENTIMETRE_PER_$2\)+ + constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this((yot.toDouble()*CENTIMETRE_PER_YOT)+(sen.toDouble()*CENTIMETRE_PER_SEN)+(wa.toDouble()*CENTIMETRE_PER_WA)+(sok.toDouble()*CENTIMETRE_PER_SOK)+(khuep.toDouble()*CENTIMETRE_PER_KHUEP)+(nio.toDouble()*CENTIMETRE_PER_NIO)+(krabiat.toDouble()*CENTIMETRE_PER_KRABIAT)) + //Auto Gen val $1: Int val krabiat: Int val nio: Int val khuep: Int @@ -17,10 +20,15 @@ data class Length (val cm: Double) { val sen: Int val yot: Int + + init { + var tmp :Double this.yot=(cm/CENTIMETRE_PER_YOT).toInt() tmp=(cm%CENTIMETRE_PER_YOT) + + //Auto Gen this.$1=\(tmp/CENTIMETRE_PER_$2\).toInt\(\)\r\ntmp=\(tmp%CENTIMETRE_PER_$2\) this.sen=(tmp/CENTIMETRE_PER_SEN).toInt() tmp=(tmp%CENTIMETRE_PER_SEN) this.wa=(tmp/CENTIMETRE_PER_WA).toInt() @@ -38,6 +46,8 @@ data class Length (val cm: Double) { companion object { + + //Auto Gen @JvmField val CENTIMETRE_PER_$1 = xx @JvmField val CENTIMETRE_PER_KRABIAT = 0.5208 @JvmField val CENTIMETRE_PER_NIO = 2.083 @JvmField val CENTIMETRE_PER_KHUEP = 25 @@ -46,6 +56,7 @@ data class Length (val cm: Double) { @JvmField val CENTIMETRE_PER_SEN = 4000 @JvmField val CENTIMETRE_PER_YOT = 1600000 + //Auto Gen @JvmField val $1 = "$2" @JvmField val KRABIAT = " กระเบียด " @JvmField val NIO = " นิ้ว " @JvmField val KHUEP = " คืบ " @@ -56,10 +67,33 @@ data class Length (val cm: Double) { } + fun prtAll(): String { val stringBuilder = StringBuilder() - return stringBuilder.append(krabiat).append(KRABIAT).append(nio).append(NIO).append(khuep).append(KHUEP).append(sok).append(SOK).append(wa).append(WA).append(sen).append(SEN).append(yot).append(YOT).toString().trim() + //Auto Gen .append\($1\).append\($2\) + return stringBuilder.append(yot).append(YOT).append(sen).append(SEN).append(wa).append(WA).append(sok).append(SOK).append(khuep).append(KHUEP).append(nio).append(NIO).append(krabiat).append(KRABIAT).toString().trim() } } + + + +//Auto Gen +/* +yot YOT +sen SEN +wa WA +sok SOK +khuep KHUEP +nio NIO +krabiat KRABIAT + +krabiat KRABIAT +nio NIO +khuep KHUEP +sok SOK +wa WA +sen SEN +yot YOT + */ diff --git a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt index e69df19..22ef1d7 100644 --- a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt +++ b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt @@ -20,6 +20,14 @@ class LenghtTest { } @Test fun prtAll() { - assertEquals("dd", lenght.prtAll()) + assertEquals("0 โยชน์ 0 เส้น 6 วา 0 ศอก 0 คืบ 0 นิ้ว 0 กระเบียด", lenght.prtAll()) } + @Test fun prtAll2() { + assertEquals("10 โยชน์ 1 เส้น 1 วา 1 ศอก 1 คืบ 1 นิ้ว 1 กระเบียด", Length(10,1,1,1,1,1,1).prtAll()) + } + + @Test fun prtAll3() { + assertEquals("10 โยชน์ 7 เส้น 8 วา 0 ศอก 1 คืบ 7 นิ้ว 1 กระเบียด", Length(10,7,6,6,5,7,1).prtAll()) + } + } From 6a31bd5b5e632c3fcd36fedb78cfb132af741b39 Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Thu, 13 Jul 2017 22:21:56 +0700 Subject: [PATCH 04/29] Add Documentation Engine for Kotlin https://github.com/Kotlin/dokka gradlew dokka --- bintray.gradle | 18 ++++++++++++++++++ build.gradle | 1 + 2 files changed, 19 insertions(+) diff --git a/bintray.gradle b/bintray.gradle index 39e8816..48d38cc 100644 --- a/bintray.gradle +++ b/bintray.gradle @@ -1,6 +1,24 @@ +buildscript { + repositories { + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + //https://github.com/Kotlin/dokka + classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.15" + } +} + +apply plugin: "org.jetbrains.dokka" apply plugin: 'com.jfrog.bintray' apply plugin: "maven-publish" +dokka { + outputFormat = 'html' + outputDirectory = "$buildDir/javadoc" +} + bintray { user = project.hasProperty('bintrayUser') ? project.getProperty('bintrayUser') : System.getenv('BINTRAY_USER') ?: '' diff --git a/build.gradle b/build.gradle index 34d5182..658970f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id "org.jetbrains.kotlin.jvm" version '1.1.2-2' id "com.jfrog.bintray" version "1.7.3" + id "org.jetbrains.dokka" version "0.9.15" } group 'th.or.nectec' From 0080a5d6b6ae3b796eda039d6ffc5f0238a7c692 Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Thu, 13 Jul 2017 23:08:38 +0700 Subject: [PATCH 05/29] Config Kotlin & Javadoc gen --- bintray.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bintray.gradle b/bintray.gradle index 48d38cc..09c044c 100644 --- a/bintray.gradle +++ b/bintray.gradle @@ -15,7 +15,11 @@ apply plugin: 'com.jfrog.bintray' apply plugin: "maven-publish" dokka { - outputFormat = 'html' + outputFormat = 'javadoc' + outputDirectory = "$buildDir/javadoc" +} +task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { + outputFormat = 'javadoc' outputDirectory = "$buildDir/javadoc" } From ee7cab58d470fa789a6b558a18cc67987561f8b4 Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Fri, 14 Jul 2017 17:04:01 +0700 Subject: [PATCH 06/29] Test KDOC and JDOC --- src/main/kotlin/nectec/thai/unit/Length.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index d244d83..ddd655c 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -3,11 +3,20 @@ package nectec.thai.unit import java.lang.StringBuilder /** + * Thai length unit. * Created by user on 11/7/2560. */ data class Length (val cm: Double) { + /** + * Create convert object + * @param cm is centimetres SI Ref. https://en.wikipedia.org/wiki/Centimetre/ + * @see http://google.com + */ constructor(cm: Number) : this(cm.toDouble()) + /** + * Create by Thai Unit Length https://en.wikipedia.org/wiki/Thai_units_of_measurement + */ //Auto Gen \($1.toDouble\(\)*CENTIMETRE_PER_$2\)+ constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this((yot.toDouble()*CENTIMETRE_PER_YOT)+(sen.toDouble()*CENTIMETRE_PER_SEN)+(wa.toDouble()*CENTIMETRE_PER_WA)+(sok.toDouble()*CENTIMETRE_PER_SOK)+(khuep.toDouble()*CENTIMETRE_PER_KHUEP)+(nio.toDouble()*CENTIMETRE_PER_NIO)+(krabiat.toDouble()*CENTIMETRE_PER_KRABIAT)) @@ -67,7 +76,10 @@ data class Length (val cm: Double) { } - + /** + * Print standart output. + * @return String "%d โยชน์ %d เส้น %d วา %d ศอก %d คืบ %d นิ้ว %d กระเบียด" + */ fun prtAll(): String { val stringBuilder = StringBuilder() From 8d6523b1554da44967ef987a514c459fc5232c8c Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Mon, 17 Jul 2017 16:18:43 +0700 Subject: [PATCH 07/29] Add zero no print. --- src/test/kotlin/nectec/thai/unit/LenghtTest.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt index 22ef1d7..9089229 100644 --- a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt +++ b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt @@ -30,4 +30,9 @@ class LenghtTest { assertEquals("10 โยชน์ 7 เส้น 8 วา 0 ศอก 1 คืบ 7 นิ้ว 1 กระเบียด", Length(10,7,6,6,5,7,1).prtAll()) } + + @Test fun prtAll4() { + assertEquals("10 โยชน์ 1 คืบ 2 นิ้ว 1 กระเบียด", Length(10,0,0,0,1,2,1).prtAllV2()) + } + } From 22754c786ebd5995a81d5c814f29384b2735a881 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Mon, 17 Jul 2017 16:27:01 +0700 Subject: [PATCH 08/29] Add zero no print. Remove my gradle KDOC --- bintray.gradle | 8 ++--- build.gradle | 2 +- src/main/kotlin/nectec/thai/unit/Length.kt | 35 ++++++++++++++++++---- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/bintray.gradle b/bintray.gradle index 09c044c..f83da7d 100644 --- a/bintray.gradle +++ b/bintray.gradle @@ -1,4 +1,4 @@ -buildscript { +/*buildscript { repositories { maven { url "https://plugins.gradle.org/m2/" @@ -10,18 +10,18 @@ buildscript { } } -apply plugin: "org.jetbrains.dokka" +apply plugin: "org.jetbrains.dokka"*/ apply plugin: 'com.jfrog.bintray' apply plugin: "maven-publish" -dokka { +/*dokka { outputFormat = 'javadoc' outputDirectory = "$buildDir/javadoc" } task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { outputFormat = 'javadoc' outputDirectory = "$buildDir/javadoc" -} +}*/ bintray { user = project.hasProperty('bintrayUser') ? project.getProperty('bintrayUser') : diff --git a/build.gradle b/build.gradle index 658970f..073cf25 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id "org.jetbrains.kotlin.jvm" version '1.1.2-2' id "com.jfrog.bintray" version "1.7.3" - id "org.jetbrains.dokka" version "0.9.15" + //id "org.jetbrains.dokka" version "0.9.15" } group 'th.or.nectec' diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index ddd655c..0cf27ca 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -1,6 +1,9 @@ package nectec.thai.unit import java.lang.StringBuilder +import java.text.NumberFormat + + /** * Thai length unit. @@ -21,7 +24,7 @@ data class Length (val cm: Double) { constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this((yot.toDouble()*CENTIMETRE_PER_YOT)+(sen.toDouble()*CENTIMETRE_PER_SEN)+(wa.toDouble()*CENTIMETRE_PER_WA)+(sok.toDouble()*CENTIMETRE_PER_SOK)+(khuep.toDouble()*CENTIMETRE_PER_KHUEP)+(nio.toDouble()*CENTIMETRE_PER_NIO)+(krabiat.toDouble()*CENTIMETRE_PER_KRABIAT)) //Auto Gen val $1: Int - val krabiat: Int + val krabiat: Double val nio: Int val khuep: Int val sok: Int @@ -29,10 +32,14 @@ data class Length (val cm: Double) { val sen: Int val yot: Int - + val nf = NumberFormat.getNumberInstance() init { + + nf.maximumFractionDigits=0 + nf.roundingMode=java.math.RoundingMode.DOWN + var tmp :Double this.yot=(cm/CENTIMETRE_PER_YOT).toInt() tmp=(cm%CENTIMETRE_PER_YOT) @@ -48,8 +55,15 @@ data class Length (val cm: Double) { tmp=(tmp%CENTIMETRE_PER_KHUEP) this.nio=(tmp/CENTIMETRE_PER_NIO).toInt() tmp=(tmp%CENTIMETRE_PER_NIO) - this.krabiat=(tmp/CENTIMETRE_PER_KRABIAT).toInt() - tmp=(tmp%CENTIMETRE_PER_KRABIAT) + + this.krabiat=((tmp/CENTIMETRE_PER_KRABIAT)+(tmp%CENTIMETRE_PER_KRABIAT)) + + + + //nf.setMaximumFractionDigits(0) + //nf.setRoundingMode(RoundingMode.UP) + + //tmp=(tmp%CENTIMETRE_PER_KRABIAT) } @@ -58,7 +72,7 @@ data class Length (val cm: Double) { //Auto Gen @JvmField val CENTIMETRE_PER_$1 = xx @JvmField val CENTIMETRE_PER_KRABIAT = 0.5208 - @JvmField val CENTIMETRE_PER_NIO = 2.083 + @JvmField val CENTIMETRE_PER_NIO = 2.0//83 @JvmField val CENTIMETRE_PER_KHUEP = 25 @JvmField val CENTIMETRE_PER_SOK = 50 @JvmField val CENTIMETRE_PER_WA = 200 @@ -84,7 +98,16 @@ data class Length (val cm: Double) { val stringBuilder = StringBuilder() //Auto Gen .append\($1\).append\($2\) - return stringBuilder.append(yot).append(YOT).append(sen).append(SEN).append(wa).append(WA).append(sok).append(SOK).append(khuep).append(KHUEP).append(nio).append(NIO).append(krabiat).append(KRABIAT).toString().trim() + return stringBuilder.append(yot).append(YOT).append(sen).append(SEN).append(wa).append(WA).append(sok).append(SOK).append(khuep).append(KHUEP).append(nio).append(NIO).append(nf.format(krabiat)).append(KRABIAT).toString().trim() + } + + /** + * Zero No Print + */ + fun prtAllV2(): String { + val stringBuilder = StringBuilder() + //Auto Gen .append\($1\).append\($2\) + return stringBuilder.append(when(yot) {0-> "" else -> yot.toString()+YOT } ).append(when(sen) {0-> "" else -> sen.toString()+SEN } ).append(when(wa) {0-> "" else -> wa.toString()+WA } ).append(when(sok) {0-> "" else -> sok.toString()+SOK } ).append(when(khuep) {0-> "" else -> khuep.toString()+KHUEP } ).append(when(nio) {0-> "" else -> nio.toString()+NIO } ).append(when(krabiat) {0.0-> "" else -> nf.format(krabiat)+KRABIAT } ).toString().trim() } } From 8000ae5b9fe22c522d01b2659312739219636034 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Mon, 17 Jul 2017 16:35:06 +0700 Subject: [PATCH 09/29] Pool --- src/test/kotlin/nectec/thai/unit/LenghtTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt index 9089229..1d9172d 100644 --- a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt +++ b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt @@ -30,7 +30,7 @@ class LenghtTest { assertEquals("10 โยชน์ 7 เส้น 8 วา 0 ศอก 1 คืบ 7 นิ้ว 1 กระเบียด", Length(10,7,6,6,5,7,1).prtAll()) } - +//Test @Test fun prtAll4() { assertEquals("10 โยชน์ 1 คืบ 2 นิ้ว 1 กระเบียด", Length(10,0,0,0,1,2,1).prtAllV2()) } From e860d61753ef811bd4a4ad097796cb1ccf78ded9 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 19 Jul 2017 11:05:39 +0700 Subject: [PATCH 10/29] Clean Code. --- src/main/kotlin/nectec/thai/unit/Length.kt | 80 ++++++++----------- .../kotlin/nectec/thai/unit/LenghtTest.kt | 13 +-- 2 files changed, 36 insertions(+), 57 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 0cf27ca..6ef35d8 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -4,22 +4,17 @@ import java.lang.StringBuilder import java.text.NumberFormat - /** * Thai length unit. * Created by user on 11/7/2560. */ data class Length (val cm: Double) { - /** - * Create convert object - * @param cm is centimetres SI Ref. https://en.wikipedia.org/wiki/Centimetre/ - * @see http://google.com - */ - constructor(cm: Number) : this(cm.toDouble()) + /** - * Create by Thai Unit Length https://en.wikipedia.org/wiki/Thai_units_of_measurement + * Create convert object */ + constructor(centimetres: Number) : this(centimetres.toDouble()) //Auto Gen \($1.toDouble\(\)*CENTIMETRE_PER_$2\)+ constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this((yot.toDouble()*CENTIMETRE_PER_YOT)+(sen.toDouble()*CENTIMETRE_PER_SEN)+(wa.toDouble()*CENTIMETRE_PER_WA)+(sok.toDouble()*CENTIMETRE_PER_SOK)+(khuep.toDouble()*CENTIMETRE_PER_KHUEP)+(nio.toDouble()*CENTIMETRE_PER_NIO)+(krabiat.toDouble()*CENTIMETRE_PER_KRABIAT)) @@ -32,44 +27,44 @@ data class Length (val cm: Double) { val sen: Int val yot: Int - val nf = NumberFormat.getNumberInstance() + val number_format = NumberFormat.getNumberInstance() init { + var temp_value :Double - nf.maximumFractionDigits=0 - nf.roundingMode=java.math.RoundingMode.DOWN + //Number rounding format. + number_format.maximumFractionDigits=0 + number_format.roundingMode=java.math.RoundingMode.DOWN - var tmp :Double + //Convert centimetres to thai unit. YOT->SEN->WA->SOK->KHUEP->NIO->KRABIAT this.yot=(cm/CENTIMETRE_PER_YOT).toInt() - tmp=(cm%CENTIMETRE_PER_YOT) + temp_value=(cm%CENTIMETRE_PER_YOT) + + //Auto Gen this.$1=\(temp_value/CENTIMETRE_PER_$2\).toInt\(\)\r\ntemp_value=\(temp_value%CENTIMETRE_PER_$2\) + this.sen=(temp_value/CENTIMETRE_PER_SEN).toInt() + temp_value=(temp_value%CENTIMETRE_PER_SEN) - //Auto Gen this.$1=\(tmp/CENTIMETRE_PER_$2\).toInt\(\)\r\ntmp=\(tmp%CENTIMETRE_PER_$2\) - this.sen=(tmp/CENTIMETRE_PER_SEN).toInt() - tmp=(tmp%CENTIMETRE_PER_SEN) - this.wa=(tmp/CENTIMETRE_PER_WA).toInt() - tmp=(tmp%CENTIMETRE_PER_WA) - this.sok=(tmp/CENTIMETRE_PER_SOK).toInt() - tmp=(tmp%CENTIMETRE_PER_SOK) - this.khuep=(tmp/CENTIMETRE_PER_KHUEP).toInt() - tmp=(tmp%CENTIMETRE_PER_KHUEP) - this.nio=(tmp/CENTIMETRE_PER_NIO).toInt() - tmp=(tmp%CENTIMETRE_PER_NIO) + this.wa=(temp_value/CENTIMETRE_PER_WA).toInt() + temp_value=(temp_value%CENTIMETRE_PER_WA) - this.krabiat=((tmp/CENTIMETRE_PER_KRABIAT)+(tmp%CENTIMETRE_PER_KRABIAT)) + this.sok=(temp_value/CENTIMETRE_PER_SOK).toInt() + temp_value=(temp_value%CENTIMETRE_PER_SOK) + this.khuep=(temp_value/CENTIMETRE_PER_KHUEP).toInt() + temp_value=(temp_value%CENTIMETRE_PER_KHUEP) + this.nio=(temp_value/CENTIMETRE_PER_NIO).toInt() + temp_value=(temp_value%CENTIMETRE_PER_NIO) - //nf.setMaximumFractionDigits(0) - //nf.setRoundingMode(RoundingMode.UP) + this.krabiat=((temp_value/CENTIMETRE_PER_KRABIAT)+(temp_value%CENTIMETRE_PER_KRABIAT)) - //tmp=(tmp%CENTIMETRE_PER_KRABIAT) } companion object { - + //Ref. https://en.wikipedia.org/wiki/Thai_units_of_measurement //Auto Gen @JvmField val CENTIMETRE_PER_$1 = xx @JvmField val CENTIMETRE_PER_KRABIAT = 0.5208 @JvmField val CENTIMETRE_PER_NIO = 2.0//83 @@ -90,26 +85,19 @@ data class Length (val cm: Double) { } - /** - * Print standart output. - * @return String "%d โยชน์ %d เส้น %d วา %d ศอก %d คืบ %d นิ้ว %d กระเบียด" - */ - fun prtAll(): String { - - val stringBuilder = StringBuilder() - //Auto Gen .append\($1\).append\($2\) - return stringBuilder.append(yot).append(YOT).append(sen).append(SEN).append(wa).append(WA).append(sok).append(SOK).append(khuep).append(KHUEP).append(nio).append(NIO).append(nf.format(krabiat)).append(KRABIAT).toString().trim() - } - - /** - * Zero No Print - */ - fun prtAllV2(): String { + fun formalPrint(): String { val stringBuilder = StringBuilder() //Auto Gen .append\($1\).append\($2\) - return stringBuilder.append(when(yot) {0-> "" else -> yot.toString()+YOT } ).append(when(sen) {0-> "" else -> sen.toString()+SEN } ).append(when(wa) {0-> "" else -> wa.toString()+WA } ).append(when(sok) {0-> "" else -> sok.toString()+SOK } ).append(when(khuep) {0-> "" else -> khuep.toString()+KHUEP } ).append(when(nio) {0-> "" else -> nio.toString()+NIO } ).append(when(krabiat) {0.0-> "" else -> nf.format(krabiat)+KRABIAT } ).toString().trim() + return stringBuilder + .append(when(yot) {0-> "" else -> yot.toString()+YOT } ) + .append(when(sen) {0-> "" else -> sen.toString()+SEN } ) + .append(when(wa) {0-> "" else -> wa.toString()+WA } ) + .append(when(sok) {0-> "" else -> sok.toString()+SOK } ) + .append(when(khuep) {0-> "" else -> khuep.toString()+KHUEP } ) + .append(when(nio) {0-> "" else -> nio.toString()+NIO } ) + .append(when(krabiat) {0.0-> "" else -> number_format.format(krabiat)+KRABIAT } ) + .toString().trim() } - } diff --git a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt index 1d9172d..25d1024 100644 --- a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt +++ b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt @@ -19,20 +19,11 @@ class LenghtTest { assertEquals(0, lenght.khuep) } - @Test fun prtAll() { - assertEquals("0 โยชน์ 0 เส้น 6 วา 0 ศอก 0 คืบ 0 นิ้ว 0 กระเบียด", lenght.prtAll()) - } - @Test fun prtAll2() { - assertEquals("10 โยชน์ 1 เส้น 1 วา 1 ศอก 1 คืบ 1 นิ้ว 1 กระเบียด", Length(10,1,1,1,1,1,1).prtAll()) - } - - @Test fun prtAll3() { - assertEquals("10 โยชน์ 7 เส้น 8 วา 0 ศอก 1 คืบ 7 นิ้ว 1 กระเบียด", Length(10,7,6,6,5,7,1).prtAll()) - } //Test @Test fun prtAll4() { - assertEquals("10 โยชน์ 1 คืบ 2 นิ้ว 1 กระเบียด", Length(10,0,0,0,1,2,1).prtAllV2()) + assertEquals("10 โยชน์ 1 คืบ 2 นิ้ว 1 กระเบียด", Length(10,0,0,0,1,2,1).formalPrint()) } + } From a57ab5b0470db41660c7f1e0e8dd6954459ef539 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 19 Jul 2017 11:38:25 +0700 Subject: [PATCH 11/29] Clean Code. --- src/main/kotlin/nectec/thai/unit/Length.kt | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 6ef35d8..c1f7432 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -8,15 +8,15 @@ import java.text.NumberFormat * Thai length unit. * Created by user on 11/7/2560. */ -data class Length (val cm: Double) { +data class Length (val centimetres: Double) { /** * Create convert object */ constructor(centimetres: Number) : this(centimetres.toDouble()) - //Auto Gen \($1.toDouble\(\)*CENTIMETRE_PER_$2\)+ - constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this((yot.toDouble()*CENTIMETRE_PER_YOT)+(sen.toDouble()*CENTIMETRE_PER_SEN)+(wa.toDouble()*CENTIMETRE_PER_WA)+(sok.toDouble()*CENTIMETRE_PER_SOK)+(khuep.toDouble()*CENTIMETRE_PER_KHUEP)+(nio.toDouble()*CENTIMETRE_PER_NIO)+(krabiat.toDouble()*CENTIMETRE_PER_KRABIAT)) + + constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this(toCentimetres(yot, sen, wa, sok, khuep, nio, krabiat)) //Auto Gen val $1: Int val krabiat: Double @@ -38,8 +38,8 @@ data class Length (val cm: Double) { number_format.roundingMode=java.math.RoundingMode.DOWN //Convert centimetres to thai unit. YOT->SEN->WA->SOK->KHUEP->NIO->KRABIAT - this.yot=(cm/CENTIMETRE_PER_YOT).toInt() - temp_value=(cm%CENTIMETRE_PER_YOT) + this.yot=(centimetres /CENTIMETRE_PER_YOT).toInt() + temp_value=(centimetres %CENTIMETRE_PER_YOT) //Auto Gen this.$1=\(temp_value/CENTIMETRE_PER_$2\).toInt\(\)\r\ntemp_value=\(temp_value%CENTIMETRE_PER_$2\) this.sen=(temp_value/CENTIMETRE_PER_SEN).toInt() @@ -83,6 +83,18 @@ data class Length (val cm: Double) { @JvmField val SEN = " เส้น " @JvmField val YOT = " โยชน์ " + private fun toCentimetres(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number):Number{ + return + + + //Auto Gen \($1.toDouble\(\)*CENTIMETRE_PER_$2\)+ + (yot.toDouble()*CENTIMETRE_PER_YOT)+ + (sen.toDouble()*CENTIMETRE_PER_SEN)+ + (wa.toDouble()*CENTIMETRE_PER_WA)+ + (sok.toDouble()*CENTIMETRE_PER_SOK)+ + (khuep.toDouble()*CENTIMETRE_PER_KHUEP)+ + (nio.toDouble()*CENTIMETRE_PER_NIO)+ + (krabiat.toDouble()*CENTIMETRE_PER_KRABIAT) + } } fun formalPrint(): String { From 60c9e41a5287fbd552eddde1619c28a6e29dc87c Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 19 Jul 2017 15:25:10 +0700 Subject: [PATCH 12/29] Clean Code. --- src/main/kotlin/nectec/thai/unit/Length.kt | 63 ++++++++++++------- .../kotlin/nectec/thai/unit/LenghtTest.kt | 21 +++++-- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index c1f7432..63a3263 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -6,19 +6,15 @@ import java.text.NumberFormat /** * Thai length unit. - * Created by user on 11/7/2560. + * Ref. https://en.wikipedia.org/wiki/Thai_units_of_measurement + * Created by max on 11/7/2560. */ data class Length (val centimetres: Double) { - - /** - * Create convert object - */ constructor(centimetres: Number) : this(centimetres.toDouble()) - constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this(toCentimetres(yot, sen, wa, sok, khuep, nio, krabiat)) - //Auto Gen val $1: Int + //Auto RegEx Output val $1: Int val krabiat: Double val nio: Int val khuep: Int @@ -27,21 +23,21 @@ data class Length (val centimetres: Double) { val sen: Int val yot: Int - val number_format = NumberFormat.getNumberInstance() + val rounding_number_format = NumberFormat.getNumberInstance() init { var temp_value :Double //Number rounding format. - number_format.maximumFractionDigits=0 - number_format.roundingMode=java.math.RoundingMode.DOWN + rounding_number_format.maximumFractionDigits=0 + rounding_number_format.roundingMode=java.math.RoundingMode.DOWN //Convert centimetres to thai unit. YOT->SEN->WA->SOK->KHUEP->NIO->KRABIAT this.yot=(centimetres /CENTIMETRE_PER_YOT).toInt() temp_value=(centimetres %CENTIMETRE_PER_YOT) - //Auto Gen this.$1=\(temp_value/CENTIMETRE_PER_$2\).toInt\(\)\r\ntemp_value=\(temp_value%CENTIMETRE_PER_$2\) + //Auto RegEx Output this.$1=\(temp_value/CENTIMETRE_PER_$2\).toInt\(\)\r\ntemp_value=\(temp_value%CENTIMETRE_PER_$2\) this.sen=(temp_value/CENTIMETRE_PER_SEN).toInt() temp_value=(temp_value%CENTIMETRE_PER_SEN) @@ -58,14 +54,12 @@ data class Length (val centimetres: Double) { temp_value=(temp_value%CENTIMETRE_PER_NIO) this.krabiat=((temp_value/CENTIMETRE_PER_KRABIAT)+(temp_value%CENTIMETRE_PER_KRABIAT)) - - } companion object { //Ref. https://en.wikipedia.org/wiki/Thai_units_of_measurement - //Auto Gen @JvmField val CENTIMETRE_PER_$1 = xx + //Auto RegEx Output @JvmField val CENTIMETRE_PER_$1 = xx @JvmField val CENTIMETRE_PER_KRABIAT = 0.5208 @JvmField val CENTIMETRE_PER_NIO = 2.0//83 @JvmField val CENTIMETRE_PER_KHUEP = 25 @@ -74,7 +68,7 @@ data class Length (val centimetres: Double) { @JvmField val CENTIMETRE_PER_SEN = 4000 @JvmField val CENTIMETRE_PER_YOT = 1600000 - //Auto Gen @JvmField val $1 = "$2" + //Auto RegEx Output @JvmField val $1 = "$2" @JvmField val KRABIAT = " กระเบียด " @JvmField val NIO = " นิ้ว " @JvmField val KHUEP = " คืบ " @@ -86,7 +80,7 @@ data class Length (val centimetres: Double) { private fun toCentimetres(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number):Number{ return + - //Auto Gen \($1.toDouble\(\)*CENTIMETRE_PER_$2\)+ + //Auto RegEx Output \($1.toDouble\(\)*CENTIMETRE_PER_$2\)+ (yot.toDouble()*CENTIMETRE_PER_YOT)+ (sen.toDouble()*CENTIMETRE_PER_SEN)+ (wa.toDouble()*CENTIMETRE_PER_WA)+ @@ -97,25 +91,51 @@ data class Length (val centimetres: Double) { } } + /** + * Print All + * Exam create object input Length(10,0,0,0,1,2,1) + * formalPrintAll output = 10 โยชน์ 0 เส้น 0 วา 0 ศอก 1 คืบ 2 นิ้ว 1 กระเบียด + */ + fun formalPrintAll(): String { + val stringBuilder = StringBuilder() + return stringBuilder + //Auto RegEx Output .append\($1\).append\($2\) + .append(yot).append(YOT) + .append(sen).append(SEN) + .append(wa).append(WA) + .append(sok).append(SOK) + .append(khuep).append(KHUEP) + .append(nio).append(NIO) + .append(rounding_number_format.format(krabiat)).append(KRABIAT) + .toString().trim() + } + + /** + * Zero value no print. + * Exam create object input Length(10,0,0,0,1,2,1) + * formalPrint output = 10 โยชน์ 1 คืบ 2 นิ้ว 1 กระเบียด + */ fun formalPrint(): String { val stringBuilder = StringBuilder() - //Auto Gen .append\($1\).append\($2\) return stringBuilder + //Auto RegEx Output .append\(when\($1\) {0-> "" else -> $1.toString\(\)+$2 } \) .append(when(yot) {0-> "" else -> yot.toString()+YOT } ) .append(when(sen) {0-> "" else -> sen.toString()+SEN } ) .append(when(wa) {0-> "" else -> wa.toString()+WA } ) .append(when(sok) {0-> "" else -> sok.toString()+SOK } ) .append(when(khuep) {0-> "" else -> khuep.toString()+KHUEP } ) .append(when(nio) {0-> "" else -> nio.toString()+NIO } ) - .append(when(krabiat) {0.0-> "" else -> number_format.format(krabiat)+KRABIAT } ) + .append(when(krabiat) {0.0-> "" else -> rounding_number_format.format(krabiat)+KRABIAT } ) .toString().trim() } } - -//Auto Gen /* +RegEx Gen Code + +^(.+)\t(.+)$ + yot YOT sen SEN wa WA @@ -123,7 +143,7 @@ sok SOK khuep KHUEP nio NIO krabiat KRABIAT - +------------------- krabiat KRABIAT nio NIO khuep KHUEP @@ -131,4 +151,5 @@ sok SOK wa WA sen SEN yot YOT +----------------- */ diff --git a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt index 25d1024..368d831 100644 --- a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt +++ b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt @@ -11,17 +11,30 @@ class LenghtTest { val lenght = Length(1200.0) - @Test fun getsok() { + @Test fun sokvalue() { assertEquals(0, lenght.sok) } - @Test fun getkhup() { + @Test fun khupvalue() { assertEquals(0, lenght.khuep) } + @Test fun formalPrintAll1() { + assertEquals("0 โยชน์ 0 เส้น 6 วา 0 ศอก 0 คืบ 0 นิ้ว 0 กระเบียด", lenght.formalPrintAll()) + } + @Test fun formalPrintAll2() { + assertEquals("10 โยชน์ 1 เส้น 1 วา 1 ศอก 1 คืบ 1 นิ้ว 1 กระเบียด", Length(10,1,1,1,1,1,1).formalPrintAll()) + } + + @Test fun formalPrintAll3() { + assertEquals("10 โยชน์ 7 เส้น 8 วา 0 ศอก 1 คืบ 7 นิ้ว 1 กระเบียด", Length(10,7,6,6,5,7,1).formalPrintAll()) + } + + @Test fun formalPrintAll4() { + assertEquals("10 โยชน์ 0 เส้น 0 วา 0 ศอก 1 คืบ 2 นิ้ว 1 กระเบียด", Length(10,0,0,0,1,2,1).formalPrintAll()) + } -//Test - @Test fun prtAll4() { + @Test fun formalPrint() { assertEquals("10 โยชน์ 1 คืบ 2 นิ้ว 1 กระเบียด", Length(10,0,0,0,1,2,1).formalPrint()) } From 664dc117b885fb5417ff30b40b638a7b2374d11c Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 19 Jul 2017 15:33:26 +0700 Subject: [PATCH 13/29] Iss bug comment --- src/main/kotlin/nectec/thai/unit/Length.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 63a3263..c47b322 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -61,7 +61,7 @@ data class Length (val centimetres: Double) { //Ref. https://en.wikipedia.org/wiki/Thai_units_of_measurement //Auto RegEx Output @JvmField val CENTIMETRE_PER_$1 = xx @JvmField val CENTIMETRE_PER_KRABIAT = 0.5208 - @JvmField val CENTIMETRE_PER_NIO = 2.0//83 + @JvmField val CENTIMETRE_PER_NIO = 2.083 @JvmField val CENTIMETRE_PER_KHUEP = 25 @JvmField val CENTIMETRE_PER_SOK = 50 @JvmField val CENTIMETRE_PER_WA = 200 From 32ed440b0ce6eecf6100d72eca91952ea91178d8 Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Fri, 21 Jul 2017 02:10:26 +0700 Subject: [PATCH 14/29] iss condition formalPrint --- src/main/kotlin/nectec/thai/unit/Length.kt | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index c47b322..f4f9c17 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -118,14 +118,14 @@ data class Length (val centimetres: Double) { fun formalPrint(): String { val stringBuilder = StringBuilder() return stringBuilder - //Auto RegEx Output .append\(when\($1\) {0-> "" else -> $1.toString\(\)+$2 } \) - .append(when(yot) {0-> "" else -> yot.toString()+YOT } ) - .append(when(sen) {0-> "" else -> sen.toString()+SEN } ) - .append(when(wa) {0-> "" else -> wa.toString()+WA } ) - .append(when(sok) {0-> "" else -> sok.toString()+SOK } ) - .append(when(khuep) {0-> "" else -> khuep.toString()+KHUEP } ) - .append(when(nio) {0-> "" else -> nio.toString()+NIO } ) - .append(when(krabiat) {0.0-> "" else -> rounding_number_format.format(krabiat)+KRABIAT } ) + //Auto RegEx Output .append\(if \($1>0\){$1.toString\(\)+$2}else{""} \) + .append(if (yot>0){yot.toString()+YOT}else{""} ) + .append(if (sen>0){sen.toString()+SEN}else{""} ) + .append(if (wa>0){wa.toString()+WA}else{""} ) + .append(if (sok>0){sok.toString()+SOK}else{""} ) + .append(if (khuep>0){khuep.toString()+KHUEP}else{""} ) + .append(if (nio>0){nio.toString()+NIO}else{""} ) + .append(if (krabiat>0){rounding_number_format.format(krabiat)+KRABIAT}else{""} ) .toString().trim() } } @@ -152,4 +152,11 @@ wa WA sen SEN yot YOT ----------------- +KRABIAT กระเบียด +NIO นิ้ว +KHUEP คืบ +SOK ศอก +WA วา +SEN เส้น +YOT โยชน์ */ From daa39312c73982df3cd3702ed196c3b4d544b790 Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Sat, 22 Jul 2017 12:03:48 +0700 Subject: [PATCH 15/29] use BigDecimal --- src/main/kotlin/nectec/thai/unit/Length.kt | 80 ++++++++++--------- .../nectec/thai/unit/LenghtJavaTest.java | 5 +- .../kotlin/nectec/thai/unit/LenghtTest.kt | 10 ++- 3 files changed, 56 insertions(+), 39 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index f4f9c17..3efafaa 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -1,6 +1,7 @@ package nectec.thai.unit import java.lang.StringBuilder +import java.math.BigDecimal import java.text.NumberFormat @@ -9,12 +10,16 @@ import java.text.NumberFormat * Ref. https://en.wikipedia.org/wiki/Thai_units_of_measurement * Created by max on 11/7/2560. */ -data class Length (val centimetres: Double) { +data class Length (val centimetres: BigDecimal) { + + constructor(centimetres: Number) : this(BigDecimal(centimetres.toDouble())) + constructor(centimetres: Double) : this(BigDecimal(centimetres)) - constructor(centimetres: Number) : this(centimetres.toDouble()) constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this(toCentimetres(yot, sen, wa, sok, khuep, nio, krabiat)) //Auto RegEx Output val $1: Int + + val krabiat: Double val nio: Int val khuep: Int @@ -23,37 +28,36 @@ data class Length (val centimetres: Double) { val sen: Int val yot: Int - val rounding_number_format = NumberFormat.getNumberInstance() + val rounding_number_format :NumberFormat init { - var temp_value :Double - //Number rounding format. + rounding_number_format = NumberFormat.getNumberInstance() rounding_number_format.maximumFractionDigits=0 rounding_number_format.roundingMode=java.math.RoundingMode.DOWN - //Convert centimetres to thai unit. YOT->SEN->WA->SOK->KHUEP->NIO->KRABIAT - this.yot=(centimetres /CENTIMETRE_PER_YOT).toInt() - temp_value=(centimetres %CENTIMETRE_PER_YOT) - - //Auto RegEx Output this.$1=\(temp_value/CENTIMETRE_PER_$2\).toInt\(\)\r\ntemp_value=\(temp_value%CENTIMETRE_PER_$2\) - this.sen=(temp_value/CENTIMETRE_PER_SEN).toInt() - temp_value=(temp_value%CENTIMETRE_PER_SEN) + var temp_value :BigDecimal - this.wa=(temp_value/CENTIMETRE_PER_WA).toInt() - temp_value=(temp_value%CENTIMETRE_PER_WA) - this.sok=(temp_value/CENTIMETRE_PER_SOK).toInt() - temp_value=(temp_value%CENTIMETRE_PER_SOK) - - this.khuep=(temp_value/CENTIMETRE_PER_KHUEP).toInt() - temp_value=(temp_value%CENTIMETRE_PER_KHUEP) - - this.nio=(temp_value/CENTIMETRE_PER_NIO).toInt() - temp_value=(temp_value%CENTIMETRE_PER_NIO) - - this.krabiat=((temp_value/CENTIMETRE_PER_KRABIAT)+(temp_value%CENTIMETRE_PER_KRABIAT)) + //Convert centimetres to thai unit. YOT->SEN->WA->SOK->KHUEP->NIO->KRABIAT + this.yot=centimetres.divide(BigDecimal(CENTIMETRE_PER_YOT)).toInt() + temp_value=centimetres.remainder(BigDecimal(CENTIMETRE_PER_YOT)) + + + //Auto RegEx Output this.$1=\(temp_value.toDouble\(\)/CENTIMETRE_PER_$2\).toInt\(\)\r\ntemp_value=temp_value.remainder\(BigDecimal\(CENTIMETRE_PER_$2\)\) + this.sen=(temp_value.toDouble()/CENTIMETRE_PER_SEN).toInt() + temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_SEN)) + this.wa=(temp_value.toDouble()/CENTIMETRE_PER_WA).toInt() + temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_WA)) + this.sok=(temp_value.toDouble()/CENTIMETRE_PER_SOK).toInt() + temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_SOK)) + this.khuep=(temp_value.toDouble()/CENTIMETRE_PER_KHUEP).toInt() + temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KHUEP)) + this.nio=(temp_value.toDouble()/CENTIMETRE_PER_NIO).toInt() + temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_NIO)) + this.krabiat=(temp_value.toDouble()/CENTIMETRE_PER_KRABIAT) + temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) } companion object { @@ -77,17 +81,19 @@ data class Length (val centimetres: Double) { @JvmField val SEN = " เส้น " @JvmField val YOT = " โยชน์ " - private fun toCentimetres(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number):Number{ - return + - - //Auto RegEx Output \($1.toDouble\(\)*CENTIMETRE_PER_$2\)+ - (yot.toDouble()*CENTIMETRE_PER_YOT)+ - (sen.toDouble()*CENTIMETRE_PER_SEN)+ - (wa.toDouble()*CENTIMETRE_PER_WA)+ - (sok.toDouble()*CENTIMETRE_PER_SOK)+ - (khuep.toDouble()*CENTIMETRE_PER_KHUEP)+ - (nio.toDouble()*CENTIMETRE_PER_NIO)+ - (krabiat.toDouble()*CENTIMETRE_PER_KRABIAT) + private fun toCentimetres(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number):BigDecimal{ + var temp_value : BigDecimal + temp_value= BigDecimal((yot.toDouble()*CENTIMETRE_PER_YOT)) + + //Auto RegEx Output temp_value = temp_value.add\(BigDecimal\(\($1.toDouble\(\)*CENTIMETRE_PER_$2\)\)\) + temp_value = temp_value.add(BigDecimal((sen.toDouble()*CENTIMETRE_PER_SEN))) + temp_value = temp_value.add(BigDecimal((wa.toDouble()*CENTIMETRE_PER_WA))) + temp_value = temp_value.add(BigDecimal((sok.toDouble()*CENTIMETRE_PER_SOK))) + temp_value = temp_value.add(BigDecimal((khuep.toDouble()*CENTIMETRE_PER_KHUEP))) + temp_value = temp_value.add(BigDecimal((nio.toDouble()*CENTIMETRE_PER_NIO))) + temp_value = temp_value.add(BigDecimal((krabiat.toDouble()*CENTIMETRE_PER_KRABIAT))) + + return temp_value } } @@ -106,7 +112,7 @@ data class Length (val centimetres: Double) { .append(sok).append(SOK) .append(khuep).append(KHUEP) .append(nio).append(NIO) - .append(rounding_number_format.format(krabiat)).append(KRABIAT) + .append(krabiat).append(KRABIAT) .toString().trim() } @@ -125,7 +131,7 @@ data class Length (val centimetres: Double) { .append(if (sok>0){sok.toString()+SOK}else{""} ) .append(if (khuep>0){khuep.toString()+KHUEP}else{""} ) .append(if (nio>0){nio.toString()+NIO}else{""} ) - .append(if (krabiat>0){rounding_number_format.format(krabiat)+KRABIAT}else{""} ) + .append(if (krabiat>0){krabiat.toString()+KRABIAT}else{""} ) .toString().trim() } } diff --git a/src/test/kotlin/nectec/thai/unit/LenghtJavaTest.java b/src/test/kotlin/nectec/thai/unit/LenghtJavaTest.java index 5cbc264..ea8f13d 100644 --- a/src/test/kotlin/nectec/thai/unit/LenghtJavaTest.java +++ b/src/test/kotlin/nectec/thai/unit/LenghtJavaTest.java @@ -7,10 +7,13 @@ import org.junit.Assert; import org.junit.Test; +import java.math.BigDecimal; + public class LenghtJavaTest { @Test public void name() throws Exception { - Length length = new Length(50).copy(100).copy(50); + //Length length = new Length(new BigDecimal(50)).copy(new BigDecimal(100)).copy(new BigDecimal(50)); + Length length = new Length(50); Assert.assertEquals(1,length.getSok()); } diff --git a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt index 368d831..d50e3f4 100644 --- a/src/test/kotlin/nectec/thai/unit/LenghtTest.kt +++ b/src/test/kotlin/nectec/thai/unit/LenghtTest.kt @@ -8,7 +8,15 @@ import org.junit.Test import kotlin.test.assertEquals class LenghtTest { - val lenght = Length(1200.0) + val lenght :Length + val lenght2 :Length + + constructor(){ + lenght2 = Length(1200.0) + lenght = Length(1200) + } + + @Test fun sokvalue() { From 18d270bb02fcd1713e96de247a8e527a36915e8d Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Sat, 22 Jul 2017 12:12:59 +0700 Subject: [PATCH 16/29] use BigDecimal and rounding --- src/main/kotlin/nectec/thai/unit/Length.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 3efafaa..a68cdf7 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -35,13 +35,13 @@ data class Length (val centimetres: BigDecimal) { //Number rounding format. rounding_number_format = NumberFormat.getNumberInstance() rounding_number_format.maximumFractionDigits=0 - rounding_number_format.roundingMode=java.math.RoundingMode.DOWN + rounding_number_format.roundingMode=java.math.RoundingMode.HALF_UP var temp_value :BigDecimal //Convert centimetres to thai unit. YOT->SEN->WA->SOK->KHUEP->NIO->KRABIAT - this.yot=centimetres.divide(BigDecimal(CENTIMETRE_PER_YOT)).toInt() + this.yot=(centimetres.toDouble()/CENTIMETRE_PER_YOT).toInt() temp_value=centimetres.remainder(BigDecimal(CENTIMETRE_PER_YOT)) @@ -57,7 +57,7 @@ data class Length (val centimetres: BigDecimal) { this.nio=(temp_value.toDouble()/CENTIMETRE_PER_NIO).toInt() temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_NIO)) this.krabiat=(temp_value.toDouble()/CENTIMETRE_PER_KRABIAT) - temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) + //temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) } companion object { @@ -112,7 +112,7 @@ data class Length (val centimetres: BigDecimal) { .append(sok).append(SOK) .append(khuep).append(KHUEP) .append(nio).append(NIO) - .append(krabiat).append(KRABIAT) + .append(rounding_number_format.format(krabiat)).append(KRABIAT) .toString().trim() } @@ -131,7 +131,7 @@ data class Length (val centimetres: BigDecimal) { .append(if (sok>0){sok.toString()+SOK}else{""} ) .append(if (khuep>0){khuep.toString()+KHUEP}else{""} ) .append(if (nio>0){nio.toString()+NIO}else{""} ) - .append(if (krabiat>0){krabiat.toString()+KRABIAT}else{""} ) + .append(if (krabiat>0){rounding_number_format.format(krabiat)+KRABIAT}else{""} ) .toString().trim() } } From 5f2bb3792c6dc8c7afcfe3f24309e69f7900886a Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Sat, 22 Jul 2017 12:21:08 +0700 Subject: [PATCH 17/29] use toCentimetres BigDecimal --- src/main/kotlin/nectec/thai/unit/Length.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index a68cdf7..79f2964 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -83,15 +83,16 @@ data class Length (val centimetres: BigDecimal) { private fun toCentimetres(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number):BigDecimal{ var temp_value : BigDecimal - temp_value= BigDecimal((yot.toDouble()*CENTIMETRE_PER_YOT)) - - //Auto RegEx Output temp_value = temp_value.add\(BigDecimal\(\($1.toDouble\(\)*CENTIMETRE_PER_$2\)\)\) - temp_value = temp_value.add(BigDecimal((sen.toDouble()*CENTIMETRE_PER_SEN))) - temp_value = temp_value.add(BigDecimal((wa.toDouble()*CENTIMETRE_PER_WA))) - temp_value = temp_value.add(BigDecimal((sok.toDouble()*CENTIMETRE_PER_SOK))) - temp_value = temp_value.add(BigDecimal((khuep.toDouble()*CENTIMETRE_PER_KHUEP))) - temp_value = temp_value.add(BigDecimal((nio.toDouble()*CENTIMETRE_PER_NIO))) - temp_value = temp_value.add(BigDecimal((krabiat.toDouble()*CENTIMETRE_PER_KRABIAT))) + temp_value= BigDecimal.ZERO + + //Auto RegEx Output temp_value = temp_value.add\(BigDecimal\($1.toDouble\(\)\).multiply\(BigDecimal\(CENTIMETRE_PER_$2\)\)\) + temp_value = temp_value.add(BigDecimal(yot.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_YOT))) + temp_value = temp_value.add(BigDecimal(sen.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_SEN))) + temp_value = temp_value.add(BigDecimal(wa.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_WA))) + temp_value = temp_value.add(BigDecimal(sok.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_SOK))) + temp_value = temp_value.add(BigDecimal(khuep.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_KHUEP))) + temp_value = temp_value.add(BigDecimal(nio.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_NIO))) + temp_value = temp_value.add(BigDecimal(krabiat.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_KRABIAT))) return temp_value } From b7e76daa892071bcace8faba95bf3b221aea9543 Mon Sep 17 00:00:00 2001 From: Max Thanachai Date: Mon, 24 Jul 2017 23:34:43 +0700 Subject: [PATCH 18/29] toXXX --- src/main/kotlin/nectec/thai/unit/Length.kt | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 79f2964..52f07a6 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -135,6 +135,79 @@ data class Length (val centimetres: BigDecimal) { .append(if (krabiat>0){rounding_number_format.format(krabiat)+KRABIAT}else{""} ) .toString().trim() } + +//Auto RegEx Output fun to$2\(\):Double{\r\nreturn to$2\(centimetres\).toDouble\(\)\r\n }\r\nfun to$2\(centimetres: Double\):Double{\r\nreturn to$2\(BigDecimal\(centimetres\)\).toDouble\(\)\r\n }\r\n fun to$2\(centimetres: BigDecimal\):BigDecimal{\r\nreturn centimetres.remainder\(BigDecimal\(CENTIMETRE_PER_$2\)\)\r\n }\r\n + fun toYOT():Double{ + return toYOT(centimetres).toDouble() + } + fun toYOT(centimetres: Double):Double{ + return toYOT(BigDecimal(centimetres)).toDouble() + } + fun toYOT(centimetres: BigDecimal):BigDecimal{ + return centimetres.remainder(BigDecimal(CENTIMETRE_PER_YOT)) + } + + fun toSEN():Double{ + return toSEN(centimetres).toDouble() + } + fun toSEN(centimetres: Double):Double{ + return toSEN(BigDecimal(centimetres)).toDouble() + } + fun toSEN(centimetres: BigDecimal):BigDecimal{ + return centimetres.remainder(BigDecimal(CENTIMETRE_PER_SEN)) + } + + fun toWA():Double{ + return toWA(centimetres).toDouble() + } + fun toWA(centimetres: Double):Double{ + return toWA(BigDecimal(centimetres)).toDouble() + } + fun toWA(centimetres: BigDecimal):BigDecimal{ + return centimetres.remainder(BigDecimal(CENTIMETRE_PER_WA)) + } + + fun toSOK():Double{ + return toSOK(centimetres).toDouble() + } + fun toSOK(centimetres: Double):Double{ + return toSOK(BigDecimal(centimetres)).toDouble() + } + fun toSOK(centimetres: BigDecimal):BigDecimal{ + return centimetres.remainder(BigDecimal(CENTIMETRE_PER_SOK)) + } + + fun toKHUEP():Double{ + return toKHUEP(centimetres).toDouble() + } + fun toKHUEP(centimetres: Double):Double{ + return toKHUEP(BigDecimal(centimetres)).toDouble() + } + fun toKHUEP(centimetres: BigDecimal):BigDecimal{ + return centimetres.remainder(BigDecimal(CENTIMETRE_PER_KHUEP)) + } + + fun toNIO():Double{ + return toNIO(centimetres).toDouble() + } + fun toNIO(centimetres: Double):Double{ + return toNIO(BigDecimal(centimetres)).toDouble() + } + fun toNIO(centimetres: BigDecimal):BigDecimal{ + return centimetres.remainder(BigDecimal(CENTIMETRE_PER_NIO)) + } + + fun toKRABIAT():Double{ + return toKRABIAT(centimetres).toDouble() + } + fun toKRABIAT(centimetres: Double):Double{ + return toKRABIAT(BigDecimal(centimetres)).toDouble() + } + fun toKRABIAT(centimetres: BigDecimal):BigDecimal{ + return centimetres.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) + } + + } From a7b518836fe73913dc8dee9bbb35203288993705 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Tue, 25 Jul 2017 11:10:15 +0700 Subject: [PATCH 19/29] Iss bug comment --- src/main/kotlin/nectec/thai/unit/Length.kt | 133 ++++++++++++--------- 1 file changed, 76 insertions(+), 57 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 52f07a6..694c23d 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -41,23 +41,30 @@ data class Length (val centimetres: BigDecimal) { //Convert centimetres to thai unit. YOT->SEN->WA->SOK->KHUEP->NIO->KRABIAT - this.yot=(centimetres.toDouble()/CENTIMETRE_PER_YOT).toInt() + this.yot=toYOT(centimetres).toInt() temp_value=centimetres.remainder(BigDecimal(CENTIMETRE_PER_YOT)) //Auto RegEx Output this.$1=\(temp_value.toDouble\(\)/CENTIMETRE_PER_$2\).toInt\(\)\r\ntemp_value=temp_value.remainder\(BigDecimal\(CENTIMETRE_PER_$2\)\) - this.sen=(temp_value.toDouble()/CENTIMETRE_PER_SEN).toInt() - temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_SEN)) - this.wa=(temp_value.toDouble()/CENTIMETRE_PER_WA).toInt() - temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_WA)) - this.sok=(temp_value.toDouble()/CENTIMETRE_PER_SOK).toInt() - temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_SOK)) - this.khuep=(temp_value.toDouble()/CENTIMETRE_PER_KHUEP).toInt() - temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KHUEP)) - this.nio=(temp_value.toDouble()/CENTIMETRE_PER_NIO).toInt() - temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_NIO)) - this.krabiat=(temp_value.toDouble()/CENTIMETRE_PER_KRABIAT) - //temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) + +this.sen=toSEN(temp_value).toInt() +temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_SEN)) + +this.wa=toWA(temp_value).toInt() +temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_WA)) + +this.sok=toSOK(temp_value).toInt() +temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_SOK)) + +this.khuep=toKHUEP(temp_value).toInt() +temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KHUEP)) + +this.nio=toNIO(temp_value).toInt() +temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_NIO)) + +this.krabiat=toKRABIAT(temp_value).toDouble() +//temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) + } companion object { @@ -136,77 +143,89 @@ data class Length (val centimetres: BigDecimal) { .toString().trim() } -//Auto RegEx Output fun to$2\(\):Double{\r\nreturn to$2\(centimetres\).toDouble\(\)\r\n }\r\nfun to$2\(centimetres: Double\):Double{\r\nreturn to$2\(BigDecimal\(centimetres\)\).toDouble\(\)\r\n }\r\n fun to$2\(centimetres: BigDecimal\):BigDecimal{\r\nreturn centimetres.remainder\(BigDecimal\(CENTIMETRE_PER_$2\)\)\r\n }\r\n - fun toYOT():Double{ - return toYOT(centimetres).toDouble() - } - fun toYOT(centimetres: Double):Double{ - return toYOT(BigDecimal(centimetres)).toDouble() + fun toYOT(): Double { + return toYOT(centimetres.toDouble()) } - fun toYOT(centimetres: BigDecimal):BigDecimal{ - return centimetres.remainder(BigDecimal(CENTIMETRE_PER_YOT)) + + fun toYOT(centimetres: Double): Double { + return centimetres / CENTIMETRE_PER_YOT } - fun toSEN():Double{ - return toSEN(centimetres).toDouble() + fun toYOT(centimetres: BigDecimal): Double { + return toYOT(centimetres.toDouble()) } - fun toSEN(centimetres: Double):Double{ - return toSEN(BigDecimal(centimetres)).toDouble() + + fun toSEN(): Double { + return toSEN(centimetres.toDouble()) } - fun toSEN(centimetres: BigDecimal):BigDecimal{ - return centimetres.remainder(BigDecimal(CENTIMETRE_PER_SEN)) + + fun toSEN(centimetres: Double): Double { + return centimetres / CENTIMETRE_PER_SEN } - fun toWA():Double{ - return toWA(centimetres).toDouble() + fun toSEN(centimetres: BigDecimal): Double { + return toSEN(centimetres.toDouble()) } - fun toWA(centimetres: Double):Double{ - return toWA(BigDecimal(centimetres)).toDouble() + + fun toWA(): Double { + return toWA(centimetres.toDouble()) } - fun toWA(centimetres: BigDecimal):BigDecimal{ - return centimetres.remainder(BigDecimal(CENTIMETRE_PER_WA)) + + fun toWA(centimetres: Double): Double { + return centimetres / CENTIMETRE_PER_WA } - fun toSOK():Double{ - return toSOK(centimetres).toDouble() + fun toWA(centimetres: BigDecimal): Double { + return toWA(centimetres.toDouble()) } - fun toSOK(centimetres: Double):Double{ - return toSOK(BigDecimal(centimetres)).toDouble() + + fun toSOK(): Double { + return toSOK(centimetres.toDouble()) } - fun toSOK(centimetres: BigDecimal):BigDecimal{ - return centimetres.remainder(BigDecimal(CENTIMETRE_PER_SOK)) + + fun toSOK(centimetres: Double): Double { + return centimetres / CENTIMETRE_PER_SOK } - fun toKHUEP():Double{ - return toKHUEP(centimetres).toDouble() + fun toSOK(centimetres: BigDecimal): Double { + return toSOK(centimetres.toDouble()) } - fun toKHUEP(centimetres: Double):Double{ - return toKHUEP(BigDecimal(centimetres)).toDouble() + + fun toKHUEP(): Double { + return toKHUEP(centimetres.toDouble()) } - fun toKHUEP(centimetres: BigDecimal):BigDecimal{ - return centimetres.remainder(BigDecimal(CENTIMETRE_PER_KHUEP)) + + fun toKHUEP(centimetres: Double): Double { + return centimetres / CENTIMETRE_PER_KHUEP } - fun toNIO():Double{ - return toNIO(centimetres).toDouble() + fun toKHUEP(centimetres: BigDecimal): Double { + return toKHUEP(centimetres.toDouble()) } - fun toNIO(centimetres: Double):Double{ - return toNIO(BigDecimal(centimetres)).toDouble() + + fun toNIO(): Double { + return toNIO(centimetres.toDouble()) } - fun toNIO(centimetres: BigDecimal):BigDecimal{ - return centimetres.remainder(BigDecimal(CENTIMETRE_PER_NIO)) + + fun toNIO(centimetres: Double): Double { + return centimetres / CENTIMETRE_PER_NIO } - fun toKRABIAT():Double{ - return toKRABIAT(centimetres).toDouble() + fun toNIO(centimetres: BigDecimal): Double { + return toNIO(centimetres.toDouble()) } - fun toKRABIAT(centimetres: Double):Double{ - return toKRABIAT(BigDecimal(centimetres)).toDouble() + + fun toKRABIAT(): Double { + return toKRABIAT(centimetres.toDouble()) } - fun toKRABIAT(centimetres: BigDecimal):BigDecimal{ - return centimetres.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) + + fun toKRABIAT(centimetres: Double): Double { + return centimetres / CENTIMETRE_PER_KRABIAT } + fun toKRABIAT(centimetres: BigDecimal): Double { + return toKRABIAT(centimetres.toDouble()) + } } From 91f12660c2b597c7057b52445d5608b326849f58 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Tue, 25 Jul 2017 11:59:56 +0700 Subject: [PATCH 20/29] Reformat --- src/main/kotlin/nectec/thai/unit/Length.kt | 66 +++++++++------------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 694c23d..0e88a5a 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -45,24 +45,23 @@ data class Length (val centimetres: BigDecimal) { temp_value=centimetres.remainder(BigDecimal(CENTIMETRE_PER_YOT)) - //Auto RegEx Output this.$1=\(temp_value.toDouble\(\)/CENTIMETRE_PER_$2\).toInt\(\)\r\ntemp_value=temp_value.remainder\(BigDecimal\(CENTIMETRE_PER_$2\)\) -this.sen=toSEN(temp_value).toInt() -temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_SEN)) + this.sen = toSEN(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(CENTIMETRE_PER_SEN)) -this.wa=toWA(temp_value).toInt() -temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_WA)) + this.wa = toWA(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(CENTIMETRE_PER_WA)) -this.sok=toSOK(temp_value).toInt() -temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_SOK)) + this.sok = toSOK(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(CENTIMETRE_PER_SOK)) -this.khuep=toKHUEP(temp_value).toInt() -temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KHUEP)) + this.khuep = toKHUEP(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(CENTIMETRE_PER_KHUEP)) -this.nio=toNIO(temp_value).toInt() -temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_NIO)) + this.nio = toNIO(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(CENTIMETRE_PER_NIO)) -this.krabiat=toKRABIAT(temp_value).toDouble() + this.krabiat = toKRABIAT(temp_value) //temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) } @@ -143,87 +142,74 @@ this.krabiat=toKRABIAT(temp_value).toDouble() .toString().trim() } - fun toYOT(): Double { + + fun toYOT(centimetres: BigDecimal): Double { return toYOT(centimetres.toDouble()) } - fun toYOT(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_YOT } - - fun toYOT(centimetres: BigDecimal): Double { + fun toYOT(): Double { return toYOT(centimetres.toDouble()) } - fun toSEN(): Double { + fun toSEN(centimetres: BigDecimal): Double { return toSEN(centimetres.toDouble()) } - fun toSEN(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_SEN } - - fun toSEN(centimetres: BigDecimal): Double { + fun toSEN(): Double { return toSEN(centimetres.toDouble()) } - fun toWA(): Double { + fun toWA(centimetres: BigDecimal): Double { return toWA(centimetres.toDouble()) } - fun toWA(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_WA } - - fun toWA(centimetres: BigDecimal): Double { + fun toWA(): Double { return toWA(centimetres.toDouble()) } - fun toSOK(): Double { + fun toSOK(centimetres: BigDecimal): Double { return toSOK(centimetres.toDouble()) } - fun toSOK(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_SOK } - - fun toSOK(centimetres: BigDecimal): Double { + fun toSOK(): Double { return toSOK(centimetres.toDouble()) } - fun toKHUEP(): Double { + fun toKHUEP(centimetres: BigDecimal): Double { return toKHUEP(centimetres.toDouble()) } - fun toKHUEP(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_KHUEP } - - fun toKHUEP(centimetres: BigDecimal): Double { + fun toKHUEP(): Double { return toKHUEP(centimetres.toDouble()) } - fun toNIO(): Double { + fun toNIO(centimetres: BigDecimal): Double { return toNIO(centimetres.toDouble()) } - fun toNIO(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_NIO } - - fun toNIO(centimetres: BigDecimal): Double { + fun toNIO(): Double { return toNIO(centimetres.toDouble()) } - fun toKRABIAT(): Double { + fun toKRABIAT(centimetres: BigDecimal): Double { return toKRABIAT(centimetres.toDouble()) } - fun toKRABIAT(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_KRABIAT } - - fun toKRABIAT(centimetres: BigDecimal): Double { + fun toKRABIAT(): Double { return toKRABIAT(centimetres.toDouble()) } From ae24d58de7698d77299235dee74f8e29b8d7d131 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 26 Jul 2017 11:51:38 +0700 Subject: [PATCH 21/29] etc fix --- src/main/kotlin/nectec/thai/unit/Length.kt | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index 0e88a5a..da73a60 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -61,7 +61,7 @@ data class Length (val centimetres: BigDecimal) { this.nio = toNIO(temp_value).toInt() temp_value = temp_value.remainder(BigDecimal(CENTIMETRE_PER_NIO)) - this.krabiat = toKRABIAT(temp_value) + this.krabiat = toKRABIAT(temp_value).toDouble() //temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) } @@ -143,72 +143,72 @@ data class Length (val centimetres: BigDecimal) { } - fun toYOT(centimetres: BigDecimal): Double { - return toYOT(centimetres.toDouble()) - } fun toYOT(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_YOT } + fun toYOT(centimetres: BigDecimal): BigDecimal { + return BigDecimal(toYOT(centimetres.toDouble())) + } fun toYOT(): Double { return toYOT(centimetres.toDouble()) } - fun toSEN(centimetres: BigDecimal): Double { - return toSEN(centimetres.toDouble()) - } fun toSEN(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_SEN } + fun toSEN(centimetres: BigDecimal): BigDecimal { + return BigDecimal(toSEN(centimetres.toDouble())) + } fun toSEN(): Double { return toSEN(centimetres.toDouble()) } - fun toWA(centimetres: BigDecimal): Double { - return toWA(centimetres.toDouble()) - } fun toWA(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_WA } + fun toWA(centimetres: BigDecimal): BigDecimal { + return BigDecimal(toWA(centimetres.toDouble())) + } fun toWA(): Double { return toWA(centimetres.toDouble()) } - fun toSOK(centimetres: BigDecimal): Double { - return toSOK(centimetres.toDouble()) - } fun toSOK(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_SOK } + fun toSOK(centimetres: BigDecimal): BigDecimal { + return BigDecimal(toSOK(centimetres.toDouble())) + } fun toSOK(): Double { return toSOK(centimetres.toDouble()) } - fun toKHUEP(centimetres: BigDecimal): Double { - return toKHUEP(centimetres.toDouble()) - } fun toKHUEP(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_KHUEP } + fun toKHUEP(centimetres: BigDecimal): BigDecimal { + return BigDecimal(toKHUEP(centimetres.toDouble())) + } fun toKHUEP(): Double { return toKHUEP(centimetres.toDouble()) } - fun toNIO(centimetres: BigDecimal): Double { - return toNIO(centimetres.toDouble()) - } fun toNIO(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_NIO } + fun toNIO(centimetres: BigDecimal): BigDecimal { + return BigDecimal(toNIO(centimetres.toDouble())) + } fun toNIO(): Double { return toNIO(centimetres.toDouble()) } - fun toKRABIAT(centimetres: BigDecimal): Double { - return toKRABIAT(centimetres.toDouble()) - } fun toKRABIAT(centimetres: Double): Double { return centimetres / CENTIMETRE_PER_KRABIAT } + fun toKRABIAT(centimetres: BigDecimal): BigDecimal { + return BigDecimal(toKRABIAT(centimetres.toDouble())) + } fun toKRABIAT(): Double { return toKRABIAT(centimetres.toDouble()) } From b2c13f892588741003e19565c4446f93f6d3de29 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 26 Jul 2017 13:47:33 +0700 Subject: [PATCH 22/29] Add Weight --- src/main/kotlin/nectec/thai/unit/Weight.kt | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 src/main/kotlin/nectec/thai/unit/Weight.kt diff --git a/src/main/kotlin/nectec/thai/unit/Weight.kt b/src/main/kotlin/nectec/thai/unit/Weight.kt new file mode 100644 index 0000000..6b38920 --- /dev/null +++ b/src/main/kotlin/nectec/thai/unit/Weight.kt @@ -0,0 +1,130 @@ +package nectec.thai.unit + +import java.math.BigDecimal + +data class Weight (val gram :BigDecimal){ + + + val salueng: Int + val baht: Int + val tamlueng: Int + val chang: Int + val hap: Int + + init { + + var temp_value :BigDecimal + + + this.hap=toHAP(gram).toInt() + temp_value=gram.remainder(BigDecimal(GRAM_PER_HAP)) + + this.chang = toCHANG(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(GRAM_PER_CHANG)) + this.tamlueng = toTAMLUENG(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(GRAM_PER_TAMLUENG)) + this.baht = toBAHT(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(GRAM_PER_BAHT)) + this.salueng = toSALUENG(temp_value).toInt() + temp_value = temp_value.remainder(BigDecimal(GRAM_PER_SALUENG)) + + + } + + companion object { + + @JvmField val GRAM_PER_SALUENG = 3.75 + @JvmField val GRAM_PER_BAHT = 15 + @JvmField val GRAM_PER_TAMLUENG = 60 + @JvmField val GRAM_PER_CHANG = 1200 + @JvmField val GRAM_PER_HAP = 60000 + + @JvmField val SALUENG = " สลึง " + @JvmField val BAHT = " บาท " + @JvmField val TAMLUENG = " ตำลึง " + @JvmField val CHANG = " ชั่ง " + @JvmField val HAP = " หาบ " + + private fun toGram( salueng: Number,baht: Number,tamlueng: Number,chang: Number,hap: Number): BigDecimal{ + + var temp_value : BigDecimal + temp_value= BigDecimal.ZERO + + temp_value = temp_value.add(BigDecimal(salueng.toDouble()).multiply(BigDecimal(GRAM_PER_SALUENG))) + temp_value = temp_value.add(BigDecimal(baht.toDouble()).multiply(BigDecimal(GRAM_PER_BAHT))) + temp_value = temp_value.add(BigDecimal(tamlueng.toDouble()).multiply(BigDecimal(GRAM_PER_TAMLUENG))) + temp_value = temp_value.add(BigDecimal(chang.toDouble()).multiply(BigDecimal(GRAM_PER_CHANG))) + temp_value = temp_value.add(BigDecimal(hap.toDouble()).multiply(BigDecimal(GRAM_PER_HAP))) + return temp_value + } + } + + fun toSALUENG(gram: Double): Double { + return gram / GRAM_PER_SALUENG + } + fun toSALUENG(gram: BigDecimal): BigDecimal { + return BigDecimal(toSALUENG(gram.toDouble())) + } + fun toSALUENG(): Double { + return toSALUENG(gram.toDouble()) + } + + fun toBAHT(gram: Double): Double { + return gram / GRAM_PER_BAHT + } + fun toBAHT(gram: BigDecimal): BigDecimal { + return BigDecimal(toBAHT(gram.toDouble())) + } + fun toBAHT(): Double { + return toBAHT(gram.toDouble()) + } + + fun toTAMLUENG(gram: Double): Double { + return gram / GRAM_PER_TAMLUENG + } + fun toTAMLUENG(gram: BigDecimal): BigDecimal { + return BigDecimal(toTAMLUENG(gram.toDouble())) + } + fun toTAMLUENG(): Double { + return toTAMLUENG(gram.toDouble()) + } + + fun toCHANG(gram: Double): Double { + return gram / GRAM_PER_CHANG + } + fun toCHANG(gram: BigDecimal): BigDecimal { + return BigDecimal(toCHANG(gram.toDouble())) + } + fun toCHANG(): Double { + return toCHANG(gram.toDouble()) + } + + fun toHAP(gram: Double): Double { + return gram / GRAM_PER_HAP + } + fun toHAP(gram: BigDecimal): BigDecimal { + return BigDecimal(toHAP(gram.toDouble())) + } + fun toHAP(): Double { + return toHAP(gram.toDouble()) + } + +} + + +/* + +^ *(.+)\t(.+)\t(.+)\t(.+)\t(.+)$ +SALUENG salueng Salueng สลึง 3.75 +BAHT baht Baht บาท 15 +TAMLUENG tamlueng Tamlueng ตำลึง 60 +CHANG chang Chang ชั่ง 1200 +HAP hap Hap หาบ 60000 + +^ *(.+)\t(.+)\t(.+)\t(.+)$ +HAP hap Hap หาบ +CHANG chang Chang ชั่ง +TAMLUENG tamlueng Tamlueng ตำลึง +BAHT baht Baht บาท +SALUENG salueng Salueng สลึง + */ From 0dd4bf3a5ee0e124ef3d6bcc489298d47da581b8 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 26 Jul 2017 14:03:38 +0700 Subject: [PATCH 23/29] Add Weight Test --- src/main/kotlin/nectec/thai/unit/Weight.kt | 5 ++- .../kotlin/nectec/thai/unit/WeightTest.kt | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/test/kotlin/nectec/thai/unit/WeightTest.kt diff --git a/src/main/kotlin/nectec/thai/unit/Weight.kt b/src/main/kotlin/nectec/thai/unit/Weight.kt index 6b38920..47e1fa5 100644 --- a/src/main/kotlin/nectec/thai/unit/Weight.kt +++ b/src/main/kotlin/nectec/thai/unit/Weight.kt @@ -4,6 +4,8 @@ import java.math.BigDecimal data class Weight (val gram :BigDecimal){ + constructor(gram: Number) : this(BigDecimal(gram.toDouble())) + constructor(gram: Double) : this(BigDecimal(gram)) val salueng: Int val baht: Int @@ -15,7 +17,6 @@ data class Weight (val gram :BigDecimal){ var temp_value :BigDecimal - this.hap=toHAP(gram).toInt() temp_value=gram.remainder(BigDecimal(GRAM_PER_HAP)) @@ -26,7 +27,7 @@ data class Weight (val gram :BigDecimal){ this.baht = toBAHT(temp_value).toInt() temp_value = temp_value.remainder(BigDecimal(GRAM_PER_BAHT)) this.salueng = toSALUENG(temp_value).toInt() - temp_value = temp_value.remainder(BigDecimal(GRAM_PER_SALUENG)) + //temp_value = temp_value.remainder(BigDecimal(GRAM_PER_SALUENG)) } diff --git a/src/test/kotlin/nectec/thai/unit/WeightTest.kt b/src/test/kotlin/nectec/thai/unit/WeightTest.kt new file mode 100644 index 0000000..400f21b --- /dev/null +++ b/src/test/kotlin/nectec/thai/unit/WeightTest.kt @@ -0,0 +1,39 @@ +package nectec.thai.unit +import org.junit.Test +import kotlin.test.assertEquals + +class WeightTest { + val weightTest1 :Weight + val weightTest2 :Weight + + constructor(){ + weightTest1 = Weight(2000.0) + weightTest2 = Weight(3000) + } + + + + + @Test fun toHapFunction() { + assertEquals(0.5, weightTest1.toHAP(30000.0)) + } + + @Test fun toChangFunction() { + assertEquals(25.0, weightTest1.toCHANG(30000.0)) + } + + @Test fun toTamluengFunction() { + assertEquals(500.0, weightTest1.toTAMLUENG(30000.0)) + } + + @Test fun toBahtFunction() { + assertEquals(2000.0, weightTest1.toBAHT(30000.0)) + } + + @Test fun toSaluengFunction() { + assertEquals(8000.0, weightTest1.toSALUENG(30000.0)) + } + + + +} From 4318143281083d2c9be8b11e9499b62b0e59ed7b Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 26 Jul 2017 14:14:40 +0700 Subject: [PATCH 24/29] Add Weight Test formalPrint --- src/main/kotlin/nectec/thai/unit/Weight.kt | 37 +++++++++++++++++++ .../kotlin/nectec/thai/unit/WeightTest.kt | 18 +++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Weight.kt b/src/main/kotlin/nectec/thai/unit/Weight.kt index 47e1fa5..8457798 100644 --- a/src/main/kotlin/nectec/thai/unit/Weight.kt +++ b/src/main/kotlin/nectec/thai/unit/Weight.kt @@ -1,6 +1,7 @@ package nectec.thai.unit import java.math.BigDecimal +import java.text.NumberFormat data class Weight (val gram :BigDecimal){ @@ -13,8 +14,15 @@ data class Weight (val gram :BigDecimal){ val chang: Int val hap: Int + val rounding_number_format : NumberFormat + init { + //Number rounding format. + rounding_number_format = NumberFormat.getNumberInstance() + rounding_number_format.maximumFractionDigits=0 + rounding_number_format.roundingMode=java.math.RoundingMode.HALF_UP + var temp_value :BigDecimal this.hap=toHAP(gram).toInt() @@ -60,6 +68,35 @@ data class Weight (val gram :BigDecimal){ } } + fun formalPrintAll(): String { + val stringBuilder = StringBuilder() + return stringBuilder + //Auto RegEx Output .append\($2\).append\($1\) + + .append(hap).append(HAP) + .append(chang).append(CHANG) + .append(tamlueng).append(TAMLUENG) + .append(baht).append(BAHT) + .append(rounding_number_format.format(salueng)).append(SALUENG) + .toString().trim() + } + + fun formalPrint(): String { + val stringBuilder = StringBuilder() + return stringBuilder + //Auto RegEx Output .append\(if \($2>0\){$2.toString\(\)+$1}else{""} \) + .append(if (hap>0){hap.toString()+HAP}else{""} ) + .append(if (chang>0){chang.toString()+CHANG}else{""} ) + .append(if (tamlueng>0){tamlueng.toString()+TAMLUENG}else{""} ) + .append(if (baht>0){baht.toString()+BAHT}else{""} ) + .append(if (salueng>0){rounding_number_format.format(salueng)+SALUENG}else{""} ) + .toString().trim() + } + + + + + fun toSALUENG(gram: Double): Double { return gram / GRAM_PER_SALUENG } diff --git a/src/test/kotlin/nectec/thai/unit/WeightTest.kt b/src/test/kotlin/nectec/thai/unit/WeightTest.kt index 400f21b..0dde1f2 100644 --- a/src/test/kotlin/nectec/thai/unit/WeightTest.kt +++ b/src/test/kotlin/nectec/thai/unit/WeightTest.kt @@ -11,9 +11,6 @@ class WeightTest { weightTest2 = Weight(3000) } - - - @Test fun toHapFunction() { assertEquals(0.5, weightTest1.toHAP(30000.0)) } @@ -34,6 +31,21 @@ class WeightTest { assertEquals(8000.0, weightTest1.toSALUENG(30000.0)) } + @Test fun formalPrintAll1() { + assertEquals("0 หาบ 1 ชั่ง 13 ตำลึง 1 บาท 1 สลึง", weightTest1.formalPrintAll()) + } + + @Test fun formalPrintAll2() { + assertEquals("0 หาบ 2 ชั่ง 10 ตำลึง 0 บาท 0 สลึง", weightTest2.formalPrintAll()) + } + + @Test fun formalPrint1() { + assertEquals("1 ชั่ง 13 ตำลึง 1 บาท 1 สลึง", weightTest1.formalPrint()) + } + + @Test fun formalPrint2() { + assertEquals("2 ชั่ง 10 ตำลึง", weightTest2.formalPrint()) + } } From 048b50b9830d195168e630c6b470050de5db0717 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 26 Jul 2017 14:29:43 +0700 Subject: [PATCH 25/29] iss bug --- src/main/kotlin/nectec/thai/unit/Weight.kt | 8 ++++---- src/test/kotlin/nectec/thai/unit/WeightTest.kt | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Weight.kt b/src/main/kotlin/nectec/thai/unit/Weight.kt index 8457798..cd06b76 100644 --- a/src/main/kotlin/nectec/thai/unit/Weight.kt +++ b/src/main/kotlin/nectec/thai/unit/Weight.kt @@ -7,6 +7,8 @@ data class Weight (val gram :BigDecimal){ constructor(gram: Number) : this(BigDecimal(gram.toDouble())) constructor(gram: Double) : this(BigDecimal(gram)) + constructor(hap: Number,chang: Number,tamlueng: Number,baht: Number,salueng: Number) : this(toGram(hap, chang, tamlueng, baht, salueng)) + val salueng: Int val baht: Int @@ -54,7 +56,7 @@ data class Weight (val gram :BigDecimal){ @JvmField val CHANG = " ชั่ง " @JvmField val HAP = " หาบ " - private fun toGram( salueng: Number,baht: Number,tamlueng: Number,chang: Number,hap: Number): BigDecimal{ + private fun toGram( hap: Number,chang: Number,tamlueng: Number,baht: Number,salueng: Number): BigDecimal{ var temp_value : BigDecimal temp_value= BigDecimal.ZERO @@ -68,6 +70,7 @@ data class Weight (val gram :BigDecimal){ } } + fun formalPrintAll(): String { val stringBuilder = StringBuilder() return stringBuilder @@ -94,9 +97,6 @@ data class Weight (val gram :BigDecimal){ } - - - fun toSALUENG(gram: Double): Double { return gram / GRAM_PER_SALUENG } diff --git a/src/test/kotlin/nectec/thai/unit/WeightTest.kt b/src/test/kotlin/nectec/thai/unit/WeightTest.kt index 0dde1f2..0e040d3 100644 --- a/src/test/kotlin/nectec/thai/unit/WeightTest.kt +++ b/src/test/kotlin/nectec/thai/unit/WeightTest.kt @@ -11,6 +11,21 @@ class WeightTest { weightTest2 = Weight(3000) } + + @Test fun constructorTest() { + assertEquals("2 หาบ 2 ชั่ง 2 ตำลึง 2 บาท 2 สลึง", Weight(2,2,2,2,2).formalPrintAll()) + } + + @Test fun constructorTest2() { + assertEquals("2000 หาบ 2 ชั่ง 2 ตำลึง 2 บาท 2 สลึง", Weight(2000,2,2,2,2).formalPrintAll()) + } + @Test fun constructorTest3() { + assertEquals("3 หาบ 45 ชั่ง 17 ตำลึง 2 บาท 0 สลึง", Weight(2,2,2,2,30000).formalPrintAll()) + } + @Test fun constructorTest4() { + assertEquals("3 หาบ 45 ชั่ง 17 ตำลึง 2 บาท", Weight(2,2,2,2,30000).formalPrint()) + } + @Test fun toHapFunction() { assertEquals(0.5, weightTest1.toHAP(30000.0)) } @@ -48,4 +63,7 @@ class WeightTest { } + + + } From be490f0b5e422aee916bbd55e662bc120e82f344 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 26 Jul 2017 14:32:58 +0700 Subject: [PATCH 26/29] Add Comment --- src/main/kotlin/nectec/thai/unit/Weight.kt | 11 ++++++++++- src/test/kotlin/nectec/thai/unit/WeightTest.kt | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/nectec/thai/unit/Weight.kt b/src/main/kotlin/nectec/thai/unit/Weight.kt index cd06b76..eb88c2b 100644 --- a/src/main/kotlin/nectec/thai/unit/Weight.kt +++ b/src/main/kotlin/nectec/thai/unit/Weight.kt @@ -70,7 +70,11 @@ data class Weight (val gram :BigDecimal){ } } - + /** + * Print All + * Exam create object input Weight(2,2,2,2,30000) + * formalPrintAll output = 3 หาบ 45 ชั่ง 17 ตำลึง 2 บาท 0 สลึง + */ fun formalPrintAll(): String { val stringBuilder = StringBuilder() return stringBuilder @@ -84,6 +88,11 @@ data class Weight (val gram :BigDecimal){ .toString().trim() } + /** + * Zero value no print. + * Exam create object input Weight(2,2,2,2,30000) + * formalPrint output = 3 หาบ 45 ชั่ง 17 ตำลึง 2 บาท + */ fun formalPrint(): String { val stringBuilder = StringBuilder() return stringBuilder diff --git a/src/test/kotlin/nectec/thai/unit/WeightTest.kt b/src/test/kotlin/nectec/thai/unit/WeightTest.kt index 0e040d3..87b2077 100644 --- a/src/test/kotlin/nectec/thai/unit/WeightTest.kt +++ b/src/test/kotlin/nectec/thai/unit/WeightTest.kt @@ -2,6 +2,12 @@ package nectec.thai.unit import org.junit.Test import kotlin.test.assertEquals + +/** + * Thai length unit. + * Ref. https://en.wikipedia.org/wiki/Thai_units_of_measurement + * Created by max on 26/7/2560. + */ class WeightTest { val weightTest1 :Weight val weightTest2 :Weight From 9ef4ad7e4bdde8faf53c78534e856c0aa290671f Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 26 Jul 2017 14:35:58 +0700 Subject: [PATCH 27/29] salueng Int is Double --- src/main/kotlin/nectec/thai/unit/Weight.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Weight.kt b/src/main/kotlin/nectec/thai/unit/Weight.kt index eb88c2b..1806461 100644 --- a/src/main/kotlin/nectec/thai/unit/Weight.kt +++ b/src/main/kotlin/nectec/thai/unit/Weight.kt @@ -10,7 +10,7 @@ data class Weight (val gram :BigDecimal){ constructor(hap: Number,chang: Number,tamlueng: Number,baht: Number,salueng: Number) : this(toGram(hap, chang, tamlueng, baht, salueng)) - val salueng: Int + val salueng: Double val baht: Int val tamlueng: Int val chang: Int @@ -36,7 +36,7 @@ data class Weight (val gram :BigDecimal){ temp_value = temp_value.remainder(BigDecimal(GRAM_PER_TAMLUENG)) this.baht = toBAHT(temp_value).toInt() temp_value = temp_value.remainder(BigDecimal(GRAM_PER_BAHT)) - this.salueng = toSALUENG(temp_value).toInt() + this.salueng = toSALUENG(temp_value).toDouble() //temp_value = temp_value.remainder(BigDecimal(GRAM_PER_SALUENG)) From 995085c8558a2b89957f0a462c1c81edc2d0e3e5 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 2 Aug 2017 13:09:07 +0700 Subject: [PATCH 28/29] Remove Rexp gen code. --- src/main/kotlin/nectec/thai/unit/Length.kt | 44 ---------------------- src/main/kotlin/nectec/thai/unit/Weight.kt | 20 ---------- 2 files changed, 64 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Length.kt b/src/main/kotlin/nectec/thai/unit/Length.kt index da73a60..e5a1ecb 100644 --- a/src/main/kotlin/nectec/thai/unit/Length.kt +++ b/src/main/kotlin/nectec/thai/unit/Length.kt @@ -17,9 +17,6 @@ data class Length (val centimetres: BigDecimal) { constructor(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number) : this(toCentimetres(yot, sen, wa, sok, khuep, nio, krabiat)) - //Auto RegEx Output val $1: Int - - val krabiat: Double val nio: Int val khuep: Int @@ -40,12 +37,9 @@ data class Length (val centimetres: BigDecimal) { var temp_value :BigDecimal - //Convert centimetres to thai unit. YOT->SEN->WA->SOK->KHUEP->NIO->KRABIAT this.yot=toYOT(centimetres).toInt() temp_value=centimetres.remainder(BigDecimal(CENTIMETRE_PER_YOT)) - - this.sen = toSEN(temp_value).toInt() temp_value = temp_value.remainder(BigDecimal(CENTIMETRE_PER_SEN)) @@ -62,14 +56,12 @@ data class Length (val centimetres: BigDecimal) { temp_value = temp_value.remainder(BigDecimal(CENTIMETRE_PER_NIO)) this.krabiat = toKRABIAT(temp_value).toDouble() -//temp_value=temp_value.remainder(BigDecimal(CENTIMETRE_PER_KRABIAT)) } companion object { //Ref. https://en.wikipedia.org/wiki/Thai_units_of_measurement - //Auto RegEx Output @JvmField val CENTIMETRE_PER_$1 = xx @JvmField val CENTIMETRE_PER_KRABIAT = 0.5208 @JvmField val CENTIMETRE_PER_NIO = 2.083 @JvmField val CENTIMETRE_PER_KHUEP = 25 @@ -78,7 +70,6 @@ data class Length (val centimetres: BigDecimal) { @JvmField val CENTIMETRE_PER_SEN = 4000 @JvmField val CENTIMETRE_PER_YOT = 1600000 - //Auto RegEx Output @JvmField val $1 = "$2" @JvmField val KRABIAT = " กระเบียด " @JvmField val NIO = " นิ้ว " @JvmField val KHUEP = " คืบ " @@ -90,8 +81,6 @@ data class Length (val centimetres: BigDecimal) { private fun toCentimetres(yot: Number,sen:Number,wa:Number,sok:Number,khuep:Number,nio:Number,krabiat:Number):BigDecimal{ var temp_value : BigDecimal temp_value= BigDecimal.ZERO - - //Auto RegEx Output temp_value = temp_value.add\(BigDecimal\($1.toDouble\(\)\).multiply\(BigDecimal\(CENTIMETRE_PER_$2\)\)\) temp_value = temp_value.add(BigDecimal(yot.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_YOT))) temp_value = temp_value.add(BigDecimal(sen.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_SEN))) temp_value = temp_value.add(BigDecimal(wa.toDouble()).multiply(BigDecimal(CENTIMETRE_PER_WA))) @@ -112,7 +101,6 @@ data class Length (val centimetres: BigDecimal) { fun formalPrintAll(): String { val stringBuilder = StringBuilder() return stringBuilder - //Auto RegEx Output .append\($1\).append\($2\) .append(yot).append(YOT) .append(sen).append(SEN) .append(wa).append(WA) @@ -131,7 +119,6 @@ data class Length (val centimetres: BigDecimal) { fun formalPrint(): String { val stringBuilder = StringBuilder() return stringBuilder - //Auto RegEx Output .append\(if \($1>0\){$1.toString\(\)+$2}else{""} \) .append(if (yot>0){yot.toString()+YOT}else{""} ) .append(if (sen>0){sen.toString()+SEN}else{""} ) .append(if (wa>0){wa.toString()+WA}else{""} ) @@ -214,34 +201,3 @@ data class Length (val centimetres: BigDecimal) { } } - - -/* -RegEx Gen Code - -^(.+)\t(.+)$ - -yot YOT -sen SEN -wa WA -sok SOK -khuep KHUEP -nio NIO -krabiat KRABIAT -------------------- -krabiat KRABIAT -nio NIO -khuep KHUEP -sok SOK -wa WA -sen SEN -yot YOT ------------------ -KRABIAT กระเบียด -NIO นิ้ว -KHUEP คืบ -SOK ศอก -WA วา -SEN เส้น -YOT โยชน์ - */ diff --git a/src/main/kotlin/nectec/thai/unit/Weight.kt b/src/main/kotlin/nectec/thai/unit/Weight.kt index 1806461..5d7a285 100644 --- a/src/main/kotlin/nectec/thai/unit/Weight.kt +++ b/src/main/kotlin/nectec/thai/unit/Weight.kt @@ -37,7 +37,6 @@ data class Weight (val gram :BigDecimal){ this.baht = toBAHT(temp_value).toInt() temp_value = temp_value.remainder(BigDecimal(GRAM_PER_BAHT)) this.salueng = toSALUENG(temp_value).toDouble() - //temp_value = temp_value.remainder(BigDecimal(GRAM_PER_SALUENG)) } @@ -78,8 +77,6 @@ data class Weight (val gram :BigDecimal){ fun formalPrintAll(): String { val stringBuilder = StringBuilder() return stringBuilder - //Auto RegEx Output .append\($2\).append\($1\) - .append(hap).append(HAP) .append(chang).append(CHANG) .append(tamlueng).append(TAMLUENG) @@ -96,7 +93,6 @@ data class Weight (val gram :BigDecimal){ fun formalPrint(): String { val stringBuilder = StringBuilder() return stringBuilder - //Auto RegEx Output .append\(if \($2>0\){$2.toString\(\)+$1}else{""} \) .append(if (hap>0){hap.toString()+HAP}else{""} ) .append(if (chang>0){chang.toString()+CHANG}else{""} ) .append(if (tamlueng>0){tamlueng.toString()+TAMLUENG}else{""} ) @@ -159,19 +155,3 @@ data class Weight (val gram :BigDecimal){ } -/* - -^ *(.+)\t(.+)\t(.+)\t(.+)\t(.+)$ -SALUENG salueng Salueng สลึง 3.75 -BAHT baht Baht บาท 15 -TAMLUENG tamlueng Tamlueng ตำลึง 60 -CHANG chang Chang ชั่ง 1200 -HAP hap Hap หาบ 60000 - -^ *(.+)\t(.+)\t(.+)\t(.+)$ -HAP hap Hap หาบ -CHANG chang Chang ชั่ง -TAMLUENG tamlueng Tamlueng ตำลึง -BAHT baht Baht บาท -SALUENG salueng Salueng สลึง - */ From 3f47a5dc2ca09f4f23421270c127275e00929c49 Mon Sep 17 00:00:00 2001 From: MaxPC_NECTEC Date: Wed, 2 Aug 2017 17:26:05 +0700 Subject: [PATCH 29/29] Remove comment gradel... --- bintray.gradle | 21 --------------------- build.gradle | 1 - thai-unit.iml | 13 +++++++++++++ 3 files changed, 13 insertions(+), 22 deletions(-) create mode 100644 thai-unit.iml diff --git a/bintray.gradle b/bintray.gradle index f83da7d..9b93f9c 100644 --- a/bintray.gradle +++ b/bintray.gradle @@ -1,27 +1,6 @@ -/*buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" - } - } - dependencies { - //https://github.com/Kotlin/dokka - classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.15" - } -} - -apply plugin: "org.jetbrains.dokka"*/ apply plugin: 'com.jfrog.bintray' apply plugin: "maven-publish" -/*dokka { - outputFormat = 'javadoc' - outputDirectory = "$buildDir/javadoc" -} -task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) { - outputFormat = 'javadoc' - outputDirectory = "$buildDir/javadoc" -}*/ bintray { user = project.hasProperty('bintrayUser') ? project.getProperty('bintrayUser') : diff --git a/build.gradle b/build.gradle index 073cf25..34d5182 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ plugins { id "org.jetbrains.kotlin.jvm" version '1.1.2-2' id "com.jfrog.bintray" version "1.7.3" - //id "org.jetbrains.dokka" version "0.9.15" } group 'th.or.nectec' diff --git a/thai-unit.iml b/thai-unit.iml new file mode 100644 index 0000000..ab3ff4b --- /dev/null +++ b/thai-unit.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file