]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Make GraphChanges Statement and Modification print functions public. 97/4897/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 23 Feb 2022 15:07:58 +0000 (17:07 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 23 Feb 2022 15:07:58 +0000 (17:07 +0200)
gitlab #37

Change-Id: Id717b5ccf97241d03579553649738b017edf0a5b

org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java

index ce7af6d1aee6c3f8ff1f81cffa6c33cfe06f1b86..a68890651f2a38b522ce6ef13066f7b5df89a8fe 100644 (file)
@@ -157,48 +157,58 @@ public class GraphChanges {
                StringBuilder sb = new StringBuilder();
                sb.append("Del:\n");
                for (Statement stm : deletions) {
-                       sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+
-                                                  NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
-                                                  NameUtils.getSafeName(graph, stm.getObject()) + " (" +
-                                                  stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+                       sb.append(toString(graph, stm));
+                       sb.append("\n");
        }
                sb.append("Add:\n");
                for (Statement stm : additions) {
-                       sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+
-                                          NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
-                                  NameUtils.getSafeName(graph, stm.getObject()) + " (" +
-                                  stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+                       sb.append(toString(graph, stm));
+                       sb.append("\n");
        }
                sb.append("Mod:\n");
                for (Modification mod :modifications) {
-                       {
-                               Statement stm = mod.getLeftStm();
-                               if (stm != null) {
-                                       sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+
-                                                          NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
-                                                          truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" +
-                                                          mod.getLeftSub() + " " + stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
-                               } else {
-                                       sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+  mod.getLeftSub() + " N/A\n");
-                               }
+                       sb.append(toString(graph, mod));
+                       sb.append("\n");
+       }
+               return sb.toString();
+       }
+       
+       public static String toString(ReadGraph graph, Statement stm) throws DatabaseException{
+               return NameUtils.getSafeName(graph, stm.getSubject()) + " "+
+                                  NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+                          NameUtils.getSafeName(graph, stm.getObject()) + " (" +
+                          stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject();
+       }
+       
+       public static String toString(ReadGraph graph, Modification mod) throws DatabaseException{
+               StringBuilder sb = new StringBuilder();
+               {
+                       Statement stm = mod.getLeftStm();
+                       if (stm != null) {
+                               sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+
+                                                  NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+                                                  truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" +
+                                                  mod.getLeftSub() + " " + stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+                       } else {
+                               sb.append(NameUtils.getSafeName(graph, mod.getLeftSub()) + " "+  mod.getLeftSub() + " N/A\n");
                        }
-                       {
-                               Statement stm = mod.getRightStm();
-                               if (stm != null) {
-                                       sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+
-                                                          NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
-                                                          truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" +
-                                                          mod.getRightSub() + " " + stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
-                               } else {
-                                       sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+  mod.getRightSub() + " N/A\n");
-                               }
-                               
+               }
+               {
+                       Statement stm = mod.getRightStm();
+                       if (stm != null) {
+                               sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+
+                                                  NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+                                                  truncate(NameUtils.getSafeName(graph, stm.getObject())) + " (" +
+                                                  mod.getRightSub() + " " + stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")");
+                       } else {
+                               sb.append(NameUtils.getSafeName(graph, mod.getRightSub()) + " "+  mod.getRightSub() + " N/A");
                        }
-       }
+                       
+               }
                return sb.toString();
        }
        
-       public String truncate(String s) {
+       public static String truncate(String s) {
                if (s.length() < 100)
                        return s;
                return s.substring(0, 100)+"...";