// Path: matrix/src/main/java/net/onedaybeard/ecs/util/MatrixStringUtil.java
// public final class MatrixStringUtil {
// 	private MatrixStringUtil() {}
// 	
// 	public static String findLongestClassName(Map<String, List<RowTypeMapping>> mappings) {
// 		return findLongestString(mappings, new LongestClassName());
// 	}
// 	
// 	public static String findLongestManagerList(Map<String, List<RowTypeMapping>> mappings) {
// 		return findLongestString(mappings, new LongestManagers());
// 	}
// 	
// 	public static String findLongestSystemList(Map<String, List<RowTypeMapping>> mappings) {
// 		return findLongestString(mappings, new LongestSystems());
// 	}
// 	
// 	private static String findLongestString(Map<String, List<RowTypeMapping>> mappings, LongestMapper longestStrategy) {
// 		String longest = "";
// 		for (Entry<String, List<RowTypeMapping>> entry : mappings.entrySet()) {
// 			if (entry.getKey().length() > longest.length()) longest = entry.getKey();
// 			for (RowTypeMapping mapping : entry.getValue()) {
// 				longest = longestStrategy.getMaxLength(mapping, longest);
// 			}
// 		}
// 		return longest;
// 	}
// 	
// 	private static interface LongestMapper {
// 		String getMaxLength(RowTypeMapping mapping, String previousLongest);
// 	}
// 	
// 	private static class LongestClassName implements LongestMapper {
// 		@Override
// 		public String getMaxLength(RowTypeMapping mapping, String longest) {
// 			return (mapping.name.length() > longest.length())
// 				? mapping.name
// 				: longest;
// 		}
// 	}
// 	
// 	private static class LongestManagers implements LongestMapper {
// 		@Override
// 		public String getMaxLength(RowTypeMapping mapping, String longest) {
// 			return (Arrays.toString(mapping.refManagers).length() > longest.length())
// 				? Arrays.toString(mapping.refManagers)
// 				: longest;
// 		}
// 	}
// 	
// 	private static class LongestSystems implements LongestMapper {
// 		@Override
// 		public String getMaxLength(RowTypeMapping mapping, String longest) {
// 			return (Arrays.toString(mapping.refSystems).length() > longest.length())
// 				? Arrays.toString(mapping.refSystems)
// 				: longest;
// 		}
// 	}
// 	
// 	public static String shortName(String s) {
// 		String name = s;
// 		return name.substring(name.lastIndexOf('.') + 1);
// 	}
// 
// 	public static String shortName(Type type) {
// 		String name = type.getClassName();
// 		return name.substring(name.lastIndexOf('.') + 1);
// 	}
// }


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.SortedMap;
import net.onedaybeard.ecs.util.MatrixStringUtil;
import org.objectweb.asm.Opcodes;
import com.x5.template.Chunk;
import com.x5.template.Theme;
import static java.util.Arrays.asList;
				process(typeInspector);
				return "Found ECS framework: " + ecs;
			}
		}

		return "Failed finding any ECS related classes.";
	}

	public void process() {
		process("");
	}

	public void process(String resourcePrefix) {
		process(new EcsTypeInspector(files, resourcePrefix));
	}

	private void process(EcsTypeInspector typeInspector) {
		write(typeInspector.getTypeMap(), typeInspector.getMatrixData());
	}

	private void write(SortedMap<String, List<RowTypeMapping>> mappedSystems, MatrixData matrix) {
		Theme theme = new Theme();
		Chunk chunk = theme.makeChunk("matrix");
		
		List<RowTypeMapping> rows = new ArrayList<RowTypeMapping>();
		for (Entry<String,List<RowTypeMapping>> entry : mappedSystems.entrySet()) {
			rows.add(new RowTypeMapping(entry.getKey()));
			rows.addAll(entry.getValue());
		}
		
// Path: matrix/src/main/java/net/onedaybeard/ecs/util/MatrixStringUtil.java
// public final class MatrixStringUtil {
// 	private MatrixStringUtil() {}
// 	
// 	public static String findLongestClassName(Map<String, List<RowTypeMapping>> mappings) {
// 		return findLongestString(mappings, new LongestClassName());
// 	}
// 	
// 	public static String findLongestManagerList(Map<String, List<RowTypeMapping>> mappings) {
// 		return findLongestString(mappings, new LongestManagers());
// 	}
// 	
// 	public static String findLongestSystemList(Map<String, List<RowTypeMapping>> mappings) {
// 		return findLongestString(mappings, new LongestSystems());
// 	}
// 	
// 	private static String findLongestString(Map<String, List<RowTypeMapping>> mappings, LongestMapper longestStrategy) {
// 		String longest = "";
// 		for (Entry<String, List<RowTypeMapping>> entry : mappings.entrySet()) {
// 			if (entry.getKey().length() > longest.length()) longest = entry.getKey();
// 			for (RowTypeMapping mapping : entry.getValue()) {
// 				longest = longestStrategy.getMaxLength(mapping, longest);
// 			}
// 		}
// 		return longest;
// 	}
// 	
// 	private static interface LongestMapper {
// 		String getMaxLength(RowTypeMapping mapping, String previousLongest);
// 	}
// 	
// 	private static class LongestClassName implements LongestMapper {
// 		@Override
// 		public String getMaxLength(RowTypeMapping mapping, String longest) {
// 			return (mapping.name.length() > longest.length())
// 				? mapping.name
// 				: longest;
// 		}
// 	}
// 	
// 	private static class LongestManagers implements LongestMapper {
// 		@Override
// 		public String getMaxLength(RowTypeMapping mapping, String longest) {
// 			return (Arrays.toString(mapping.refManagers).length() > longest.length())
// 				? Arrays.toString(mapping.refManagers)
// 				: longest;
// 		}
// 	}
// 	
// 	private static class LongestSystems implements LongestMapper {
// 		@Override
// 		public String getMaxLength(RowTypeMapping mapping, String longest) {
// 			return (Arrays.toString(mapping.refSystems).length() > longest.length())
// 				? Arrays.toString(mapping.refSystems)
// 				: longest;
// 		}
// 	}
// 	
// 	public static String shortName(String s) {
// 		String name = s;
// 		return name.substring(name.lastIndexOf('.') + 1);
// 	}
// 
// 	public static String shortName(Type type) {
// 		String name = type.getClassName();
// 		return name.substring(name.lastIndexOf('.') + 1);
// 	}
// }


// Path: matrix/src/main/java/net/onedaybeard/ecs/model/ComponentDependencyMatrix.java
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.SortedMap;
import net.onedaybeard.ecs.util.MatrixStringUtil;
import org.objectweb.asm.Opcodes;
import com.x5.template.Chunk;
import com.x5.template.Theme;
import static java.util.Arrays.asList;

				process(typeInspector);
				return "Found ECS framework: " + ecs;
			}
		}

		return "Failed finding any ECS related classes.";
	}

	public void process() {
		process("");
	}

	public void process(String resourcePrefix) {
		process(new EcsTypeInspector(files, resourcePrefix));
	}

	private void process(EcsTypeInspector typeInspector) {
		write(typeInspector.getTypeMap(), typeInspector.getMatrixData());
	}

	private void write(SortedMap<String, List<RowTypeMapping>> mappedSystems, MatrixData matrix) {
		Theme theme = new Theme();
		Chunk chunk = theme.makeChunk("matrix");
		
		List<RowTypeMapping> rows = new ArrayList<RowTypeMapping>();
		for (Entry<String,List<RowTypeMapping>> entry : mappedSystems.entrySet()) {
			rows.add(new RowTypeMapping(entry.getKey()));
			rows.addAll(entry.getValue());
		}
		
		chunk.set("longestName", MatrixStringUtil.findLongestClassName(mappedSystems).replaceAll(".", "_") + "______");