<commit_before>/*******************************************************************************
 * Copyright 2005, CHISEL Group, University of Victoria, Victoria, BC, Canada.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     The Chisel Group, University of Victoria
 *******************************************************************************/
package org.eclipse.mylar.zest.core.internal.graphmodel;

import java.util.Iterator;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.mylar.zest.core.viewers.IGraphContentProvider;
import org.eclipse.swt.widgets.Canvas;

import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;


/**
 * This factory helps make models (nodes & connections).
 * 
 * @author <NAME>
 * @author <NAME>
 */
public class GraphModelFactory implements IGraphModelFactory {
	/**
	 * 
	 * Class to keep track of the number of connections there are between two nodes.
	 * @author <NAME>
	 *
	 */
	//@tag bug(114452-MultipleArcs) : resolution
	class ConnectionCounter {
		Object source;
		Object dest;
		public ConnectionCounter(Object source, Object dest) {
			this.source = source;
			this.dest = dest;
		}
		public boolean equals(Object that) {
			return (
				this.source.equals(((ConnectionCounter)that).source) &&
				this.dest.equals(((ConnectionCounter)that).dest)
			);
		}
		public int hashCode() {
			return 0;
		}
	}

	private StructuredViewer viewer = null;
	private boolean highlightAdjacentNodes = false;
		
	public GraphModelFactory(StructuredViewer viewer, boolean highlightAdjacentNodes) {
		this.viewer = viewer;
		this.highlightAdjacentNodes = highlightAdjacentNodes;
	}
	
	/* (non-Javadoc)
	 * @see ca.uvic.cs.zest.internal.graphmodel.IGraphModelFactory#createModel()
	 */
	public GraphModel createModel() {
		return new GraphModel((Canvas)viewer.getControl());
	}
	
	private IGraphContentProvider getContentProvider() {
		return (IGraphContentProvider)viewer.getContentProvider();
	}
	
	private ILabelProvider getLabelProvider() {
		return (ILabelProvider)viewer.getLabelProvider();
	}
	
	/* (non-Javadoc)
	 * @see ca.uvic.cs.zest.internal.graphmodel.IGraphModelFactory#createModelFromContentProvider(java.lang.Object)
	 */
	public GraphModel createModelFromContentProvider( Object inputElement, int nodeStyle, int connectionStyle) {
		//@tag bug(152045-UnconnectedNodes) : This does not take care of non-connected nodes. FIXED
		GraphModel model = createModel();
		model.setConnectionStyle(connectionStyle);
		model.setNodeStyle(nodeStyle);
		//make the model have the same styles as the viewer
		Object rels[] = getContentProvider().getElements(inputElement);
		for ( int i = 0; i < rels.length; i++ ) {
			createRelationship(model, rels[i], getContentProvider().getSource(rels[i]), getContentProvider().getDestination(rels[i]));
		}
		//@tag bug(114452-MultipleArcs) : count the number of arcs between nodes, and set the curve accordingly
		Iterator ci = model.getConnections().iterator();
		Hashtable counters = new Hashtable();
		while (ci.hasNext()) {
			GraphModelConnection conn = (GraphModelConnection) ci.next();
			ConnectionCounter key = new ConnectionCounter(
				conn.getSource().getExternalNode(),
				conn.getDestination().getExternalNode()
			);
			Integer count = (Integer) counters.get(key);
			if (count == null) {
				count = new Integer(1);
				counters.put(key, count);
			} else {<commit_msg>Completed: 134928: An empty graph causes an NPE https://bugs.eclipse.org/bugs/show_bug.cgi?id=134928<commit_after>/*******************************************************************************
 * Copyright 2005, CHISEL Group, University of Victoria, Victoria, BC, Canada.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     The Chisel Group, University of Victoria
 *******************************************************************************/
package org.eclipse.mylar.zest.core.internal.graphmodel;

import java.util.Iterator;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.mylar.zest.core.viewers.IGraphContentProvider;
import org.eclipse.swt.widgets.Canvas;

import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;


/**
 * This factory helps make models (nodes & connections).
 * 
 * @author <NAME>
 * @author <NAME>
 */
public class GraphModelFactory implements IGraphModelFactory {
	/**
	 * 
	 * Class to keep track of the number of connections there are between two nodes.
	 * @author <NAME>
	 *
	 */
	//@tag bug(114452-MultipleArcs) : resolution
	class ConnectionCounter {
		Object source;
		Object dest;
		public ConnectionCounter(Object source, Object dest) {
			this.source = source;
			this.dest = dest;
		}
		public boolean equals(Object that) {
			return (
				this.source.equals(((ConnectionCounter)that).source) &&
				this.dest.equals(((ConnectionCounter)that).dest)
			);
		}
		public int hashCode() {
			return 0;
		}
	}

	private StructuredViewer viewer = null;
	private boolean highlightAdjacentNodes = false;
		
	public GraphModelFactory(StructuredViewer viewer, boolean highlightAdjacentNodes) {
		this.viewer = viewer;
		this.highlightAdjacentNodes = highlightAdjacentNodes;
	}
	
	/* (non-Javadoc)
	 * @see ca.uvic.cs.zest.internal.graphmodel.IGraphModelFactory#createModel()
	 */
	public GraphModel createModel() {
		return new GraphModel((Canvas)viewer.getControl());
	}
	
	private IGraphContentProvider getContentProvider() {
		return (IGraphContentProvider)viewer.getContentProvider();
	}
	
	private ILabelProvider getLabelProvider() {
		return (ILabelProvider)viewer.getLabelProvider();
	}
	
	/* (non-Javadoc)
	 * @see ca.uvic.cs.zest.internal.graphmodel.IGraphModelFactory#createModelFromContentProvider(java.lang.Object)
	 */
	public GraphModel createModelFromContentProvider( Object inputElement, int nodeStyle, int connectionStyle) {
		//@tag bug(152045-UnconnectedNodes) : This does not take care of non-connected nodes. FIXED
		GraphModel model = createModel();
		model.setConnectionStyle(connectionStyle);
		model.setNodeStyle(nodeStyle);
		//make the model have the same styles as the viewer
		Object rels[] = getContentProvider().getElements(inputElement);
		
		if ( rels != null ) {
			// If rels returns null then just continue
			// @tag bug (134928) : An empty graph causes an NPE
			for ( int i = 0; i < rels.length; i++ ) {
				createRelationship(model, rels[i], getContentProvider().getSource(rels[i]), getContentProvider().getDestination(rels[i]));
			}
		}
		//@tag bug(114452-MultipleArcs) : count the number of arcs between nodes, and set the curve accordingly
		Iterator ci = model.getConnections().iterator();
		Hashtable counters = new Hashtable();
		while (ci.hasNext()) {
			GraphModelConnection conn = (GraphModelConnection) ci.next();
			ConnectionCounter key = new ConnectionCounter(
				conn.getSource().getExternalNode(),
				conn.getDestination().getExternalNode()
			);
			Integer count = (Integer) counters.get(key);
			if (count == null) {
				count = new Integer(1);
				counters.put(key, count);
			} else {
{'fraction_non_alphanumeric': 0.1485017236807213, 'fraction_numerical': 0.01007690267833466, 'mean_word_length': 4.684250188394875, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, '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': '146413', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2138, 'n_words': 543}