<commit_before>package a4_p01_JS_MJ;

public class Hierholzer {

}<commit_msg>halfway done -> untested<commit_after>package a4_p01_JS_MJ;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jgraph.graph.Edge;
import org.jgrapht.Graphs;
import org.jgrapht.UndirectedGraph;

public class Hierholzer<T extends Comparable<T>> {
	
	
	/**
	 * foo
	 * @param graph
	 */
	public void algorithm(UndirectedGraph<T, Edge> graph)
	{
		
		List<List<Edge>> subCircleList = new ArrayList();
		HashSet<Edge> edgeSet = new HashSet(graph.edgeSet());
		List<T> vertexList = new ArrayList(graph.vertexSet());
		Set<T> schnittpunkte = new HashSet();
		for(T v : graph.vertexSet())//PRECONDITIONS
		{	int grad=graph.degreeOf(v) ;
			if((grad%2)!=0)
			{
				throw new IllegalArgumentException();
			}
			else if(grad>2)
			{
				schnittpunkte.add(v);
			}
			else if(grad==0)
			{
				vertexList.remove(v);
			}
		}	
		while(!edgeSet.isEmpty())
			{
				T aktVertex = vertexList.remove(0);
				List<Edge> _tmp = buildSubCircle(aktVertex, edgeSet, graph);
				if(_tmp!=null)
				subCircleList.add(_tmp);							
			}
		//TODO weitermachen
	}
	
	private List<Edge> buildSubCircle(T vertex, HashSet<Edge> edgeSet,UndirectedGraph<T, Edge>graph)
	{
		T aktVertex = vertex;
		List<Edge> subCircle = new ArrayList();
		List<T> subCircleVertex = new ArrayList();
		boolean circleNotClosed = false;
		while (circleNotClosed)
		{
			List<T>neigh= Graphs.neighborListOf(graph, vertex);
			T target;
			if(neigh.contains(aktVertex))
			{
				target=aktVertex;
				neigh.remove(target);
			}else{
			target = neigh.remove(0);
			}
			Edge e = graph.getEdge(aktVertex, target);
			
			while(!edgeSet.contains(e))//Eine Kante finden die noch nicht frei ist.
			{
				try{
					target = neigh.remove(0);
				}catch (IndexOutOfBoundsException ex)
				{
					edgeSet.addAll(subCircle);
					return null;
				}

				e = graph.getEdge(aktVertex, target);
			}
			if(target.equals(vertex))
			{
				circleNotClosed = true;
			}
			subCircle.add(e);
			subCircleVertex.add(target);
			edgeSet.remove(e);
			aktVertex= target; 
		}		
		return subCircle;
	}
	

}
{'fraction_non_alphanumeric': 0.1328735632183908, 'fraction_numerical': 0.005977011494252874, 'mean_word_length': 3.477366255144033, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1342905', 'n_tokens_mistral': 956, 'n_tokens_neox': 792, 'n_words': 148}