<commit_before>package {{{packagename}}}.model.dao;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
import java.util.ArrayList;
import java.io.*;
import {{{packagename}}}.model.dto.*;

/**
 * DAO for entity {{{entity.daoClassName}}}, Singleton
 * @author Service Generator
 *
 * Generated Class - DO NOT MODIFY
 */
public final class {{{entity.daoClassName}}}{

	// XML field constants
	{{#entity.baseFields}}
	private static final String CONSTANT_{{{nameFullUcase}}}="{{{serviceName}}}";
	{{/entity.baseFields}}
	{{#entity.baseArrayFields}}
	private static final String CONSTANT_{{{nameFullUcase}}}="{{{serviceName}}}";
	{{/entity.baseArrayFields}}
	{{#entity.objectFields}}
	private static final String CONSTANT_{{{nameFullUcase}}}="{{{serviceName}}}";
	{{/entity.objectFields}}
	{{#entity.objectArrayFields}}
	private static final String CONSTANT_{{{nameFullUcase}}}="{{{serviceName}}}";
	{{/entity.objectArrayFields}}
	
	private static {{{entity.daoClassName}}} instance=new {{{entity.daoClassName}}}();

	private {{{entity.daoClassName}}}(){
		
	}
	/**
	 * Gets DAO instance
	 * @returns instance
	 */
	public static {{{entity.daoClassName}}} getInstance(){
		return instance;
	}
	
	/**
	 * Build an {{{entity.name}}} from JSON
	 */
	public {{{entity.name}}} create(JSONObject value) throws JSONException{
		{{{entity.name}}} returnValue=new {{{entity.name}}}();
		
		{{#entity.baseFields}}
		{{#isLong}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			returnValue.set{{{nameUcase}}}(Long.parseLong(String.valueOf(value.get(CONSTANT_{{nameFullUcase}}))));
		}
		{{/isLong}}
		{{#isInteger}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			if(value.get(CONSTANT_{{nameFullUcase}}).getClass()==String.class){
				returnValue.set{{{nameUcase}}}(Integer.parseInt((String)value.get(CONSTANT_{{nameFullUcase}})));
			}
			else{
				returnValue.set{{{nameUcase}}}(({{{typeJava}}})value.get(CONSTANT_{{nameFullUcase}}));
			}
		}	
		{{/isInteger}}
		{{#isFloat}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			if(value.get(CONSTANT_{{nameFullUcase}}).getClass()==String.class){
				returnValue.set{{{nameUcase}}}(Float.parseFloat((String)value.get(CONSTANT_{{nameFullUcase}})));
			}
			else{
				returnValue.set{{{nameUcase}}}(({{{typeJava}}})value.get(CONSTANT_{{nameFullUcase}}));
			}
		}	
		{{/isFloat}}
		{{#isDouble}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			returnValue.set{{{nameUcase}}}(Double.valueOf(String.valueOf(value.get(CONSTANT_{{nameFullUcase}}))));			
		}	
		{{/isDouble}}
		{{#isBoolean}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			if(value.get(CONSTANT_{{nameFullUcase}}).getClass()==String.class){
				returnValue.set{{{nameUcase}}}(Boolean.parseBoolean((String)value.get(CONSTANT_{{nameFullUcase}})));
			}
			else{
				returnValue.set{{{nameUcase}}}(({{{typeJava}}})value.get(CONSTANT_{{nameFullUcase}}));
			}
		}	
		{{/isBoolean}}		
		{{#isString}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			returnValue.set{{{nameUcase}}}(value.get(CONSTANT_{{nameFullUcase}}).toString());
		}
		{{/isString}}
		{{/entity.baseFields}}
		
		{{#entity.baseArrayFields}}
		ArrayList<{{{baseTypeSingular}}}> {{{javaName}}}List=new ArrayList<{{{baseTypeSingular}}}>();
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {

			if(value.get(CONSTANT_{{nameFullUcase}}) instanceof JSONArray){
				JSONArray {{{name}}}Array=value.getJSONArray(CONSTANT_{{nameFullUcase}});
				for(int i=0;i!={{{name}}}Array.length();i++){
					{{#isString}}
					{{{javaName}}}List.add({{{name}}}Array.getString(i));
					{{/isString}}
					{{#isInteger}}
					{{{javaName}}}List.add(Integer.valueOf((int){{{name}}}Array.getLong(i)));					
					{{/isInteger}}
					{{#isFloat}}
					{{{javaName}}}List.add(Float.valueOf((float){{{name}}}Array.getDouble(i)));					
					{{/isFloat}}
					{{#isDouble}}
					{{{javaName}}}List.add(Double.valueOf({{{name}}}Array.getDouble(i)));
					{{/isDouble}}
					{{#isBoolean}}
					{{{javaName}}}List.add(new Boolean({{{name}}}Array.getBoolean(i)));
					{{/isBoolean}}
				}
			} else {
				{{#isString}}
				{{{javaName}}}List.add(value.getString(CONSTANT_{{nameFullUcase}}));
				{{/isString}}
				{{#isInteger}}
				{{{javaName}}}List.add(Integer.valueOf(value.getLong(CONSTANT_{{nameFullUcase}})));					
				{{/isInteger}}
				{{#isFloat}}
				{{{javaName}}}List.add(Float.valueOf((float)value.getDouble(CONSTANT_{{nameFullUcase}})));					
				{{/isFloat}}
				{{#isDouble}}
				{{{javaName}}}List.add(Double.valueOf(value.getDouble(CONSTANT_{{nameFullUcase}})));
				{{/isDouble}}
				{{#isBoolean}}<commit_msg>Fix "Integer.valueOf(long)".<commit_after>package {{{packagename}}}.model.dao;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
import java.util.ArrayList;
import java.io.*;
import {{{packagename}}}.model.dto.*;

/**
 * DAO for entity {{{entity.daoClassName}}}, Singleton
 * @author Service Generator
 *
 * Generated Class - DO NOT MODIFY
 */
public final class {{{entity.daoClassName}}}{

	// XML field constants
	{{#entity.baseFields}}
	private static final String CONSTANT_{{{nameFullUcase}}}="{{{serviceName}}}";
	{{/entity.baseFields}}
	{{#entity.baseArrayFields}}
	private static final String CONSTANT_{{{nameFullUcase}}}="{{{serviceName}}}";
	{{/entity.baseArrayFields}}
	{{#entity.objectFields}}
	private static final String CONSTANT_{{{nameFullUcase}}}="{{{serviceName}}}";
	{{/entity.objectFields}}
	{{#entity.objectArrayFields}}
	private static final String CONSTANT_{{{nameFullUcase}}}="{{{serviceName}}}";
	{{/entity.objectArrayFields}}
	
	private static {{{entity.daoClassName}}} instance=new {{{entity.daoClassName}}}();

	private {{{entity.daoClassName}}}(){
		
	}
	/**
	 * Gets DAO instance
	 * @returns instance
	 */
	public static {{{entity.daoClassName}}} getInstance(){
		return instance;
	}
	
	/**
	 * Build an {{{entity.name}}} from JSON
	 */
	public {{{entity.name}}} create(JSONObject value) throws JSONException{
		{{{entity.name}}} returnValue=new {{{entity.name}}}();
		
		{{#entity.baseFields}}
		{{#isLong}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			returnValue.set{{{nameUcase}}}(Long.parseLong(String.valueOf(value.get(CONSTANT_{{nameFullUcase}}))));
		}
		{{/isLong}}
		{{#isInteger}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			if(value.get(CONSTANT_{{nameFullUcase}}).getClass()==String.class){
				returnValue.set{{{nameUcase}}}(Integer.parseInt((String)value.get(CONSTANT_{{nameFullUcase}})));
			}
			else{
				returnValue.set{{{nameUcase}}}(({{{typeJava}}})value.get(CONSTANT_{{nameFullUcase}}));
			}
		}	
		{{/isInteger}}
		{{#isFloat}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			if(value.get(CONSTANT_{{nameFullUcase}}).getClass()==String.class){
				returnValue.set{{{nameUcase}}}(Float.parseFloat((String)value.get(CONSTANT_{{nameFullUcase}})));
			}
			else{
				returnValue.set{{{nameUcase}}}(({{{typeJava}}})value.get(CONSTANT_{{nameFullUcase}}));
			}
		}	
		{{/isFloat}}
		{{#isDouble}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			returnValue.set{{{nameUcase}}}(Double.valueOf(String.valueOf(value.get(CONSTANT_{{nameFullUcase}}))));			
		}	
		{{/isDouble}}
		{{#isBoolean}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			if(value.get(CONSTANT_{{nameFullUcase}}).getClass()==String.class){
				returnValue.set{{{nameUcase}}}(Boolean.parseBoolean((String)value.get(CONSTANT_{{nameFullUcase}})));
			}
			else{
				returnValue.set{{{nameUcase}}}(({{{typeJava}}})value.get(CONSTANT_{{nameFullUcase}}));
			}
		}	
		{{/isBoolean}}		
		{{#isString}}
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {
			returnValue.set{{{nameUcase}}}(value.get(CONSTANT_{{nameFullUcase}}).toString());
		}
		{{/isString}}
		{{/entity.baseFields}}
		
		{{#entity.baseArrayFields}}
		ArrayList<{{{baseTypeSingular}}}> {{{javaName}}}List=new ArrayList<{{{baseTypeSingular}}}>();
		if(value.has(CONSTANT_{{nameFullUcase}}) && !value.get(CONSTANT_{{nameFullUcase}}).toString().equals("null")) {

			if(value.get(CONSTANT_{{nameFullUcase}}) instanceof JSONArray){
				JSONArray {{{name}}}Array=value.getJSONArray(CONSTANT_{{nameFullUcase}});
				for(int i=0;i!={{{name}}}Array.length();i++){
					{{#isString}}
					{{{javaName}}}List.add({{{name}}}Array.getString(i));
					{{/isString}}
					{{#isInteger}}
					{{{javaName}}}List.add(Integer.valueOf((int){{{name}}}Array.getLong(i)));					
					{{/isInteger}}
					{{#isFloat}}
					{{{javaName}}}List.add(Float.valueOf((float){{{name}}}Array.getDouble(i)));					
					{{/isFloat}}
					{{#isDouble}}
					{{{javaName}}}List.add(Double.valueOf({{{name}}}Array.getDouble(i)));
					{{/isDouble}}
					{{#isBoolean}}
					{{{javaName}}}List.add(new Boolean({{{name}}}Array.getBoolean(i)));
					{{/isBoolean}}
				}
			} else {
				{{#isString}}
				{{{javaName}}}List.add(value.getString(CONSTANT_{{nameFullUcase}}));
				{{/isString}}
				{{#isInteger}}
				{{{javaName}}}List.add(Integer.valueOf((int)value.getLong(CONSTANT_{{nameFullUcase}})));					
				{{/isInteger}}
				{{#isFloat}}
				{{{javaName}}}List.add(Float.valueOf((float)value.getDouble(CONSTANT_{{nameFullUcase}})));					
				{{/isFloat}}
				{{#isDouble}}
				{{{javaName}}}List.add(Double.valueOf(value.getDouble(CONSTANT_{{nameFullUcase}})));
				{{/isDouble}}
				{{#isBoolean}}
{'fraction_non_alphanumeric': 0.23088984711877694, 'fraction_numerical': 0.0001960015680125441, 'mean_word_length': 5.86742934051144, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6334150', 'n_tokens_mistral': 3955, 'n_tokens_neox': 3434, 'n_words': 360}