Skip to content

Commit

Permalink
Fixed UnOrdered elements in contents of Log.
Browse files Browse the repository at this point in the history
Resolved Issue #6 by switching data-type of HashMap to one of it's derivatives, LinkedHashMap.

Also performed some minor clean-up of methods and variables in logUtils. (Took care of/Suppressed some compiler warnings)
  • Loading branch information
AvidhBavkar committed Jul 10, 2018
1 parent 3f22c37 commit 14eedc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/logUtils/Log.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package logUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
Expand All @@ -18,14 +18,14 @@ public class Log {
/**
* The raw contents of the log.
*/
private HashMap<String, ArrayList<Object>> contents;
private LinkedHashMap<String, ArrayList<Object>> contents;


/**
* Default Constructor.
*/
public Log(){
contents = new HashMap<>();
contents = new LinkedHashMap<>();
}

/**
Expand All @@ -47,7 +47,7 @@ public Log(Log copyFrom){
* @param key The "key" of the data to log.
* @param object The actual data to write to that key.
*/
public void append(String key, Object object){
void append(String key, Object object){
if (!contents.containsKey(key))
contents.put(key, new ArrayList<>());
contents.get(key).add(object);
Expand All @@ -60,8 +60,9 @@ public void append(String key, Object object){
*
* @return A copy of the contents of the log in it's raw hashmap form.
*/
private HashMap<String, ArrayList<Object>> getRaw(){
return (HashMap<String, ArrayList<Object>>) contents.clone();
@SuppressWarnings("unchecked")
private LinkedHashMap<String, ArrayList<Object>> getRaw(){
return (LinkedHashMap<String, ArrayList<Object>>) contents.clone();
}


Expand Down
4 changes: 2 additions & 2 deletions src/logUtils/Loggable.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
*/
public abstract class Loggable {

String[] keys;
private String[] keys;

/**
* The {@link Log} object that stores all logged values for this class.
*/
Log log;
private Log log;

/**
* Constructor
Expand Down

0 comments on commit 14eedc1

Please sign in to comment.