Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

29
LINES

< > BotCompany Repo | #1026307 // nicelyFormatJsonDiff

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5837L/34K).

sS nicelyFormatJsonDiff(O diff) {
  new StringBuilderWithIndent buf;
  nicelyFormatJsonDiff(diff, buf);
  ret str(buf);
}

svoid nicelyFormatJsonDiff(O diff, StringBuilderWithIndent buf) {
  if (diff == null) ret with buf.println("No differences");
  if (diff cast JsonDiff.Removed)
    ret with buf.println("DELETE " + diff.a);
  if (diff cast JsonDiff.Added)
    ret with buf.println("ADD " + diff.b);
  if (diff cast JsonDiff.Different) // also covers DifferentType
    ret with buf.println(diff.a + " -> " + diff.b);
  if (diff cast Map<O>) {
    for (O key, O value : diff) {
      if (!value instanceof JsonDiff.Different
        || !key instanceof JsonDiff.GatheredKey)
        if (key cast JsonDiff.GatheredKey) {
          buf.println(key.key + "=" + key.value);
        } else
          buf.println(key);
      temp buf.indent();
      nicelyFormatJsonDiff(value, buf);
    }
    ret;
  }
  buf.println(sfu(diff)); // something unknown
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1026307
Snippet name: nicelyFormatJsonDiff
Eternal ID of this version: #1026307/15
Text MD5: 0250e7c86d193cf9cc94ca0220f02ede
Transpilation MD5: 06401e886b82ab52a3d026556f243145
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-02 04:32:36
Source code size: 975 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 241 / 400
Version history: 14 change(s)
Referenced in: [show references]