diff --git a/kotlin/gradle/wrapper/gradle-wrapper.properties b/kotlin/gradle/wrapper/gradle-wrapper.properties index be52383..e1bef7e 100644 --- a/kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/kotlin/gradlew.bat b/kotlin/gradlew.bat index 107acd3..ac1b06f 100644 --- a/kotlin/gradlew.bat +++ b/kotlin/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/kotlin/lib/build.gradle.kts b/kotlin/lib/build.gradle.kts index 3cd2ccb..839b0c1 100644 --- a/kotlin/lib/build.gradle.kts +++ b/kotlin/lib/build.gradle.kts @@ -8,7 +8,7 @@ plugins { // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. - id("org.jetbrains.kotlin.jvm") version "1.3.72" + id("org.jetbrains.kotlin.jvm") version "1.8.20" // Apply the java-library plugin for API and implementation separation. `java-library` @@ -27,7 +27,7 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // This dependency is used internally, and not exposed to consumers on their own compile classpath. - implementation("com.google.guava:guava:29.0-jre") + implementation("com.google.guava:guava:31.1-jre") // Use the Kotlin test library. testImplementation("org.jetbrains.kotlin:kotlin-test") diff --git a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IPAddress.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IPAddress.kt index d801780..1a136a9 100644 --- a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IPAddress.kt +++ b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IPAddress.kt @@ -109,8 +109,8 @@ class IPAddress( companion object { fun sort(ipas: List): MutableList { - var ret = ipas.toMutableList() - ret.sortWith(Comparator { a, b -> a.compare(b); }) + val ret = ipas.toMutableList() + ret.sortWith({ a, b -> a.compare(b); }) return ret } @@ -204,7 +204,7 @@ class IPAddress( fun split_to_u32(addr: String): Result { var ip = 0L var shift = 24 - var split_addr = addr.split("."); //.collect::>() + var split_addr = addr.split(".") //.collect::>() if (split_addr.size > 4) { return Result.Err("IP has not the right format:${addr}") } @@ -272,7 +272,7 @@ class IPAddress( } fun split_to_num(addr: String): Result { - var pre_post = addr.trim().split("::").toMutableList() + val pre_post = addr.trim().split("::").toMutableList() if (pre_post.isEmpty() && addr.contains("::")) { //pre_post = Arrays.copyOf(pre_post, pre_post.size + 1) //pre_post.set(pre_post.size - 1, "") @@ -343,7 +343,7 @@ class IPAddress( if (pos < 0) { pos = 0 } - val stack_len = stack.size; // borrow checker + val stack_len = stack.size // borrow checker // println!("loop:{}:{}", pos, stack_len) // if stack_len == 1 { // println!("exit 1") @@ -376,15 +376,15 @@ class IPAddress( stack.get(first).includes(stack.get(second))) { pos = pos - 2 val idx = pos_to_idx(pos, stack_len) - stack.set(idx, stack.get(first).clone()); // kaputt + stack.set(idx, stack.get(first).clone()) // kaputt stack.removeAt(pos_to_idx(pos + 1, stack_len)) // println!("remove-2:{}:{}", pos + 1, stack_len) - pos = pos - 1; // backtrack + pos = pos - 1 // backtrack } else { val myFirst = stack.get(first) - stack.set(first, myFirst.change_prefix(myFirst.prefix.add(1).unwrap()).unwrap()); //reset prefix + stack.set(first, myFirst.change_prefix(myFirst.prefix.add(1).unwrap()).unwrap()) //reset prefix // println!("easy:{}:{}=>{}", pos, stack_len, stack[first].to_string()) - pos = pos - 1; // do it with second as first + pos = pos - 1 // do it with second as first } } } @@ -410,7 +410,7 @@ class IPAddress( } fun sum_first_found(arr: List): List { - var dup = arr.toMutableList() + val dup = arr.toMutableList() if (dup.size < 2) { return dup } @@ -431,7 +431,7 @@ class IPAddress( } fun to_ipaddress_vec(vec: List): Result> { - var ret = mutableListOf() + val ret = mutableListOf() for (ipstr in vec) { val ipa = parse(ipstr) if (ipa.isErr()) { @@ -691,11 +691,11 @@ class IPAddress( fun dns_parts(): IntArray { val len = this.ip_bits.bits / this.ip_bits.dns_bits - var ret = IntArray(len) + val ret = IntArray(len) var num = BigInteger.ZERO.add(this.host_address) val mask = BigInteger.ONE.shiftLeft(this.ip_bits.dns_bits) for (i in 0 until len) { - var part = num.mod(mask) + val part = num.mod(mask) num = num.shiftRight(this.ip_bits.dns_bits) ret.set(i, part.intValueExact()) } @@ -824,7 +824,7 @@ class IPAddress( /// /// "172.16.100.4/22" /// fun to_string(): String { - var ret = StringBuilder() + val ret = StringBuilder() ret.append(this.to_s()) ret.append("/") ret.append(this.prefix.to_s()) @@ -875,7 +875,7 @@ class IPAddress( fun bits(): String { val num = this.host_address.toString(2) - var ret = StringBuilder() + val ret = StringBuilder() for (i in num.length until this.ip_bits.bits) { ret.append("0") } @@ -1303,7 +1303,7 @@ class IPAddress( fun newprefix(num: Int): Result { for (i in num until this.ip_bits.bits) { - var a = Math.floor(Math.log(i.toDouble()) / Math.log(2.0)) + val a = Math.floor(Math.log(i.toDouble()) / Math.log(2.0)) if (a == Math.log(i.toDouble()) / Math.log(2.0)) { return this.prefix.add(a.toInt()) } diff --git a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpV4.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpV4.kt index 4aaf5c1..f7e9b44 100644 --- a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpV4.kt +++ b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/IpV4.kt @@ -2,9 +2,9 @@ package com.adviser.ipaddress.kotlin import java.math.BigInteger -val x80000000 = BigInteger.valueOf(2147483648L) -val xc0000000 = BigInteger.valueOf(3221225472L) -val xe0000000 = BigInteger.valueOf(3758096384L) +val x80000000: BigInteger = BigInteger.valueOf(2147483648L) +val xc0000000: BigInteger = BigInteger.valueOf(3221225472L) +val xe0000000: BigInteger = BigInteger.valueOf(3758096384L) val is_private = arrayOf( IPAddress.parse("10.0.0.0/8").unwrap(), @@ -49,7 +49,7 @@ class IpV4 { fun create(str: String): Result { val splitted = IPAddress.split_at_slash(str) if (!IPAddress.is_valid_ipv4(splitted.addr)) { - return Result.Err("Invalid IP ${str}") + return Result.Err("Invalid IP $str") } var ip_prefix_num = Result.Ok(32) if (splitted.netmask !== null) { diff --git a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Loopback.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Loopback.kt index d0ffe3f..c0e7eac 100644 --- a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Loopback.kt +++ b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Loopback.kt @@ -48,7 +48,7 @@ import java.math.BigInteger class Ipv6Loopback { companion object { fun create(): IPAddress { - return IpV6.from_int(BigInteger.ONE, 128).unwrap(); + return IpV6.from_int(BigInteger.ONE, 128).unwrap() } } } diff --git a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Mapped.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Mapped.kt index e71f002..58d9710 100644 --- a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Mapped.kt +++ b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Ipv6Mapped.kt @@ -86,7 +86,7 @@ class Ipv6Mapped { val split_colon = ret.addr.split(":") if (split_colon.size <= 1) { // println!("---1") - return Result.Err("not mapped format-1: ${str}") + return Result.Err("not mapped format-1: $str") } var netmask = "" if (ret.netmask != null) { diff --git a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix.kt index 147e8cf..5b5f4ef 100644 --- a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix.kt +++ b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix.kt @@ -8,7 +8,7 @@ interface VtFrom { } */ -public class Prefix(val num: Int, +class Prefix(val num: Int, val ip_bits: IpBits, val net_mask: BigInteger, val vt_from: (p: Prefix, n: Int) -> Result) { diff --git a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix128.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix128.kt index 2351a0a..623dfce 100644 --- a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix128.kt +++ b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Prefix128.kt @@ -1,7 +1,7 @@ package com.adviser.ipaddress.kotlin -public class Prefix128 { +class Prefix128 { companion object { diff --git a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Rle.kt b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Rle.kt index 219d100..672432d 100644 --- a/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Rle.kt +++ b/kotlin/lib/src/main/kotlin/com/adviser/ipaddress/Rle.kt @@ -7,7 +7,7 @@ class Rle(val part: Int, var pos: Int, var cnt: Int, var max: Boolean) { return " self.part, self.pos, self.cnt, self.max)" } - public final override fun equals(other: Any?): Boolean { + final override fun equals(other: Any?): Boolean { if (other is Rle) { return eq(other) } @@ -43,7 +43,7 @@ class Rle(val part: Int, var pos: Int, var cnt: Int, var max: Boolean) { _last.max = false } else if (prev.cnt == _last.cnt) { // nothing - } else if (prev.cnt < _last.cnt) { + } else /* if (prev.cnt < _last.cnt) */ { // println!("<<<<< last={:?}->{}->prev={:?}", _last, idx, prev) //this.ret[idx].max = false prev.max = false