|
@@ -0,0 +1,82 @@
|
|
|
+package com.tedxiong.kotlin
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat
|
|
|
+import java.util.*
|
|
|
+import kotlin.collections.ArrayList
|
|
|
+import kotlin.collections.HashMap
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by ted on 2017/8/16.
|
|
|
+ * in com.tedxiong.kotlin
|
|
|
+ */
|
|
|
+class KotlinUnit {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 姓名拆分,通过空格拆分出姓和名
|
|
|
+ */
|
|
|
+ fun nameSplit(name: String): Boolean {
|
|
|
+ name.let {
|
|
|
+ if (it.indexOf(" ") == -1) return false
|
|
|
+ println("Your first Name is " + it.substring(0, it.indexOf(" ")))
|
|
|
+ println("Your last Name is " + it.substring(it.indexOf(" ")))
|
|
|
+ print(this)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在一个空的数组里塞入日期和时间的字符串
|
|
|
+ */
|
|
|
+ fun getDateStr(space: ArrayList<String>): Boolean {
|
|
|
+ space.apply {
|
|
|
+ add(SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(Date()))
|
|
|
+ add(SimpleDateFormat.getTimeInstance().format(Date()))
|
|
|
+ println(this)
|
|
|
+ }.let {
|
|
|
+ println("The date info is " + it[0])
|
|
|
+ println("The time info is " + it[1])
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取到编译环境相关的系统信息
|
|
|
+ */
|
|
|
+ fun getCompileInfo(map: HashMap<String, String>): Boolean {
|
|
|
+ return with(map) {
|
|
|
+ put("Java环境版本", System.getProperties().getProperty("java.version"))
|
|
|
+ put("Java环境供应商", System.getProperties().getProperty("java.vendor"))
|
|
|
+ put("操作系统名称", System.getProperties().getProperty("os.name"))
|
|
|
+ put("操作系统架构", System.getProperties().getProperty("os.arch"))
|
|
|
+ put("操作系统版本", System.getProperties().getProperty("os.version"))
|
|
|
+ println(this)
|
|
|
+ true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 接收一个姓名,打印三句话
|
|
|
+ */
|
|
|
+ fun sayHiTo(name: String): Boolean {
|
|
|
+ println(name.run {
|
|
|
+ println("Hi," + name)
|
|
|
+ println("Nice to meet you," + this)
|
|
|
+ "The run has over!!!!"
|
|
|
+ })
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算圆周长
|
|
|
+ */
|
|
|
+ fun getCircumference(dia: Int): Boolean {
|
|
|
+ println("The dia is " +
|
|
|
+ dia.also {
|
|
|
+ println("The Circumference is " + Math.PI * it)
|
|
|
+ println(this)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+}
|