This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a commit to branch NLPCRAFT-520
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-520 by this push:
     new 1a2620a2 WIP.
1a2620a2 is described below

commit 1a2620a2047c697e6c3273774266ff7482d65791
Author: Sergey Kamov <[email protected]>
AuthorDate: Sun Dec 18 17:25:03 2022 +0400

    WIP.
---
 .../apache/nlpcraft/internal/util/NCUtils.scala    | 61 ----------------------
 .../nlpcraft/internal/util/NCUtilsSpec.scala       | 33 ++++++++++--
 2 files changed, 28 insertions(+), 66 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
index 8804faac..6791429d 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
@@ -223,19 +223,6 @@ object NCUtils extends LazyLogging:
         else if isUrl(src) then new URL(src).openStream()
         else E(s"Source not found or unsupported: $src")
 
-    /**
-      * Sleeps number of milliseconds properly handling exceptions.
-      *
-      * @param delay Number of milliseconds to sleep.
-      */
-    def sleep(delay: Long): Unit =
-        try
-            Thread.sleep(delay)
-        catch
-            case _: InterruptedException => Thread.currentThread().interrupt()
-            case e: Throwable => logger.warn("Unhandled exception caught 
during sleep:", e)
-
-
     /**
       * Interrupts thread and waits for its finish.
       *
@@ -277,54 +264,6 @@ object NCUtils extends LazyLogging:
       */
     def distinct[T](seq: List[T]): List[T] = if containsDups(seq) then 
seq.distinct else seq
 
-    /**
-      * Safely and silently closes the client socket.
-      *
-      * @param sock Client socket to close.
-      */
-    def close(sock: Socket): Unit =
-        if sock != null then
-            try sock.close()
-            catch case _: Exception => ()
-
-    /**
-      * Safely and silently closes the server socket.
-      *
-      * @param sock Server socket to close.
-      */
-    def close(sock: ServerSocket): Unit =
-        if sock != null then
-            try sock.close()
-            catch case _: Exception => ()
-
-    /**
-      *
-      * @param in Stream.
-      */
-    def close(in: InputStream): Unit =
-        if in != null then
-            try in.close()
-            catch case _: Exception => ()
-
-    /**
-      *
-      * @param out Stream.
-      */
-    def close(out: OutputStream): Unit =
-        if out != null then
-            try out.close()
-            catch case _: Exception => ()
-
-    /**
-      * Closes auto-closeable ignoring any exceptions.
-      *
-      * @param a Resource to close.
-      */
-    def close(a: AutoCloseable): Unit =
-        if a != null then
-            try a.close()
-            catch case _: Exception => ()
-
     /**
       *
       * @param s
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/util/NCUtilsSpec.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/util/NCUtilsSpec.scala
index eeb70057..f64c851f 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/util/NCUtilsSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/util/NCUtilsSpec.scala
@@ -18,19 +18,42 @@
 package org.apache.nlpcraft.internal.util
 
 import org.scalatest.funsuite.AnyFunSuite
+import org.apache.nlpcraft.internal.util.NCUtils as U
 
-import java.io.FileInputStream
+import java.io.*
 
 /**
   *
   */
 class NCUtilsSpec extends AnyFunSuite:
-    test("test") {
+    test("test sources") {
         val res = "moby/354984si.ngl"
         val file = NCResourceReader.get("badfilter/swear_words.txt")
         val is = new FileInputStream(file)
 
-        require(NCUtils.readLines(res).toList.nonEmpty)
-        require(NCUtils.readLines(file).toList.nonEmpty)
-        require(NCUtils.readLines(is).toList.nonEmpty)
+        require(U.readLines(res).toList.nonEmpty)
+        require(U.readLines(file).toList.nonEmpty)
+        require(U.readLines(is).toList.nonEmpty)
+    }
+
+    test("test parameters") {
+        val data = Seq(
+            "#",
+            "",
+            " AA",
+            "a"
+        )
+
+        val arr = data.mkString("\n").getBytes
+
+        var lines = U.readLines(new ByteArrayInputStream(arr), strip = 
false).toList
+
+        require(lines.length == 4)
+        require(lines.exists(_.contains(" AA")))
+
+        lines = U.readLines(new ByteArrayInputStream(arr), convert = 
_.toLowerCase, filterText = true).toList
+
+        require(lines.length == 2)
+        require(!lines.exists(_.contains(" AA")))
+        require(lines.exists(_.contains("aa")))
     }
\ No newline at end of file

Reply via email to