From: Marko Luukkainen Date: Wed, 23 Feb 2022 15:07:58 +0000 (+0200) Subject: Make GraphChanges Statement and Modification print functions public. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=e334209213fe36fd7b4f209fa41a15f1e3b9c751;p=simantics%2Finterop.git Make GraphChanges Statement and Modification print functions public. gitlab #37 Change-Id: Id717b5ccf97241d03579553649738b017edf0a5b --- diff --git a/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java b/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java index ce7af6d..a688906 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java @@ -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)+"...";