<commit_before>package cscie99.team2.lingolearn.server.datastore;

import static cscie99.team2.lingolearn.server.datastore.OfyService.ofy;

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

import cscie99.team2.lingolearn.shared.Gender;
import cscie99.team2.lingolearn.shared.User;

public class UserDAO {

	private static UserDAO instance;
	
	private UserDAO(){
		
	}
	
	public static UserDAO getInstance(){
		if( instance == null )
			instance = new UserDAO();
		
		return instance;
	}
	
	/**
	 * This method stores the User in the datastore
	 * @param user User object to be stored in datastore
	 * @return USer for diagnostic
	 */
	public User storeUser( User user ) {
		
		ObjectifyableUser userEntity = new ObjectifyableUser(user);
		ofy().save().entity(userEntity).now();
		User stored = userEntity.getUser();
		return stored;	
	}
	
	public User getUserById( Long uid ){
		if (uid < 1 || uid == null) {
			return null;
		}
		ObjectifyableUser oUser = ofy().load().type(ObjectifyableUser.class).id(uid).now();
		if (oUser != null) {
			User user = oUser.getUser();
			return user;
			}
		return null;
	}
	
	/**
	 * Obtains User by UserId
	 * @param gplus userId
	 * @return User stored with the userId or null if not found
	 */
	public User getUserByGplusId(String gplus) {
		if (gplus.isEmpty() || gplus == null) {
			return null;
		}
		ObjectifyableUser oUser = ofy().load().type(ObjectifyableUser.class).id(gplus).now();
		if (oUser != null) {
			User user = oUser.getUser();<commit_msg>Fixed a bug in UserDAO.getUserByGplusId().<commit_after>package cscie99.team2.lingolearn.server.datastore;

import static cscie99.team2.lingolearn.server.datastore.OfyService.ofy;

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

import cscie99.team2.lingolearn.shared.Gender;
import cscie99.team2.lingolearn.shared.User;

public class UserDAO {

	private static UserDAO instance;
	
	private UserDAO(){
		
	}
	
	public static UserDAO getInstance(){
		if( instance == null )
			instance = new UserDAO();
		
		return instance;
	}
	
	/**
	 * This method stores the User in the datastore
	 * @param user User object to be stored in datastore
	 * @return USer for diagnostic
	 */
	public User storeUser( User user ) {
		
		ObjectifyableUser userEntity = new ObjectifyableUser(user);
		ofy().save().entity(userEntity).now();
		User stored = userEntity.getUser();
		return stored;	
	}
	
	public User getUserById( Long uid ){
		if (uid < 1 || uid == null) {
			return null;
		}
		ObjectifyableUser oUser = ofy().load().type(ObjectifyableUser.class).id(uid).now();
		if (oUser != null) {
			User user = oUser.getUser();
			return user;
			}
		return null;
	}
	
	/**
	 * Obtains User by UserId
	 * @param gplus userId
	 * @return User stored with the userId or null if not found
	 */
	public User getUserByGplusId(String gplus) {
		if (gplus.isEmpty() || gplus == null) {
			return null;
		}
		ObjectifyableUser oUser = ofy().load().type(ObjectifyableUser.class).
											filter("gplusId", gplus).first().now();
		if (oUser != null) {
			User user = oUser.getUser();
{'fraction_non_alphanumeric': 0.12202954399486192, 'fraction_numerical': 0.008349389852280027, 'mean_word_length': 3.656203288490284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2766282', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1039, 'n_words': 273}