commit 84937a3ffc7efed6176601dca89e591385e6a11b
Author: @havlijan17 <havlijan@students.zcu.cz>
Date:   Mon May 4 22:09:31 2020 +0200

    re #7893 comments into code and Javadoc
    Added for jdeserialize and its usage in Converter.java
    Not sure if this level of refactoring is enough - better check

diff --git a/project/Deserializer/src/Converter.java b/project/Deserializer/src/Converter.java
index e3ba882..1e50c5d 100644
--- a/project/Deserializer/src/Converter.java
+++ b/project/Deserializer/src/Converter.java
@@ -74,6 +74,8 @@ public class Converter extends Thread {
 		while (active.get()) {
 			AtomicReference<File> inputFile = new AtomicReference<File>();
 			AtomicReference<DB_Messenger> query = new AtomicReference<DB_Messenger>();
+			StringBuilder json = new StringBuilder();
+			boolean error = false;
 
 			if (!getInput(inputFile, query)) {
 				continue;
@@ -87,11 +89,8 @@ public class Converter extends Thread {
 				continue;
 			}
 			
-			StringBuilder json = new StringBuilder();
-			
-			boolean error = false;
 			try {
-				// Redirectovany system.out do null streamu. Mozno redirect do souboru
+				// Redirection of System.out to jdeserialize log file
 				System.setOut(FileWorker.createRedirectStream(false));
 				System.setErr(FileWorker.createRedirectStream(true));
 				System.out.println("--- jdeserialize begins ---".toUpperCase());
@@ -122,10 +121,17 @@ public class Converter extends Thread {
 		return array;
 	}
 	
+	/**
+	 * Converts the input byte buffer given by parameter into json
+	 * which is saved using the StringBuilder.
+	 * 
+	 * @param buffer  byte array buffer for input data of serialized object
+	 * @param json	  StringBuilder to which will be saved the json result
+	 */
 	private void convert(byte[] buffer, StringBuilder json) throws Exception {
 		jdeserialize deserializer = new jdeserialize(buffer);
 
-		// gets the "contents" into an array - returnes the deserialization of all
+		// gets the "contents" into an array - returns the deserialization of all
 		// 'writes' into serialized object via objectOutputStream
 		List<content> cntnts = deserializer.getContent();
 
diff --git a/project/Deserializer/src/jdeserialize/arrayobj.java b/project/Deserializer/src/jdeserialize/arrayobj.java
index 9b9409f..22a48a6 100644
--- a/project/Deserializer/src/jdeserialize/arrayobj.java
+++ b/project/Deserializer/src/jdeserialize/arrayobj.java
@@ -35,12 +35,11 @@ public class arrayobj extends contentbase {
     public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, boolean child) {
         StringBuilder sb = new StringBuilder();
         boolean bracketInserted = false;
-        boolean isLast = false;
 
         for(int i = 0; i < this.data.size(); i++) {
             Object el = this.data.get(i);
             
-            isLast = (i == this.data.size()-1) || (this.data.get(i+1) == null);
+            boolean isLast = (i == this.data.size()-1) || (this.data.get(i+1) == null);
 
             if (el != null) {
                 if (el instanceof content) {
@@ -64,15 +63,16 @@ public class arrayobj extends contentbase {
                         sb.append("[ ");
                         bracketInserted = true;
                     }
+                    
                     sb.append(el.toString());
+                    
                     if (!isLast) {
                         sb.append(", ");
                     }
-                    if (isLast) {
+                    else {
                         sb.append(" ]");
                     }
                 }
-                
             }
         }
         return sb.toString();
diff --git a/project/Deserializer/src/jdeserialize/classdesc.java b/project/Deserializer/src/jdeserialize/classdesc.java
index 28f717d..f2b2629 100644
--- a/project/Deserializer/src/jdeserialize/classdesc.java
+++ b/project/Deserializer/src/jdeserialize/classdesc.java
@@ -1,21 +1,22 @@
 package jdeserialize;
+
 import java.io.*;
 import java.util.*;
 
 /**
  * <p>
- * Represents the entire serialized prototype of the class, including all fields,
- * inner classes, class annotations, and inheritance hierarchy.  This includes proxy class
- * descriptions.
+ * Represents the entire serialized prototype of the class, including all
+ * fields, inner classes, class annotations, and inheritance hierarchy. This
+ * includes proxy class descriptions.
  * </p>
  *
  * <p>
- * Generally, this class is used to represent the type of an instance written to an
- * ObjectOutputStream with its writeObject() method, or of a related array or field type.
- * However, there's a notable exception: when instances of type java.io.ObjectStreamClass
- * are written with writeObject(), only their class description is written (cf. Object
- * Serialization Specification, 4.3).  They will be represented with an instance of
- * classdesc as well.
+ * Generally, this class is used to represent the type of an instance written to
+ * an ObjectOutputStream with its writeObject() method, or of a related array or
+ * field type. However, there's a notable exception: when instances of type
+ * java.io.ObjectStreamClass are written with writeObject(), only their class
+ * description is written (cf. Object Serialization Specification, 4.3). They
+ * will be represented with an instance of classdesc as well.
  * </p>
  */
 public class classdesc extends contentbase {
@@ -35,8 +36,9 @@ public class classdesc extends contentbase {
     public long serialVersionUID;
 
     /**
-     * Description flags byte; this should be a mask of values from the ObjectStreamContants 
-     * class.  Refer to chapter 6 of the Object Stream Serialization Protocol for details.
+     * Description flags byte; this should be a mask of values from the
+     * ObjectStreamContants class. Refer to chapter 6 of the Object Stream
+     * Serialization Protocol for details.
      */
     public byte descflags;
 
@@ -49,11 +51,16 @@ public class classdesc extends contentbase {
      * List of inner classes, in the order serialized by the stream writer.
      */
     public List<classdesc> innerclasses;
-    
+
     /**
-     * List of annotation objects; these are *not* Java annotations, but data written by
-     * the <pre>annotateClass(Class<?>)<pre> and <pre>annotateProxyClass(Class<?>)</pre> methods of an
-     * ObjectOutputStream.  
+     * List of annotation objects; these are *not* Java annotations, but data
+     * written by the
+     * 
+     * <pre>
+     * annotateClass(Class<?>)<pre> and <pre>annotateProxyClass(Class<?>)
+     * </pre>
+     * 
+     * methods of an ObjectOutputStream.
      */
     public List<content> annotations;
 
@@ -73,15 +80,17 @@ public class classdesc extends contentbase {
     public Set<String> enumconstants;
 
     private boolean isInnerClass = false;
+
     /**
-     * True if this class has been determined to be an inner class; this determination is
-     * generally made by connectMemberClasses().
+     * True if this class has been determined to be an inner class; this
+     * determination is generally made by connectMemberClasses().
      * 
      * @return true if the class is an inner class
      */
     public boolean isInnerClass() {
         return isInnerClass;
     }
+
     /**
      * Sets the value that denotes that the class is an inner class.
      *
@@ -92,6 +101,7 @@ public class classdesc extends contentbase {
     }
 
     private boolean isLocalInnerClass = false;
+
     /**
      * True if this class has been determined to be a local inner class; this
      * determination is generally made by connectMemberClasses().
@@ -101,6 +111,7 @@ public class classdesc extends contentbase {
     public boolean isLocalInnerClass() {
         return isLocalInnerClass;
     }
+
     /**
      * Sets the flag that denotes whether this class is a local inner class.
      * 
@@ -111,6 +122,7 @@ public class classdesc extends contentbase {
     }
 
     private boolean isStaticMemberClass = false;
+
     /**
      * <p>
      * True if this class has been determined to be a static member class; this
@@ -118,9 +130,9 @@ public class classdesc extends contentbase {
      * </p>
      *
      * <p>
-     * Note that in some cases, static member classes' descriptions will be serialized
-     * even though their enclosing class is not.  In these cases, this may return false.
-     * See connectMemberClasses() for details.
+     * Note that in some cases, static member classes' descriptions will be
+     * serialized even though their enclosing class is not. In these cases, this may
+     * return false. See connectMemberClasses() for details.
      * </p>
      *
      * @return true if this is a static member class
@@ -128,6 +140,7 @@ public class classdesc extends contentbase {
     public boolean isStaticMemberClass() {
         return isStaticMemberClass;
     }
+
     /**
      * Sets the flag that denotes whether this class is a static member class.
      *
@@ -151,6 +164,7 @@ public class classdesc extends contentbase {
 
     /**
      * Add an inner class to the description's list.
+     * 
      * @param cd inner class to add
      */
     public void addInnerClass(classdesc cd) {
@@ -167,16 +181,18 @@ public class classdesc extends contentbase {
     }
 
     /**
-     * Determines whether this is an array type. 
+     * Determines whether this is an array type.
+     * 
      * @return true if this is an array type.
      */
     public boolean isArrayClass() {
-        if(name != null && name.length() > 1 && name.charAt(0) == '[') {
+        if (name != null && name.length() > 1 && name.charAt(0) == '[') {
             return true;
         } else {
             return false;
         }
     }
+
     public String toString() {
         StringBuffer sb = new StringBuffer();
         sb.append("[cd ").append(jdeserialize.hex(handle)).append(": name ").append(name);
@@ -186,128 +202,136 @@ public class classdesc extends contentbase {
     }
 
     /**
-     * Generates a list of all class descriptions in this class's hierarchy, in the order
-     * described by the Object Stream Serialization Protocol.  This is the order in which
-     * fields are read from the stream.
+     * Generates a list of all class descriptions in this class's hierarchy, in the
+     * order described by the Object Stream Serialization Protocol. This is the
+     * order in which fields are read from the stream.
      * 
      * @param classes a list to be filled in with the hierarchy
      */
     public void getHierarchy(ArrayList<classdesc> classes) {
-        if(superclass != null) {
-            if(superclass.classtype == classdesctype.PROXYCLASS) {
+        if (superclass != null) {
+            if (superclass.classtype == classdesctype.PROXYCLASS) {
                 jdeserialize.debugerr("warning: hit a proxy class in superclass hierarchy");
             } else {
                 superclass.getHierarchy(classes);
             }
-        } 
+        }
         classes.add(this);
     }
+
     public void validate() throws ValidityException {
         // If neither SC_SERIALIZABLE nor SC_EXTERNALIZABLE is set, then the number of
-        // fields is always zero.  (spec section 4.3)
-        if((descflags & (ObjectStreamConstants.SC_SERIALIZABLE | ObjectStreamConstants.SC_EXTERNALIZABLE)) == 0 && fields != null && fields.length > 0) {
+        // fields is always zero. (spec section 4.3)
+        if ((descflags & (ObjectStreamConstants.SC_SERIALIZABLE | ObjectStreamConstants.SC_EXTERNALIZABLE)) == 0
+                && fields != null && fields.length > 0) {
             throw new ValidityException("non-serializable, non-externalizable class has fields!");
         }
-        if((descflags & (ObjectStreamConstants.SC_SERIALIZABLE | ObjectStreamConstants.SC_EXTERNALIZABLE)) == (ObjectStreamConstants.SC_SERIALIZABLE | ObjectStreamConstants.SC_EXTERNALIZABLE)) {
+        if ((descflags & (ObjectStreamConstants.SC_SERIALIZABLE
+                | ObjectStreamConstants.SC_EXTERNALIZABLE)) == (ObjectStreamConstants.SC_SERIALIZABLE
+                        | ObjectStreamConstants.SC_EXTERNALIZABLE)) {
             throw new ValidityException("both Serializable and Externalizable are set!");
         }
-        if((descflags & ObjectStreamConstants.SC_ENUM) != 0) {
+        if ((descflags & ObjectStreamConstants.SC_ENUM) != 0) {
             // we're an enum; shouldn't have any fields/superinterfaces
-            if((fields != null && fields.length > 0) || interfaces != null) {
+            if ((fields != null && fields.length > 0) || interfaces != null) {
                 throw new ValidityException("enums shouldn't implement interfaces or have non-constant fields!");
             }
         } else {
-            // non-enums shouldn't have enum constant fields.  
-            if(enumconstants != null && enumconstants.size() > 0) {
+            // non-enums shouldn't have enum constant fields.
+            if (enumconstants != null && enumconstants.size() > 0) {
                 throw new ValidityException("non-enum classes shouldn't have enum constants!");
             }
         }
     }
 
-    public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, boolean child)
-    {
+    public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, boolean child) {
         StringBuffer sb = new StringBuffer();
-        String val = "";
+        String fieldJsonValue = "";
 
-        if(!child)
-        {
+        if (!child) {
             sb.append(indentation);
         }
-        
-        sb.append("{\n");
 
+        sb.append("{\n");
         indentation += "\t";
 
-        // ClassName
-        sb.append(indentation).append("class ");
-        sb.append(this.name);
-        // extends
-        if (this.superclass != null) {
-            sb.append(" extends ");
-            sb.append(this.superclass.name);
-        }
-        // implements
-        if (this.interfaces != null) {
-            sb.append(" implements ");
-            for (String str : this.interfaces) {
-                sb.append(str);
-                if(this.interfaces[this.interfaces.length-1] != str)
-                {
-                    sb.append(", ");
-                }
-            }
-        }
+        sb.append(indentation).append("class ").append(this.name);
+
+        this.extendsToJson(sb, this.superclass);
+        this.interfacesToJson(sb, this.interfaces);
+
         sb.append(" : {"); // ending of first line
-        
         indentation += "\t";
 
-        for (field f : this.fields) {
-            // v this.fielddata najit element, jehoz key == classdesc
-            // v tomto prvku fielddata najdu value (element) podle key == f
-            // jeho value je chtena hodnota
-            Object locVal = fielddata.get(this).get(f);
-            
-            // Sometimes locVal may be a null.
+        //iterating through fields and converts them into json string
+        for (field locField : this.fields) {
+            Object locVal = fielddata.get(this).get(locField);
+
+            // field could be null, but then, nothing to show
             if (locVal == null)
-            	continue;
+                continue;
 
-            if(locVal instanceof content)
-            {
-                val = ((content)locVal).toJson(indentation, fielddata, true);
-            }
-            else {
-                val = locVal.toString();
+            if (locVal instanceof content) {
+                fieldJsonValue = ((content) locVal).toJson(indentation, fielddata, true);
+            } else {
+                fieldJsonValue = locVal.toString();
             }
 
-            String locStringTest = "\n" + indentation + "\"" + f.name + "\"" + " : " + val;
-            sb.append(locStringTest);
-            /*sb.append(formatting.get("lineBreak")).append(indentation);
-            sb.append(formatting.get("fieldCol")).append("\"").append(f.name).append("\"").append(formatting.get("closeTagCol"));
-            sb.append(" : ");
-            sb.append(val);*/
+            String locString = "\n" + indentation + "\"" + locField.name + "\"" + " : " + fieldJsonValue;
+            sb.append(locString);
 
-            if (!f.equals(this.fields[this.fields.length - 1])) {
+            if (!locField.equals(this.fields[this.fields.length - 1])) {
                 sb.append(", ");
             }
         }
-        indentation = indentation.replaceFirst("\t", "");
 
+        indentation = indentation.replaceFirst("\t", "");
         sb.append("\n").append(indentation).append("}");
 
-        if(this.superclass != null)
-        {
+        //recursively call toJson for superclass if presented
+        if (this.superclass != null) {
             indentation = indentation.replaceFirst("\t", "");
             sb.append("\n").append(indentation).append("}");
             sb.append("," + "\n");
             sb.append(this.superclass.toJson(indentation, fielddata, false));
-        }
-        else 
-        {
+        } else {
             indentation = indentation.replaceFirst("\t", "");
             sb.append("\n").append(indentation).append("}");
         }
 
         return sb.toString();
     }
-}
 
+    /**
+     * Appends the extends clausule to the input StringBuffer.
+     * Only if superclass presented
+     * 
+     * @param sb            StringBuffer to append the string to
+     * @param superclass    superclass instance which name will be appended
+     */
+    private void extendsToJson(StringBuffer sb, classdesc superclass) {
+        if (this.superclass != null) {
+            sb.append(" extends ");
+            sb.append(this.superclass.name);
+        }
+    }
+
+    /**
+     * Appends the implements clausule to the input StringBuffer.
+     * Only if any interface implementation presented
+     * 
+     * @param sb            StringBuffer to append the string to
+     * @param interfaces    Array of implemented interface names
+     */
+    private void interfacesToJson(StringBuffer sb, String[] interfaces) {
+        if (interfaces != null) {
+            sb.append(" implements ");
+            for (String str : this.interfaces) {
+                sb.append(str);
+                if (this.interfaces[this.interfaces.length - 1] != str) {
+                    sb.append(", ");
+                }
+            }
+        }
+    }
+}
diff --git a/project/Deserializer/src/jdeserialize/content.java b/project/Deserializer/src/jdeserialize/content.java
index ef468ea..1e51ef4 100644
--- a/project/Deserializer/src/jdeserialize/content.java
+++ b/project/Deserializer/src/jdeserialize/content.java
@@ -69,6 +69,20 @@ public interface content {
      */
     public void setIsExceptionObject(boolean value);
 
+    /**
+     * <p>
+     * Analogy for toString method; however, outputs its string in json formatting.
+     * Returns the exact json representation of object with indentation.
+     * 
+     * <p>
+     * Inherited by multiple classes via contentbase, often calls itself for another object
+     * 
+     * @param indentation   starting indentation for json output
+     * @param fielddata     used when calling this method for inner instances 
+     *                      so the instance has info about its variables
+     * @param child         tells that the instance is child of another because of indentation
+     * @return              The string in json format representing this instance
+     */
     public String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, boolean child);
 }
 
diff --git a/project/Deserializer/src/jdeserialize/instance.java b/project/Deserializer/src/jdeserialize/instance.java
index 8b802ad..892309d 100644
--- a/project/Deserializer/src/jdeserialize/instance.java
+++ b/project/Deserializer/src/jdeserialize/instance.java
@@ -29,6 +29,7 @@ public class instance extends contentbase {
     
     public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata, boolean child)
     {
+        //basically, for representing the 'instance' instance, its classdesc is just enough
         return this.classdesc.toJson(indentation, this.fielddata, child);
     }
     
diff --git a/project/Deserializer/src/jdeserialize/jdeserialize.java b/project/Deserializer/src/jdeserialize/jdeserialize.java
index d4fcabd..8b07801 100644
--- a/project/Deserializer/src/jdeserialize/jdeserialize.java
+++ b/project/Deserializer/src/jdeserialize/jdeserialize.java
@@ -1139,6 +1139,8 @@ public class jdeserialize {
     }
     
     /*
+    This main commented-in because of using the project as library. No need for main.
+
     public static void main(String[] args) {
         HashMap<String, Integer> options = new HashMap<String, Integer>();
         Getopt go = new Getopt();
