split Util to Quantifer and Time
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Sun, 22 Dec 2024 10:37:31 +0000 (10:37 +0000)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Sun, 22 Dec 2024 10:37:31 +0000 (10:37 +0000)
15 files changed:
developer/javacđź–‰/Mosaic_Logger.java
developer/javacđź–‰/Mosaic_Quantifier.java [new file with mode: 0644]
developer/javacđź–‰/Mosaic_Time.java [new file with mode: 0644]
developer/javacđź–‰/Mosaic_Util.java [deleted file]
developer/toolđź–‰/gather_third_party
documentđź–‰/LICENSE.txt [new symlink]
documentđź–‰/README.txt [new symlink]
release/Mosaic.jar
tester/javacđź–‰/Dispatcher_0.java
tester/javacđź–‰/Dispatcher_1.java
tester/javacđź–‰/Dispatcher_3.java
tester/javacđź–‰/IO.java
tester/javacđź–‰/Util.java
tester/javacđź–‰/smoke.java
tester/toolđź–‰/run_jdb [deleted file]

index 014d732..1abb5c1 100644 (file)
@@ -3,19 +3,13 @@ package com.ReasoningTechnology.Mosaic;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.time.Instant;
-import java.time.ZoneOffset;
-import java.time.format.DateTimeFormatter;
-
 public class Mosaic_Logger{
 
   private static final Logger LOGGER = LoggerFactory.getLogger(Mosaic_Logger.class);
-  private static final DateTimeFormatter ISO_UTC_FORMATTER =
-    DateTimeFormatter.ISO_INSTANT.withZone(ZoneOffset.UTC);
 
   // Formats and logs an output related to a specific test
   public static void output(String test_name, String stream, String output_data){
-    String timestamp = iso_utc_time();
+    String timestamp = Mosaic_Time.iso_UTC_time();
     String formatted_log = String.format(
       "\n%s -----------------------------------------------------------\n" +
       "Test: %s\n" +
@@ -29,7 +23,7 @@ public class Mosaic_Logger{
 
   // Logs a general message for a test
   public static void message(String test_name, String message){
-    String timestamp = iso_utc_time();
+    String timestamp = Mosaic_Time.iso_UTC_time();
     String formatted_log = String.format(
       "\n%s -----------------------------------------------------------\n" +
       "Test: %s\n" +
@@ -41,7 +35,7 @@ public class Mosaic_Logger{
   }
 
   public static void error(String test_name, String message, Throwable error){
-    String timestamp = iso_utc_time();
+    String timestamp = Mosaic_Time.iso_UTC_time();
     String formatted_log = String.format(
     "\n%s -----------------------------------------------------------\n" +
     "Test: %s\n" +
@@ -55,29 +49,4 @@ public class Mosaic_Logger{
     LOGGER.error(formatted_log, error);
   }
 
-  /*
-  // Logs an error with stack trace
-  public static void error(String test_name, String message, Throwable error){
-    String timestamp = iso_utc_time();
-    StringBuilder stack_trace = new StringBuilder();
-    for (StackTraceElement element : error.getStackTrace()){
-      stack_trace.append(element.toString()).append("\n");
-    }
-
-    String formatted_log = String.format(
-      "\n%s -----------------------------------------------------------\n" +
-      "Test: %s\n" +
-      "Message:\n%s\n" +
-      "Error:\n%s\n",
-      timestamp, test_name, message, stack_trace
-    );
-
-    LOGGER.error(formatted_log);
-  }
-  */
-  
-  // Utility to fetch the current time in ISO UTC format
-  private static String iso_utc_time(){
-    return ISO_UTC_FORMATTER.format(Instant.now());
-  }
 }
diff --git a/developer/javacđź–‰/Mosaic_Quantifier.java b/developer/javacđź–‰/Mosaic_Quantifier.java
new file mode 100644 (file)
index 0000000..493b3c0
--- /dev/null
@@ -0,0 +1,42 @@
+package com.ReasoningTechnology.Mosaic;
+
+import java.util.function.Predicate;
+
+public class Mosaic_Quantifier{
+
+  // Linear search with a predicate
+  public static <T> T find( T[] elements ,Predicate<T> predicate ){
+    for( T element : elements ){
+      if( predicate.test( element )) return element; // Return the first match
+    }
+    return null; // Return null if no element satisfies the predicate
+  }
+
+  // True when it does a search and finds a true value; otherwise false.
+  public static Boolean exists( Object[] elements ){
+    return elements.length > 0 && find( elements ,element -> (element instanceof Boolean) && (Boolean) element ) != null;
+  }
+
+  // True when it does a search and does not find a false value; otherwise false.
+  // Hence, all true for the empty set is false, which is appropriate for testing.
+  public static Boolean all( Object[] elements ){
+    return elements.length > 0 && find( elements ,element -> !(element instanceof Boolean) || !(Boolean) element ) == null;
+  }
+
+  public static void all_set_false( Boolean[] condition_list ){
+    int i = 0;
+    while(i < condition_list.length){
+      condition_list[i] = false;
+      i++;
+    }
+  }
+
+  public static void all_set_true( Boolean[] condition_list ){
+    int i = 0;
+    while(i < condition_list.length){
+      condition_list[i] = true;
+      i++;
+    }
+  }
+
+}
diff --git a/developer/javacđź–‰/Mosaic_Time.java b/developer/javacđź–‰/Mosaic_Time.java
new file mode 100644 (file)
index 0000000..6e30236
--- /dev/null
@@ -0,0 +1,13 @@
+package com.ReasoningTechnology.Mosaic;
+
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+
+public class Mosaic_Time{
+
+  public static String iso_UTC_time(){
+    return Instant.now().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT);
+  }
+
+}
diff --git a/developer/javacđź–‰/Mosaic_Util.java b/developer/javacđź–‰/Mosaic_Util.java
deleted file mode 100644 (file)
index 1fba0cc..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.ReasoningTechnology.Mosaic;
-
-import java.time.Instant;
-import java.time.ZoneOffset;
-import java.time.format.DateTimeFormatter;
-import java.util.function.Predicate;
-
-public class Mosaic_Util{
-
-  // Linear search with a predicate
-  public static <T> T find( T[] elements ,Predicate<T> predicate ){
-    for( T element : elements ){
-      if( predicate.test( element )) return element; // Return the first match
-    }
-    return null; // Return null if no element satisfies the predicate
-  }
-
-  // True when it does a search and finds a true value; otherwise false.
-  public static Boolean exists( Object[] elements ){
-    return elements.length > 0 && find( elements ,element -> (element instanceof Boolean) && (Boolean) element ) != null;
-  }
-
-  // True when it does a search and does not find a false value; otherwise false.
-  public static Boolean all( Object[] elements ){
-    return elements.length > 0 && find( elements ,element -> !(element instanceof Boolean) || !(Boolean) element ) == null;
-  }
-
-  public static void all_set_false( Boolean[] condition_list ){
-    int i = 0;
-    while(i < condition_list.length){
-      condition_list[i] = false;
-      i++;
-    }
-  }
-
-  public static void all_set_true( Boolean[] condition_list ){
-    int i = 0;
-    while(i < condition_list.length){
-      condition_list[i] = true;
-      i++;
-    }
-  }
-
-  public static String iso_utc_time(){
-    return Instant.now().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT);
-  }
-
-
-
-}
index e2c9bd9..1e81ace 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/env bash
 script_afp=$(realpath "${BASH_SOURCE[0]}")
 
-# This script expands Mosaic third party projects onto the scratchpad. This is done before releasing or running local ad hoc tests, so that the third party tools will be present.
+# This script expands Mosaic third party projects onto the scratchpad. This is done before releasing or running local ad hoc tests, so that the third party tools will be present.  I.e. this is for creating a 'fat' jar.
 
 # Input guards
 
@@ -13,7 +13,7 @@ script_afp=$(realpath "${BASH_SOURCE[0]}")
 
   cd "$REPO_HOME"/developer
 
-# Link sources into the package tree
+# Expand the third party tools into the package tree
 
   echo "Expanding .jar files to be included with Mosaic into scratchpad."
 
diff --git a/documentđź–‰/LICENSE.txt b/documentđź–‰/LICENSE.txt
new file mode 120000 (symlink)
index 0000000..4ab4373
--- /dev/null
@@ -0,0 +1 @@
+../LICENSE.txt
\ No newline at end of file
diff --git a/documentđź–‰/README.txt b/documentđź–‰/README.txt
new file mode 120000 (symlink)
index 0000000..ecfa029
--- /dev/null
@@ -0,0 +1 @@
+../README.txt
\ No newline at end of file
index 18cae87..f5b1a35 100644 (file)
Binary files a/release/Mosaic.jar and b/release/Mosaic.jar differ
index 869f6ff..7f4e1f2 100644 (file)
@@ -1,6 +1,6 @@
 import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher;
 import com.ReasoningTechnology.Mosaic.Mosaic_IsPrimitive;
-import com.ReasoningTechnology.Mosaic.Mosaic_Util;
+import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier;
 
 import tester.TestClasses_0;
 import tester.TestClasses_1;
@@ -34,7 +34,7 @@ public class Dispatcher_0{
 
   public static boolean test_make_0(){
     Boolean[] condition_list = new Boolean[4];
-    Mosaic_Util.all_set_false(condition_list);
+    Mosaic_Quantifier.all_set_false(condition_list);
     int i = 0;
 
     Mosaic_Dispatcher d1 = new Mosaic_Dispatcher(TestClasses_1.class);
@@ -51,7 +51,7 @@ public class Dispatcher_0{
     TestClasses_1 tc3 = (TestClasses_1) d1.make(new Mosaic_IsPrimitive(21) ,new Mosaic_IsPrimitive(17) );
     condition_list[i++] = tc3.get_i() == 38;
 
-    return Mosaic_Util.all(condition_list);
+    return Mosaic_Quantifier.all(condition_list);
   }
 
   // Test public static method
index 8bd7462..4758510 100644 (file)
@@ -1,5 +1,5 @@
 import com.ReasoningTechnology.Mosaic.Mosaic_Dispatcher;
-import com.ReasoningTechnology.Mosaic.Mosaic_Util;
+import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier;
 
 import tester.TestClasses_0;
 
index ca28d1e..e79a1af 100644 (file)
@@ -10,9 +10,9 @@ public class Dispatcher_3{
       Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher("tester.TestClasses_0$APrivateClass_02");
       Object nested_instance = nested_dispatcher.make(new Object[]{outer_instance});
       boolean result = nested_dispatcher.dispatch(
-        nested_instance ,
-        boolean.class ,
-        "a_public_method_5"
+        nested_instance
+        ,boolean.class
+        ,"a_public_method_5"
       );
       return result;
     }catch(Throwable t){
@@ -28,9 +28,9 @@ public class Dispatcher_3{
       Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher("tester.TestClasses_0$APrivateClass_02");
       Object nested_instance = nested_dispatcher.make(new Object[]{outer_instance});
       boolean result = nested_dispatcher.dispatch(
-        nested_instance ,
-        boolean.class ,
-        "a_private_method_6"
+        nested_instance
+        ,boolean.class
+        ,"a_private_method_6"
       );
       return result;
     }catch(Throwable t){
@@ -46,9 +46,9 @@ public class Dispatcher_3{
       TestClasses_0.APublicClass_01 nested_instance = outer.new APublicClass_01();
       Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class);
       boolean result = nested_dispatcher.dispatch(
-        nested_instance ,
-        boolean.class ,
-        "a_public_method_3"
+        nested_instance
+        ,boolean.class
+        ,"a_public_method_3"
       );
       return result;
     }catch(Throwable t){
@@ -64,9 +64,9 @@ public class Dispatcher_3{
       TestClasses_0.APublicClass_01 nested_instance = outer.new APublicClass_01();
       Mosaic_Dispatcher nested_dispatcher = new Mosaic_Dispatcher(TestClasses_0.APublicClass_01.class);
       boolean result = nested_dispatcher.dispatch(
-        nested_instance ,
-        boolean.class ,
-        "a_private_method_4"
+        nested_instance
+        ,boolean.class
+        ,"a_private_method_4"
       );
       return result;
     }catch(Throwable t){
index 18e8a8f..5615a09 100644 (file)
@@ -1,5 +1,5 @@
 import com.ReasoningTechnology.Mosaic.Mosaic_IO;
-import com.ReasoningTechnology.Mosaic.Mosaic_Util;
+import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier;
 
 public class IO{
 
@@ -53,7 +53,7 @@ public class IO{
     // Restore original IO streams
     io.restore();
 
-    if(!Mosaic_Util.all(condition)){
+    if(!Mosaic_Quantifier.all(condition)){
       System.out.println("IO failed");
       return 1;
     }
index 210fe71..78e30c9 100644 (file)
@@ -1,4 +1,4 @@
-import com.ReasoningTechnology.Mosaic.Mosaic_Util;
+import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier;
 
 /*
 Util
@@ -10,23 +10,23 @@ public class Util{
   public static Boolean test_all(){
     // Test with zero condition
     Boolean[] condition0 = {};
-    Boolean result = !Mosaic_Util.all(condition0);  // Empty condition list is false.
+    Boolean result = !Mosaic_Quantifier.all(condition0);  // Empty condition list is false.
 
     // Test with one condition
     Boolean[] condition1_true = {true};
     Boolean[] condition1_false = {false};
-    result &= Mosaic_Util.all(condition1_true);    // should return true
-    result &= !Mosaic_Util.all(condition1_false);  // should return false
+    result &= Mosaic_Quantifier.all(condition1_true);    // should return true
+    result &= !Mosaic_Quantifier.all(condition1_false);  // should return false
 
     // Test with two condition
     Boolean[] condition2_true = {true, true};
     Boolean[] condition2_false1 = {true, false};
     Boolean[] condition2_false2 = {false, true};
     Boolean[] condition2_false3 = {false, false};
-    result &= Mosaic_Util.all(condition2_true);     // should return true
-    result &= !Mosaic_Util.all(condition2_false1);  // should return false
-    result &= !Mosaic_Util.all(condition2_false2);  // should return false
-    result &= !Mosaic_Util.all(condition2_false3);  // should return false
+    result &= Mosaic_Quantifier.all(condition2_true);     // should return true
+    result &= !Mosaic_Quantifier.all(condition2_false1);  // should return false
+    result &= !Mosaic_Quantifier.all(condition2_false2);  // should return false
+    result &= !Mosaic_Quantifier.all(condition2_false3);  // should return false
 
     // Test with three condition
     Boolean[] condition3_false1 = {true, true, false};
@@ -34,24 +34,24 @@ public class Util{
     Boolean[] condition3_false2 = {true, false, true};
     Boolean[] condition3_false3 = {false, true, true};
     Boolean[] condition3_false4 = {false, false, false};
-    result &= !Mosaic_Util.all(condition3_false1); // should return false
-    result &= Mosaic_Util.all(condition3_true);    // should return true
-    result &= !Mosaic_Util.all(condition3_false2); // should return false
-    result &= !Mosaic_Util.all(condition3_false3); // should return false
-    result &= !Mosaic_Util.all(condition3_false4); // should return false
+    result &= !Mosaic_Quantifier.all(condition3_false1); // should return false
+    result &= Mosaic_Quantifier.all(condition3_true);    // should return true
+    result &= !Mosaic_Quantifier.all(condition3_false2); // should return false
+    result &= !Mosaic_Quantifier.all(condition3_false3); // should return false
+    result &= !Mosaic_Quantifier.all(condition3_false4); // should return false
 
     return result;
   }
 
   public static Boolean test_all_set_false(){
     Boolean[] condition_list = {true, true, true};
-    Mosaic_Util.all_set_false(condition_list);
+    Mosaic_Quantifier.all_set_false(condition_list);
     return !condition_list[0] && !condition_list[1] && !condition_list[2]; 
   }
 
   public static Boolean test_all_set_true(){
     Boolean[] condition_list = {false, false, false};
-    Mosaic_Util.all_set_true(condition_list);
+    Mosaic_Quantifier.all_set_true(condition_list);
     return condition_list[0] && condition_list[1] && condition_list[2]; 
   }
   
index ccfc75e..567b8f6 100644 (file)
@@ -1,4 +1,4 @@
-import com.ReasoningTechnology.Mosaic.Mosaic_Util;
+import com.ReasoningTechnology.Mosaic.Mosaic_Quantifier;
 
 /*
 Plug it in, see if there is smoke. There usually is.
@@ -16,7 +16,7 @@ public class smoke{
     condition[0] = test_is_true();
 
     int i = 0;
-    if( !Mosaic_Util.all(condition) ){
+    if( !Mosaic_Quantifier.all(condition) ){
       System.out.println("Test0 failed");
       return 1;
     }
diff --git a/tester/toolđź–‰/run_jdb b/tester/toolđź–‰/run_jdb
deleted file mode 100755 (executable)
index 8334c1b..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/env bash
-script_afp=$(realpath "${BASH_SOURCE[0]}")
-
-# input guards
-env_must_be="tester/toolđź–‰/env"
-if [ "$ENV" != "$env_must_be" ]; then
-  echo "$(script_fp):: error: must be run in the $env_must_be environment"
-  exit 1
-fi
-
-jdb -sourcepath "$SOURCEPATH" "$@"
-