<commit_before>import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


public class StarUML
{
	public static void main(String[] args) throws XPathExpressionException
	{
		File f = new File(args[0]);
		XML xml = new StarUML.XML(f);
	}
	
	public static class XML
	{
		public XML(File file) throws XPathExpressionException
		{
			try {
				DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
				DocumentBuilder db = dbf.newDocumentBuilder();
				doc = db.parse(file);
			}
			catch (ParserConfigurationException e) { e.printStackTrace(); }
			catch (SAXException e) { e.printStackTrace(); }
			catch (IOException e) { e.printStackTrace(); }
			
			iMap printem = new aMap()
			{
				public Object map(Object item, Object[] args)
				{
					Node n = (Node)item;
					String tab = Global.tabs((Integer)args[0],"  ");
					
					NamedNodeMap nmap = n.getAttributes();
					if (nmap != null)
						for (int i=0; i < nmap.getLength(); ++i)
						{
							Node a = nmap.item(i);
							System.out.println(tab+a);
						}
					
					System.out.println(tab+n);
					return item;
				}
			};
			
			class NodeListIterator implements Iterable<Node>
			{
				public NodeListIterator(NodeList nl)
				{ this.nl = nl; }
				private NodeList nl; 
				public Iterator<Node> iterator()
				{
					List<Node> nodes = new ArrayList<Node>(nl.getLength());
					for (int i=0; i < nl.getLength(); ++i)
						nodes.add(nl.item(i));
					return nodes.iterator();
				}
			}
			
			xPath = XPathFactory.newInstance().newXPath();
			
			sized = xPathEval(sizedXPath);
			positioned = xPathEval(positionedXPath);
			classViews = xPathEval(classViewsXPath);
			dependencyViews = xPathEval(dependencyViewsXPath);
			deeseViews = xPathEval(deeseViewsXPath);
			
			class Lambda
			{
				public void eval(List<Node> nodes)
				{ 
					Set<String> types = new HashSet<String>(nodes.size());
					for (Node n : nodes)
					{
						String type = n.getAttributes().getNamedItem("type").getTextContent();
						String name = n.getAttributes().getNamedItem("name").getTextContent();
						System.out.print(String.format("%-40s", type));
						System.out.println(name);
						types.add(type);
					}
					System.out.println();
					System.out.println(types);
				}
			}
			Lambda lambda = new Lambda();
			
			System.out.println("\nClass Views: =============================================");
			lambda.eval(classViews);
			
			System.out.println("\nDependency Views: ========================================");
			lambda.eval(dependencyViews);
			
			System.out.println("\nDependency Views: ========================================");
			lambda.eval(deeseViews);
			
		}
		
		protected Document doc;
		protected XPath xPath;
		
		protected List<Node> sized;
		protected List<Node> positioned;
		
		protected List<Node> classViews;
		protected List<Node> dependencyViews;
		protected List<Node> deeseViews;
		
		private final static String sizedXPath = "PROJECT/BODY//OBJ/ATTR[@name=\"Height\"]/..";
		private final static String positionedXPath = "PROJECT/BODY//OBJ/ATTR[@name=\"Top\"]/..";
		private final static String classViewsXPath = "PROJECT/BODY//OBJ[@type=\"UMLClassView\"]";
		private final static String dependencyViewsXPath = "PROJECT/BODY//OBJ[@type=\"UMLDependencyView\"]";
		private final static String deeseViewsXPath = "PROJECT/BODY//OBJ[starts-with(@type,\"UML\") and contains(@type,\"View\")]";
		
 		protected void traverse(Node n, iMap map)
		{ traverse(n,map,0,0); }
		protected void traverse(Node n, iMap map, int maxDepth)
		{ traverse(n,map,maxDepth,0); }
		protected void traverse(Node n, iMap map, int maxDepth, int currentDepth)
		{
			if (maxDepth > 0 && currentDepth > maxDepth)
				return;
			
			if (map == null)
			{
				
			}
			else
			{
				int tab = 0;
				Object res = map.map(n,new Object[]{new Integer(currentDepth)});
				
				if (n.hasChildNodes())
				{
					NodeList children = n.getChildNodes();
					for (int i=0; i < children.getLength(); ++i)
					{
						traverse(children.item(i),map,maxDepth,currentDepth+1);
					}
				}
			}
		}
		
		protected List<Node> xPathEval(String pattern) throws XPathExpressionException
		{
			NodeList nl = (NodeList)xPath.compile(pattern).evaluate(doc, XPathConstants.NODESET);
			ArrayList<Node> ret = new ArrayList<Node>(nl.getLength());
			for (int i=0; i < nl.getLength(); ++i)
				ret.add(nl.item(i));
			return ret;
		}
	}
	
	public static class UMLView
	{
		protected String name;
		protected String type;
		protected int width;
		protected int height;
		protected int left;
		protected int top;
		
		public String getName()   { return name; }
		public String getType()   { return type; }
		public int    getWidth()  { return width; }
		public int    getHeight() { return width; }
		public int    getLeft()   { return width; }
		public int    getTop()    { return width; }
		
		public static class Factory
		{
			public UMLView initNew(int... args)<commit_msg>Playing around with this Factory idea...<commit_after>import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


public class StarUML
{
	public static void main(String[] args) throws XPathExpressionException
	{
		File f = new File(args[0]);
		XML xml = new StarUML.XML(f);
	}
	
	public static class XML
	{
		public XML(File file) throws XPathExpressionException
		{
			try {
				DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
				DocumentBuilder db = dbf.newDocumentBuilder();
				doc = db.parse(file);
			}
			catch (ParserConfigurationException e) { e.printStackTrace(); }
			catch (SAXException e) { e.printStackTrace(); }
			catch (IOException e) { e.printStackTrace(); }
			
			iMap printem = new aMap()
			{
				public Object map(Object item, Object[] args)
				{
					Node n = (Node)item;
					String tab = Global.tabs((Integer)args[0],"  ");
					
					NamedNodeMap nmap = n.getAttributes();
					if (nmap != null)
						for (int i=0; i < nmap.getLength(); ++i)
						{
							Node a = nmap.item(i);
							System.out.println(tab+a);
						}
					
					System.out.println(tab+n);
					return item;
				}
			};
			
			class NodeListIterator implements Iterable<Node>
			{
				public NodeListIterator(NodeList nl)
				{ this.nl = nl; }
				private NodeList nl; 
				public Iterator<Node> iterator()
				{
					List<Node> nodes = new ArrayList<Node>(nl.getLength());
					for (int i=0; i < nl.getLength(); ++i)
						nodes.add(nl.item(i));
					return nodes.iterator();
				}
			}
			
			xPath = XPathFactory.newInstance().newXPath();
			
			sized = xPathEval(sizedXPath);
			positioned = xPathEval(positionedXPath);
			classViews = xPathEval(classViewsXPath);
			dependencyViews = xPathEval(dependencyViewsXPath);
			deeseViews = xPathEval(deeseViewsXPath);
			
			class Lambda
			{
				public void eval(List<Node> nodes)
				{ 
					Set<String> types = new HashSet<String>(nodes.size());
					for (Node n : nodes)
					{
						String type = n.getAttributes().getNamedItem("type").getTextContent();
						String name = n.getAttributes().getNamedItem("name").getTextContent();
						System.out.print(String.format("%-40s", type));
						System.out.println(name);
						types.add(type);
					}
					System.out.println();
					System.out.println(types);
				}
			}
			Lambda lambda = new Lambda();
			
			System.out.println("\nClass Views: =============================================");
			lambda.eval(classViews);
			
			System.out.println("\nDependency Views: ========================================");
			lambda.eval(dependencyViews);
			
			System.out.println("\nDependency Views: ========================================");
			lambda.eval(deeseViews);
			
		}
		
		protected Document doc;
		protected XPath xPath;
		
		protected List<Node> sized;
		protected List<Node> positioned;
		
		protected List<Node> classViews;
		protected List<Node> dependencyViews;
		protected List<Node> deeseViews;
		
		private final static String sizedXPath = "PROJECT/BODY//OBJ/ATTR[@name=\"Height\"]/..";
		private final static String positionedXPath = "PROJECT/BODY//OBJ/ATTR[@name=\"Top\"]/..";
		private final static String classViewsXPath = "PROJECT/BODY//OBJ[@type=\"UMLClassView\"]";
		private final static String dependencyViewsXPath = "PROJECT/BODY//OBJ[@type=\"UMLDependencyView\"]";
		private final static String deeseViewsXPath = "PROJECT/BODY//OBJ[starts-with(@type,\"UML\") and contains(@type,\"View\")]";
		
 		protected void traverse(Node n, iMap map)
		{ traverse(n,map,0,0); }
		protected void traverse(Node n, iMap map, int maxDepth)
		{ traverse(n,map,maxDepth,0); }
		protected void traverse(Node n, iMap map, int maxDepth, int currentDepth)
		{
			if (maxDepth > 0 && currentDepth > maxDepth)
				return;
			
			if (map == null)
			{
				
			}
			else
			{
				int tab = 0;
				Object res = map.map(n,new Object[]{new Integer(currentDepth)});
				
				if (n.hasChildNodes())
				{
					NodeList children = n.getChildNodes();
					for (int i=0; i < children.getLength(); ++i)
					{
						traverse(children.item(i),map,maxDepth,currentDepth+1);
					}
				}
			}
		}
		
		protected List<Node> xPathEval(String pattern) throws XPathExpressionException
		{
			NodeList nl = (NodeList)xPath.compile(pattern).evaluate(doc, XPathConstants.NODESET);
			ArrayList<Node> ret = new ArrayList<Node>(nl.getLength());
			for (int i=0; i < nl.getLength(); ++i)
				ret.add(nl.item(i));
			return ret;
		}
	}
	
	public static class UMLView
	{
		protected String name;
		protected String type;
		protected int width;
		protected int height;
		protected int left;
		protected int top;
		
		public String getName()   { return name; }
		public String getType()   { return type; }
		public int    getWidth()  { return width; }
		public int    getHeight() { return width; }
		public int    getLeft()   { return width; }
		public int    getTop()    { return width; }
		
		// NOTE: Trying out this Factory thing...
		public static class Factory
		{
			public UMLView initNew(Object... params)
			{
				return null;
			}
			public UMLView initNew(String name, String type, int... args)
			{
				UMLView v = initNew(args);
				v.name = name;
				v.type = type;
				return v;
			}
			public UMLView initNew(int... args)
{'fraction_non_alphanumeric': 0.150407223796034, 'fraction_numerical': 0.003186968838526912, 'mean_word_length': 3.3871844660194177, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6491589', 'n_tokens_mistral': 4434, 'n_tokens_neox': 3550, 'n_words': 817}