<commit_before>package models.helpers;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Query;

import models.User;
import models.UserConnection;
import play.db.jpa.JPA;

/**
 * 
 * @author <NAME> <EMAIL>
 */
public class UserConnectionHelper {
	
	public static void createUserConnection(User user1, User user2) {
		UserConnection con1 = new UserConnection();
		UserConnection con2 = new UserConnection();
		con1.user = user1;
		con2.user = user2;
		con1.save();
		con2.save();
		con1.userConnection = con2;
		con2.userConnection = con1;
		con1.save();
		con2.save();
		user1.connections.add(con1);
		user2.connections.add(con2);
	}
	
	public static void removeUserConnection(User user1, User user2) {
		
		// Get the UserConnection objects that represent user1 to user2
		Query query = JPA.em().createQuery("SELECT uc FROM UserConnection uc WHERE user = :user1 AND userConnection.user = :user2 ");
		query.setParameter("user1", user1);
		query.setParameter("user2", user2);
		UserConnection con1 = (UserConnection) query.getSingleResult();
		UserConnection con2 = con1.userConnection;
		
		// Delete the UserConnection objects
		con1.delete();
		con2.delete();
	}
	
	public static List<User> connectionsAsUsers(User user) {
		List<User> connections = new ArrayList<User>();
		for (UserConnection connection : user.connections) {
			connections.add(connection.userConnection.user);
		}
		return connections;
	}<commit_msg>Fixed bug with duplication of elements in collection. The element was already added by the ManyToOne relationship.<commit_after>package models.helpers;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Query;

import models.User;
import models.UserConnection;
import play.db.jpa.JPA;

/**
 * 
 * @author <NAME> <EMAIL>
 */
public class UserConnectionHelper {
	
	public static void createUserConnection(User user1, User user2) {
		UserConnection con1 = new UserConnection();
		UserConnection con2 = new UserConnection();
		con1.user = user1;
		con2.user = user2;
		con1.save();
		con2.save();
		con1.userConnection = con2;
		con2.userConnection = con1;
		con1.save();
		con2.save();
	}
	
	public static void removeUserConnection(User user1, User user2) {
		
		// Get the UserConnection objects that represent user1 to user2
		Query query = JPA.em().createQuery("SELECT uc FROM UserConnection uc WHERE user = :user1 AND userConnection.user = :user2 ");
		query.setParameter("user1", user1);
		query.setParameter("user2", user2);
		UserConnection con1 = (UserConnection) query.getSingleResult();
		UserConnection con2 = con1.userConnection;
		
		// Delete the UserConnection objects
		con1.delete();
		con2.delete();
	}
	
	public static List<User> connectionsAsUsers(User user) {
		List<User> connections = new ArrayList<User>();
		for (UserConnection connection : user.connections) {
			connections.add(connection.userConnection.user);
		}
		return connections;
	}
{'fraction_non_alphanumeric': 0.11220673240394424, 'fraction_numerical': 0.022441346480788847, 'mean_word_length': 4.540489642184557, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1778947', 'n_tokens_mistral': 969, 'n_tokens_neox': 882, 'n_words': 236}