package tdl.client.audit;

/**
 * Created by julianghionoiu on 03/02/2016.
 */
public final class PresentationUtils {

    private PresentationUtils() {
        //Utility class
    }

    public static String toDisplayableString(Object ... items) {
        StringBuilder sb = new StringBuilder();
        for (Object item : items) {
            if (sb.length() > 0) {
                sb.append(", ");
            }


            String representation = ""+item;

            if (representation.contains("\n")) {
                String[] parts = representation.split("\n");
                representation = parts[0];

                int suppressedParts = parts.length - 1;
                representation += " .. ( "+ suppressedParts +" more line";

                if (suppressedParts > 1) {
                    representation += "s";
                }

                representation += " )";
            }

            if (item instanceof Number) {
                sb.append(representation);
            } else {
                sb.append("\"").append(representation).append("\"");
            }
        }
        return sb.toString();
    }

}

@@ -232,12 +232,10 @@
 ject
- ...
+%5B%5D
  ite
@@ -411,44 +411,575 @@
  %7D%0A%0A
-%0A            String representation =
+            sb.append(toDisplayableString(item));%0A        %7D%0A        return sb.toString();%0A    %7D%0A%0A    public static String toDisplayableString(Object item) %7B%0A        String representation = asString(item);%0A%0A        if (isMultilineString(representation)) %7B%0A            representation = suppressExtraLines(representation);%0A        %7D%0A%0A        if (isNotNumber(item)) %7B%0A            representation = addQuotes(representation);%0A        %7D%0A%0A        return representation;%0A    %7D%0A%0A    //~~~ Handle individual item%0A%0A    private static String asString(Object item) %7B%0A        return
  %22%22+
@@ -988,66 +988,312 @@
 em;%0A
-%0A
     
+%7D%0A%0A
     
-    if (representation.contains(%22%5Cn%22)) %7B%0A        
+private static boolean isMultilineString(String representation) %7B%0A        return representation.contains(%22%5Cn%22);%0A    %7D%0A%0A    private static boolean isNotNumber(Object item) %7B%0A        return ! (item instanceof Number);%0A    %7D%0A%0A    private static String suppressExtraLines(String representation) %7B%0A
     
@@ -1345,32 +1345,24 @@
 %22);%0A        
-       
- 
 representati
@@ -1377,24 +1377,16 @@
 ts%5B0%5D;%0A%0A
-        
         
@@ -1425,24 +1425,16 @@
 th - 1;%0A
-        
         
@@ -1493,24 +1493,16 @@
 line%22;%0A%0A
-        
         
@@ -1524,32 +1524,24 @@
 arts %3E 1) %7B%0A
-        
             
@@ -1571,35 +1571,19 @@
         
-        %7D%0A%0A        
+%7D%0A%0A
         
@@ -1618,242 +1618,138 @@
     
-    %7D%0A%0A            if (item instanceof Number) %7B%0A                sb.append(representation);%0A            %7D else %7B%0A                sb.append(%22%5C%22%22).append(representation).append(%22%5C%22%22);%0A            %7D%0A        %7D%0A        return sb.toString()
+return representation;%0A    %7D%0A%0A    private static String addQuotes(String representation) %7B%0A        return %22%5C%22%22+representation+%22%5C%22%22
 ;%0A  

TIDY Refactor PresentationUtils to better describe the logic