package edu.ntnu.idi.goldfish;

import org.apache.commons.lang3.StringUtils;

import java.util.*;

public class Columns extends HashMap<String, String> {

	List<String> properties;
	List<String> formats;
	
	public Columns() {
		properties = new ArrayList<>();
		formats = new ArrayList<>();
	}
	

	public String join(String delimiter) {
		String fs = StringUtils.join(properties.toArray(),delimiter);
		return String.format(fs, formats.toArray());
	}

    public static Columns getPrintFormats(String... properties) {

        Columns columns = new Columns();
        columns.put("name", "%-11s");
        columns.put("similarity", "%19s");
        columns.put("numFeatures", "%5.2f");
        columns.put("TopN", "%3d");
        columns.put("RMSE", "%6.3f");
        columns.put("AAD", "%6.3f");
        columns.put("precision", "%6.3f");
        columns.put("recall", "%6.3f");
        columns.put("buildTime", "%4.0f");
        columns.put("recTime", "%2.0f");
        columns.put("evalTime", "%4.0f");
        columns.put("average", "%4d");

        // filter by arguments
        columns.keySet().retainAll(Arrays.asList(properties));

        return columns;
    }

    public static Columns getSaveFormats(String... properties) {
        Columns columns = new Columns();
        columns.put("name", "%s");
        columns.put("similarity", "%s");
        columns.put("numFeatures", "%.2f");
        columns.put("TopN", "%d");
        columns.put("RMSE", "%.3f");
        columns.put("AAD", "%.3f");
        columns.put("precision", "%.3f");
        columns.put("recall", "%.3f");
        columns.put("buildTime", "%.0f");
        columns.put("recTime", "%.0f");
        columns.put("evalTime", "%0.f");
        columns.put("average", "%d");

        // filter by arguments
        columns.keySet().retainAll(Arrays.asList(properties));

        return columns;
    }
}

@@ -121,16 +121,22 @@
 extends 
+Linked
 HashMap%3C
@@ -153,16 +153,16 @@
 ring%3E %7B%0A
-
 %0A%09List%3CS
@@ -593,24 +593,63 @@
 , %22%25-11s%22);%0A
+        columns.put(%22average%22, %22%254d%22);%0A
         colu
@@ -1047,47 +1047,8 @@
 f%22);
-%0A        columns.put(%22average%22, %22%254d%22);
 %0A%0A  
@@ -1304,32 +1304,70 @@
 (%22name%22, %22%25s%22);%0A
+        columns.put(%22average%22, %22%25d%22);%0A
         columns.
@@ -1698,32 +1698,32 @@
 Time%22, %22%25.0f%22);%0A
+
         columns.
@@ -1750,46 +1750,8 @@
 f%22);
-%0A        columns.put(%22average%22, %22%25d%22);
 %0A%0A  

Change Columns to use LinkedHashmap in order to remember column order