commit a74cf2f28708e312496afd4d2779d7aadd4c59e2 Author: Bunny <1319900154@qq.com> Date: Mon Aug 12 23:58:38 2024 +0800 init diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Kotlin-Demo.iml b/.idea/Kotlin-Demo.iml new file mode 100644 index 0000000..f392c3c --- /dev/null +++ b/.idea/Kotlin-Demo.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..0dd4b35 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..409da39 --- /dev/null +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c1b85cc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BasicSyntax-Loop.kt b/BasicSyntax-Loop.kt new file mode 100644 index 0000000..277c222 --- /dev/null +++ b/BasicSyntax-Loop.kt @@ -0,0 +1,55 @@ +val items = listOf("apple", "banana", "kiwifruit") + +fun main() { + for (item in items) { + println(item) + } + + println("----------------") + + for (index in items.indices) { + println("item 在 $index 是 ${items[index]}") + } + + println("----------------像是Switch--------------") + println(describe(1)) + println(describe("Hello")) + println(describe(1000L)) + println(describe(2)) + println(describe("other")) + + println("----------------Ranges------------") + rangeTest() + + println("----------------for..in..------------") + forTest() +} + +// 使用when +fun describe(obj: Any): Any = when (obj) { + 1 -> "是一" + "Hello" -> "Greeting" + is Long -> "Long" + !is String -> "Not a string" + else -> "Unknown" +} + +// 范围测试 +fun rangeTest() { + val x = 10 + val y = 100 + + if (x in 1..y + 1) { + println("1 在这个范围里") + } + + if (-1 !in 1..y + 1) { + println("-1 不在这个范围里") + } +} + +fun forTest() { + for (x in 1..5) { + println(x) + } +} \ No newline at end of file diff --git a/jTest/FIleCopyBase.java b/jTest/FIleCopyBase.java new file mode 100644 index 0000000..43badeb --- /dev/null +++ b/jTest/FIleCopyBase.java @@ -0,0 +1,69 @@ +package jTest; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; + +public class FIleCopyBase { + public static void main(String[] args) throws IOException { + Path source = Path.of("D:\\Project\\demo\\source\\神偷奶爸4.ts"); + Path target = Path.of("D:\\Project\\demo\\target\\神偷奶爸4.ts"); + + // 复制速度很快 + Path copyPath = Files.copy(source, target); + System.out.println("输出复制完成后的路径" + copyPath); + + // 删除文件,文件不存在或者目录不存在会抛出异常 + Files.delete(target); + + // 删除文件如果存在就删除,不存在不会抛出异常 + Files.deleteIfExists(target); + + // 移动文件 + Path movePath = Files.move(source, target); + System.out.println("输出移动完成后的路径" + movePath); + + // 判断文件是否存在 + boolean exists = Files.exists(source); + System.out.println(exists); + + // 是否为隐藏文件 + boolean hidden = Files.isHidden(target); + System.out.println(hidden); + + // 判断是否为目录 + boolean directory = Files.isDirectory(target); + System.out.println(directory); + + // 检查指定路径是否可读取。当文件或目录具有读取权限时,Files.isReadable() 方法将返回 true,否则返回 false。 + boolean readable = Files.isReadable(target); + System.out.println(readable); + + // 表示是否是可执行的文件 + boolean executable = Files.isExecutable(target); + System.out.println(executable); + + // 是否表示一个常规文件,是指不是目录或符号链接的文件 + boolean regularFile = Files.isRegularFile(target); + System.out.println(regularFile); + + // 检查文件是否相同 + Files.copy(target, source); + boolean sameFile = Files.isSameFile(target, source); + System.out.println(sameFile); + + // 是否表示一个符号链接 + boolean symbolicLink = Files.isSymbolicLink(target); + System.out.println(symbolicLink); + + // 文件按字节的大小 + long size = Files.size(target); + System.out.println(size); + + // 读取指定文件的属性,如果第二个参数为空字符串,将返回所有基本文件属性。 + // {lastAccessTime=2024-08-10T15:37:23.5577285Z, lastModifiedTime=2024-08-10T08:18:39.377836Z, size=1158625012, creationTime=2024-08-10T15:12:56.5838403Z, isSymbolicLink=false, isRegularFile=true, fileKey=null, isOther=false, isDirectory=false} + Map stringObjectMap = Files.readAttributes(source, "basic:*"); + System.out.println(stringObjectMap); + } +} diff --git a/jTest/HasMapTest.java b/jTest/HasMapTest.java new file mode 100644 index 0000000..18dd5b4 --- /dev/null +++ b/jTest/HasMapTest.java @@ -0,0 +1,43 @@ +package jTest; + +import java.util.HashMap; + +public class HasMapTest { + public static void main(String[] args) { + // 如果使用的是 Map 没用直接的 forEach + HashMap hashMap = new HashMap<>(); + hashMap.put("a", 1); + hashMap.put("b", 2); + hashMap.put("c", 3); + hashMap.put("d", 4); + hashMap.put("e", 5); + + // 如果在这个Map中没用找到这个键返回默认的值 666 + System.out.println(hashMap.getOrDefault("n", 666)); + + // 拿到a的键 + System.out.println(hashMap.get("a")); + + // 是否包含键 a + System.out.println(hashMap.containsKey("a")); + + // 是否包含值 + System.out.println(hashMap.containsValue(1)); + + // 遍历 hashMap + hashMap.forEach((s, o) -> { + System.out.println("key:" + s); + System.out.println("value:" + o); + }); + hashMap.entrySet().forEach(System.out::println); + + // 将所以的键都添加到 hashMap 中 + HashMap addAllMap = new HashMap<>(); + addAllMap.put("f", 6); + addAllMap.put("g", 7); + addAllMap.put("h", 8); + addAllMap.put("i", 9); + hashMap.putAll(addAllMap); + System.out.println(hashMap); + } +} diff --git a/jTest/HashSetTest.java b/jTest/HashSetTest.java new file mode 100644 index 0000000..13d1eb0 --- /dev/null +++ b/jTest/HashSetTest.java @@ -0,0 +1,72 @@ +package jTest; + +import java.util.HashSet; +import java.util.NavigableSet; +import java.util.SortedSet; +import java.util.TreeSet; + +public class HashSetTest { + public static void main(String[] args) { + // 删除重复的元素 + HashSet hashSet = new HashSet<>() { + { + add("a"); + add("b"); + add("c"); + add("d"); + add("e"); + add("a"); + } + }; + System.out.println(hashSet);// [a, b, c, d, e] + hashSet.forEach(System.out::println); + + // TreeSet 会自动排序,即使是乱序也会自动排序 + TreeSet treeSet = new TreeSet<>() { + { + add("a"); + add("b"); + add("d"); + add("e"); + add("c"); + } + }; + System.out.println(treeSet);// [a, b, c, d, e] + treeSet.forEach(System.out::println); + + // 排序Tree + SortedSet sortedSet = new TreeSet<>() {{ + add("a"); + add("b"); + add("d"); + add("e"); + add("c"); + }}; + System.out.println(sortedSet);// [a, b, c, d, e] + sortedSet.forEach(System.out::println); + + NavigableSet navigableSet = new TreeSet<>() {{ + add("a"); + add("b"); + add("d"); + add("e"); + add("c"); + }}; + System.out.println(navigableSet);// [a, b, c, d, e] + // 大于a的元素,没用返回null + System.out.println(navigableSet.higher("a"));// b + // 小于a的元素,没用返回null + System.out.println(navigableSet.lower("a"));// null + // 小于等于b的元素,没有返回null + System.out.println(navigableSet.floor("b"));// b + // 大于等于 a 的元素,没用返回null + System.out.println(navigableSet.ceiling("a"));// a + + // 删除第一个元素 + navigableSet.pollFirst(); + System.out.println(navigableSet);// [b, c, d, e] + // 删除最后一个元素 + navigableSet.pollLast(); + System.out.println(navigableSet);// [b, c, d] + } +} diff --git a/jTest/TreeMapTest.java b/jTest/TreeMapTest.java new file mode 100644 index 0000000..e9b3587 --- /dev/null +++ b/jTest/TreeMapTest.java @@ -0,0 +1,40 @@ +package jTest; + +import java.util.SortedMap; +import java.util.TreeMap; + +public class TreeMapTest { + public static void main(String[] args) { + TreeMap treeMap = new TreeMap<>() {{ + put("c", 3); + put("a", 1); + put("b", 2); + put("e", 5); + put("d", 4); + }}; + + // 会自动排序 + System.out.println(treeMap); + + // 遍历集合 + treeMap.forEach((key, value) -> { + System.out.println("key:" + key); + System.out.println("value:" + value); + }); + + + SortedMap sortedMap = new TreeMap<>() {{ + put("c", 3); + put("a", 1); + put("b", 2); + put("e", 5); + put("d", 4); + }}; + + // 拿到第一个值 + System.out.println(sortedMap.firstKey()); + + // 最后一个值 + System.out.println(sortedMap.lastKey()); + } +} diff --git a/out/production/Kotlin-Demo/.idea/.gitignore b/out/production/Kotlin-Demo/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/out/production/Kotlin-Demo/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/out/production/Kotlin-Demo/.idea/Kotlin-Demo.iml b/out/production/Kotlin-Demo/.idea/Kotlin-Demo.iml new file mode 100644 index 0000000..f392c3c --- /dev/null +++ b/out/production/Kotlin-Demo/.idea/Kotlin-Demo.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Kotlin-Demo/.idea/codeStyles/codeStyleConfig.xml b/out/production/Kotlin-Demo/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/out/production/Kotlin-Demo/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/out/production/Kotlin-Demo/.idea/kotlinc.xml b/out/production/Kotlin-Demo/.idea/kotlinc.xml new file mode 100644 index 0000000..0dd4b35 --- /dev/null +++ b/out/production/Kotlin-Demo/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/out/production/Kotlin-Demo/.idea/libraries/KotlinJavaRuntime.xml b/out/production/Kotlin-Demo/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..409da39 --- /dev/null +++ b/out/production/Kotlin-Demo/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Kotlin-Demo/.idea/misc.xml b/out/production/Kotlin-Demo/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /dev/null +++ b/out/production/Kotlin-Demo/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Kotlin-Demo/.idea/modules.xml b/out/production/Kotlin-Demo/.idea/modules.xml new file mode 100644 index 0000000..c1b85cc --- /dev/null +++ b/out/production/Kotlin-Demo/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/Kotlin-Demo/.idea/uiDesigner.xml b/out/production/Kotlin-Demo/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/out/production/Kotlin-Demo/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Kotlin-Demo/BasicSyntax_LoopKt.class b/out/production/Kotlin-Demo/BasicSyntax_LoopKt.class new file mode 100644 index 0000000..bedb36c Binary files /dev/null and b/out/production/Kotlin-Demo/BasicSyntax_LoopKt.class differ diff --git a/out/production/Kotlin-Demo/META-INF/Kotlin-Demo.kotlin_module b/out/production/Kotlin-Demo/META-INF/Kotlin-Demo.kotlin_module new file mode 100644 index 0000000..faf0ad1 Binary files /dev/null and b/out/production/Kotlin-Demo/META-INF/Kotlin-Demo.kotlin_module differ diff --git a/out/production/Kotlin-Demo/jTest/FIleCopyBase.class b/out/production/Kotlin-Demo/jTest/FIleCopyBase.class new file mode 100644 index 0000000..b74b7d8 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/FIleCopyBase.class differ diff --git a/out/production/Kotlin-Demo/jTest/HasMapTest.class b/out/production/Kotlin-Demo/jTest/HasMapTest.class new file mode 100644 index 0000000..7b31d25 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/HasMapTest.class differ diff --git a/out/production/Kotlin-Demo/jTest/HashSetTest$1.class b/out/production/Kotlin-Demo/jTest/HashSetTest$1.class new file mode 100644 index 0000000..24574f2 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/HashSetTest$1.class differ diff --git a/out/production/Kotlin-Demo/jTest/HashSetTest$2.class b/out/production/Kotlin-Demo/jTest/HashSetTest$2.class new file mode 100644 index 0000000..9884ad5 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/HashSetTest$2.class differ diff --git a/out/production/Kotlin-Demo/jTest/HashSetTest$3.class b/out/production/Kotlin-Demo/jTest/HashSetTest$3.class new file mode 100644 index 0000000..67a23b1 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/HashSetTest$3.class differ diff --git a/out/production/Kotlin-Demo/jTest/HashSetTest$4.class b/out/production/Kotlin-Demo/jTest/HashSetTest$4.class new file mode 100644 index 0000000..82bd20c Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/HashSetTest$4.class differ diff --git a/out/production/Kotlin-Demo/jTest/HashSetTest.class b/out/production/Kotlin-Demo/jTest/HashSetTest.class new file mode 100644 index 0000000..4b56286 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/HashSetTest.class differ diff --git a/out/production/Kotlin-Demo/jTest/PropertiesTest.class b/out/production/Kotlin-Demo/jTest/PropertiesTest.class new file mode 100644 index 0000000..36f30a7 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/PropertiesTest.class differ diff --git a/out/production/Kotlin-Demo/jTest/TreeMapTest$1.class b/out/production/Kotlin-Demo/jTest/TreeMapTest$1.class new file mode 100644 index 0000000..25ff18d Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/TreeMapTest$1.class differ diff --git a/out/production/Kotlin-Demo/jTest/TreeMapTest$2.class b/out/production/Kotlin-Demo/jTest/TreeMapTest$2.class new file mode 100644 index 0000000..541dbf1 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/TreeMapTest$2.class differ diff --git a/out/production/Kotlin-Demo/jTest/TreeMapTest.class b/out/production/Kotlin-Demo/jTest/TreeMapTest.class new file mode 100644 index 0000000..f99ee51 Binary files /dev/null and b/out/production/Kotlin-Demo/jTest/TreeMapTest.class differ diff --git a/out/production/Kotlin-Demo/test1/BasicSyntax.class b/out/production/Kotlin-Demo/test1/BasicSyntax.class new file mode 100644 index 0000000..04cffd4 Binary files /dev/null and b/out/production/Kotlin-Demo/test1/BasicSyntax.class differ diff --git a/out/production/Kotlin-Demo/test1/BasicSyntaxKt.class b/out/production/Kotlin-Demo/test1/BasicSyntaxKt.class new file mode 100644 index 0000000..d8cb008 Binary files /dev/null and b/out/production/Kotlin-Demo/test1/BasicSyntaxKt.class differ diff --git a/test1/BasicSyntax.kt b/test1/BasicSyntax.kt new file mode 100644 index 0000000..0a18422 --- /dev/null +++ b/test1/BasicSyntax.kt @@ -0,0 +1,79 @@ +package test1 + +fun main() { + println("Hello world!") +} + +var x = 2 +var y: Int = 2 +val z: Int = 2 + + +fun main(array: Array) { + println(array.contentToString()) + print("Hello ") + print("world!\n") + main() + println(42) + val sum = sum(1, 2) + println(sum) + val sum2 = sum2(1, 6) + println(sum2) + println("总和为:$sum and $sum2 那么sum和sum2相加为:${sum + sum2}") + + val basicSyntax = BasicSyntax(2.0000, 6.0) + println(basicSyntax.percent) + + // 模板字符串 + var a = 1 + val b = "a 是 $a" + a = 2 + val c = "${b.replace("是", "就是")},但是现在的a是 $a" + println(c) + + // 返回最大值 + println(BasicSyntax(1.0,2.0).maxOf(1, 2)) + println(BasicSyntax(1.0,2.0).maxOf2(1, 2)) + println(maxOf3(1, 2)) + + // 循环 + val items = listOf("11", "22", "23", "24", "25") + for (item in items) { + println(item) + } + for (index in items.indices) { + println(index) + } +} + +fun sum(a: Int, b: Int): Int { + return a + b +} + +fun sum2(a: Int, b: Int) = a + b + +class BasicSyntax(height: Double, length: Double) { + val percent = (height + length) * 2 + fun maxOf(a: Int, b: Int): Int { + if (a > b) { + return a + } else { + return b + } + } + + fun maxOf2(a: Int, b: Int): Int { + return if (a > b) { + a + } else { + b + } + } +} + +/* The comment starts here +/* contains a nested comment */ +and ends here. */ + + +fun maxOf3(a:Int,b:Int)=if (a>b)a else b