<commit_before>/* DO NOT EDIT: File is auto-generated */
package <%= to_package(struct.gwt.qualified_jso_name) %>;

<%= description_javadoc_for(struct, "") %>@javax.annotation.Generated( "Domgen" )
@java.lang.SuppressWarnings( { "UnusedDeclaration", "JavaDoc", "unchecked", "PMD.IfStmtsMustUseBraces" } )
public final class <%= struct.gwt.jso_name %>
  extends com.google.gwt.core.client.JavaScriptObject
  implements <%= struct.gwt.qualified_interface_name %>
{
  protected <%= struct.gwt.jso_name %>()
  {
  }

  protected static <%= struct.gwt.jso_name %> create( <%= struct.fields.collect {|field| "#{annotated_type(field, :gwt, :boundary, :final => true) } #{Domgen::Naming.camelize(field.name)}" }.join(", ") %> )
  {
    final <%= struct.gwt.jso_name %> entity = com.google.gwt.core.client.JavaScriptObject.createObject().cast();
<%
  creators_used = []

  struct.fields.each do |field|
    converted_value = Proc.new do |var|
      case
        when field.struct? then "(#{field.referenced_struct.gwt.jso_name})#{var}"
        when field.date? then "#{var}.toString()"
        when field.enumeration? then "#{var}.#{field.enumeration.textual_values? ? 'name()' : 'ordinal()' }"
        else "#{var}"
      end
    end
     if :none == field.collection_type
%>    entity.set<%= field.name %>( <%= converted_value.call(field.name) %> );
<%     else
    gwt_type =
      case
        when field.date? || field.text? then "com.google.gwt.core.client.JsArrayString"
        when field.enumeration? && !field.enumeration.textual_values? then "com.google.gwt.core.client.JsArrayInteger"
        when field.enumeration? && field.enumeration.textual_values? then "com.google.gwt.core.client.JsArrayString"
        when field.integer? then "com.google.gwt.core.client.JsArrayInteger"
        when field.boolean? then "com.google.gwt.core.client.JsArrayBoolean"
        when field.struct? then "com.google.gwt.core.client.JsArray<#{field.referenced_struct.gwt.qualified_jso_name}>"
        else (Domgen.error("Unsupported field type #{field.name}"))
      end
    gwt_creator =
      case
        when field.date? || field.text? then "StringArray"
        when field.enumeration? && !field.enumeration.textual_values? then "IntegerArray"
        when field.enumeration? && field.enumeration.textual_values? then "StringArray"
        when field.integer? then "IntegerArray"
        when field.boolean? then "BooleanArray"
        when field.struct? then "ObjectArray"
        else (Domgen.error("Unsupported field type #{field.name}"))
      end
    creators_used << gwt_creator unless creators_used.include?(gwt_creator)
%>
<% if field.nullable? -%>
    if( null != <%= Domgen::Naming.camelize(field.name) %> )
    {
<% end -%>
    final <%= gwt_type %> $<%= field.name %> = newNative<%= gwt_creator %>();
    for ( final <%= field.gwt.java_component_type %> v : <%= Domgen::Naming.camelize(field.name) %> )
    {
      $<%= field.name %>.push( <%= converted_value.call("v") %> );
    }
    entity.set<%= field.name %>( $<%= field.name %> );
<% if field.nullable? -%>
    }
    else
    {
      entity.set<%= field.name %>( null );
    }
<% end -%>
<%   end
   end
%>    return entity;
  }

<% if creators_used.include?('StringArray') %>
  private static native com.google.gwt.core.client.JsArrayString newNativeStringArray() /*-{ return []; }-*/;
<% end %>
<% if creators_used.include?('IntegerArray') %>
  private static native com.google.gwt.core.client.JsArrayInteger newNativeIntegerArray() /*-{ return []; }-*/;
<% end %>
<% if creators_used.include?('ObjectArray') %>
  private static native <E extends com.google.gwt.core.client.JavaScriptObject> com.google.gwt.core.client.JsArray<E> newNativeObjectArray() /*-{ return []; }-*/;
<% end %>

<% struct.fields.select{|field| field.gwt?}.each do |field|
  if field.collection?
    collection_type_impl = field.collection_type == :set ? "HashSet" : "ArrayList"
    gwt_type_suffix =
      case
        when field.date? || field.text? then "String"
        when field.enumeration? && !field.enumeration.textual_values? then "Integer"
        when field.enumeration? && field.enumeration.textual_values? then "String"
        when field.integer? then "Integer"
        when field.boolean? then "Boolean"
        when field.struct? then "<#{field.referenced_struct.gwt.qualified_jso_name}>"
        else (Domgen.error("Unsupported field type #{field.name}"))
      end
    conversion_rule =
      case
        when field.date? then Proc.new {|field, transport_value| "org.realityforge.gwt.datatypes.client.date.RDate.parse( #{transport_value} )"}
        when field.enumeration? then Proc.new {|field, transport_value| "#{field.gwt.java_component_type}.#{field.enumeration.textual_values? ? "valueOf( #{transport_value} )" : "values()[ #{transport_value} ]"}"}
        else nil
      end
%>
  <%= annotated_type(field, :gwt, :boundary, :public => true) %> <%= getter_prefix(field) %><%= field.name %>()
  {
<% if field.nullable? -%>
    if ( is<%= field.name %>Null0() )
    {
      return null;
    }
<% end -%>
<% if conversion_rule.nil? %>
    return (<%= field.gwt.java_type %>)new org.realityforge.gwt.datatypes.client.collections.JsoReadOnly<%= field.struct? ? "" : gwt_type_suffix %><%= field.collection_type == :set ? "Set" : "List" %>( <%= getter_prefix(field) %><%= field.name %>0() );
<% else %>
    final com.google.gwt.core.client.JsArray<%= gwt_type_suffix %> source = <%= getter_prefix(field) %><%= field.name %>0();
    final java.util.<%= collection_type_impl %><<%= field.gwt.java_component_type %>> collection = new java.util.<%= collection_type_impl %><<%= field.gwt.java_component_type %>>();
    final int size = source.length();
    for( int i = 0; i < size; i++ )
    {
      collection.add( <%= conversion_rule.call(field, "source.get( i )") %> );
    }
    return java.util.Collections.unmodifiable<%= field.collection_type == :set ? "Set" : "List" %>( collection );
<% end %>
  }

  private native com.google.gwt.core.client.JsArray<%= gwt_type_suffix %> <%= getter_prefix(field) %><%= field.name %>0() /*-{
    return this.<%= field.json.name %>;
  }-*/;

<% if field.nullable? -%>
  private native boolean is<%= field.name %>Null0() /*-{
    return this.<%= field.json.name %> == null;
  }-*/;

<% end -%>
  private native void set<%= field.name %>( com.google.gwt.core.client.JsArray<%= gwt_type_suffix %> value ) /*-{
    this.<%= field.json.name %> = value;
  }-*/;
<%
   elsif field.date?
%>
  <%= annotated_type(field, :gwt, :boundary, :public => true) %> <%= getter_prefix(field) %><%= field.name %>()
  {
<% if field.nullable? -%>
    if ( is<%= field.name %>Null0() )
    {
      return null;
    }
<% end -%>
    return org.realityforge.gwt.datatypes.client.date.RDate.parse( <%= getter_prefix(field) %><%= field.name %>0() );
  }

  private native String <%= getter_prefix(field) %><%= field.name %>0() /*-{
    return this.<%= field.json.name %>;
  }-*/;

<% if field.nullable? -%>
  private native boolean is<%= field.name %>Null0() /*-{
    return this.<%= field.json.name %> == null;
  }-*/;

<% end -%>
  private native void set<%= field.name %>( String value ) /*-{
    this.<%= field.json.name %> = value;
  }-*/;
<%
   elsif field.enumeration?
%>
  <%= annotated_type(field, :gwt, :boundary, :public => true) %> <%= getter_prefix(field) %><%= field.name %>()
  {
<% if field.nullable? -%>
    if ( is<%= field.name %>Null0() )
    {
      return null;
    }
<% end -%>
    <% transport_value = "#{getter_prefix(field)}#{field.name}0()" -%>
    return <%= field.gwt.java_type %>.<%= field.enumeration.textual_values? ? "valueOf( #{transport_value} )" : "values()[ #{transport_value} ]" %>;
  }

  private native <%= field.enumeration.textual_values? ? "String" : "int" %> <%= getter_prefix(field) %><%= field.name %>0() /*-{
    return this.<%= field.json.name %>;
  }-*/;

<% if field.nullable? -%>
  private native boolean is<%= field.name %>Null0() /*-{
    return this.<%= field.json.name %> == null;
  }-*/;

<% end -%>
  private native void set<%= field.name %>( <%= field.enumeration.textual_values? ? 'String':'int'%> value ) /*-{
    this.<%= field.json.name %> = value;
  }-*/;
<%
   elsif field.integer? && field.nullable?
%>
  <%= annotated_type(field, :gwt, :boundary, :native => true, :public => true) %> <%= getter_prefix(field) %><%= field.name %>() /*-{
    return this.<%= field.json.name %> ? @java.lang.Integer::valueOf(I)( this.<%= field.json.name %> ) : null
  }-*/;

  private void set<%= field.name %>( <%= annotated_type(field, :gwt, :boundary, :final => true) %> value )
  {
    if( null != value ) set<%= field.name %>0( value.intValue() );
  }<commit_msg>Handle nulls properly, including numm numeric enumerations<commit_after>/* DO NOT EDIT: File is auto-generated */
package <%= to_package(struct.gwt.qualified_jso_name) %>;

<%= description_javadoc_for(struct, "") %>@javax.annotation.Generated( "Domgen" )
@java.lang.SuppressWarnings( { "UnusedDeclaration", "JavaDoc", "unchecked", "PMD.IfStmtsMustUseBraces" } )
public final class <%= struct.gwt.jso_name %>
  extends com.google.gwt.core.client.JavaScriptObject
  implements <%= struct.gwt.qualified_interface_name %>
{
  protected <%= struct.gwt.jso_name %>()
  {
  }

  protected static <%= struct.gwt.jso_name %> create( <%= struct.fields.collect {|field| "#{annotated_type(field, :gwt, :boundary, :final => true) } #{Domgen::Naming.camelize(field.name)}" }.join(", ") %> )
  {
    final <%= struct.gwt.jso_name %> entity = com.google.gwt.core.client.JavaScriptObject.createObject().cast();
<%
  creators_used = []

  struct.fields.each do |field|
    converted_value = Proc.new do |var|
      case
        when field.struct? then "(#{field.referenced_struct.gwt.jso_name})#{var}"
        when field.date? then "#{var}.toString()"
        when field.enumeration? then "#{var}.#{field.enumeration.textual_values? ? 'name()' : 'ordinal()' }"
        else "#{var}"
      end
    end
     if :none == field.collection_type
%>    entity.set<%= field.name %>( <%= field.nullable? ? "#{Domgen::Naming.camelize(field.name)} == null ? null : " : '' %><%= converted_value.call(Domgen::Naming.camelize(field.name)) %> );
<%     else
    gwt_type =
      case
        when field.date? || field.text? then "com.google.gwt.core.client.JsArrayString"
        when field.enumeration? && !field.enumeration.textual_values? then "com.google.gwt.core.client.JsArrayInteger"
        when field.enumeration? && field.enumeration.textual_values? then "com.google.gwt.core.client.JsArrayString"
        when field.integer? then "com.google.gwt.core.client.JsArrayInteger"
        when field.boolean? then "com.google.gwt.core.client.JsArrayBoolean"
        when field.struct? then "com.google.gwt.core.client.JsArray<#{field.referenced_struct.gwt.qualified_jso_name}>"
        else (Domgen.error("Unsupported field type #{field.name}"))
      end
    gwt_creator =
      case
        when field.date? || field.text? then "StringArray"
        when field.enumeration? && !field.enumeration.textual_values? then "IntegerArray"
        when field.enumeration? && field.enumeration.textual_values? then "StringArray"
        when field.integer? then "IntegerArray"
        when field.boolean? then "BooleanArray"
        when field.struct? then "ObjectArray"
        else (Domgen.error("Unsupported field type #{field.name}"))
      end
    creators_used << gwt_creator unless creators_used.include?(gwt_creator)
%>
<% if field.nullable? -%>
    if( null != <%= Domgen::Naming.camelize(field.name) %> )
    {
<% end -%>
    final <%= gwt_type %> $<%= field.name %> = newNative<%= gwt_creator %>();
    for ( final <%= field.gwt.java_component_type %> v : <%= Domgen::Naming.camelize(field.name) %> )
    {
      $<%= field.name %>.push( <%= converted_value.call("v") %> );
    }
    entity.set<%= field.name %>( $<%= field.name %> );
<% if field.nullable? -%>
    }
    else
    {
      entity.set<%= field.name %>( null );
    }
<% end -%>
<%   end
   end
%>    return entity;
  }

<% if creators_used.include?('StringArray') %>
  private static native com.google.gwt.core.client.JsArrayString newNativeStringArray() /*-{ return []; }-*/;
<% end %>
<% if creators_used.include?('IntegerArray') %>
  private static native com.google.gwt.core.client.JsArrayInteger newNativeIntegerArray() /*-{ return []; }-*/;
<% end %>
<% if creators_used.include?('ObjectArray') %>
  private static native <E extends com.google.gwt.core.client.JavaScriptObject> com.google.gwt.core.client.JsArray<E> newNativeObjectArray() /*-{ return []; }-*/;
<% end %>

<% struct.fields.select{|field| field.gwt?}.each do |field|
  if field.collection?
    collection_type_impl = field.collection_type == :set ? "HashSet" : "ArrayList"
    gwt_type_suffix =
      case
        when field.date? || field.text? then "String"
        when field.enumeration? && !field.enumeration.textual_values? then "Integer"
        when field.enumeration? && field.enumeration.textual_values? then "String"
        when field.integer? then "Integer"
        when field.boolean? then "Boolean"
        when field.struct? then "<#{field.referenced_struct.gwt.qualified_jso_name}>"
        else (Domgen.error("Unsupported field type #{field.name}"))
      end
    conversion_rule =
      case
        when field.date? then Proc.new {|field, transport_value| "org.realityforge.gwt.datatypes.client.date.RDate.parse( #{transport_value} )"}
        when field.enumeration? then Proc.new {|field, transport_value| "#{field.gwt.java_component_type}.#{field.enumeration.textual_values? ? "valueOf( #{transport_value} )" : "values()[ #{transport_value} ]"}"}
        else nil
      end
%>
  <%= annotated_type(field, :gwt, :boundary, :public => true) %> <%= getter_prefix(field) %><%= field.name %>()
  {
<% if field.nullable? -%>
    if ( is<%= field.name %>Null0() )
    {
      return null;
    }
<% end -%>
<% if conversion_rule.nil? %>
    return (<%= field.gwt.java_type %>)new org.realityforge.gwt.datatypes.client.collections.JsoReadOnly<%= field.struct? ? "" : gwt_type_suffix %><%= field.collection_type == :set ? "Set" : "List" %>( <%= getter_prefix(field) %><%= field.name %>0() );
<% else %>
    final com.google.gwt.core.client.JsArray<%= gwt_type_suffix %> source = <%= getter_prefix(field) %><%= field.name %>0();
    final java.util.<%= collection_type_impl %><<%= field.gwt.java_component_type %>> collection = new java.util.<%= collection_type_impl %><<%= field.gwt.java_component_type %>>();
    final int size = source.length();
    for( int i = 0; i < size; i++ )
    {
      collection.add( <%= conversion_rule.call(field, "source.get( i )") %> );
    }
    return java.util.Collections.unmodifiable<%= field.collection_type == :set ? "Set" : "List" %>( collection );
<% end %>
  }

  private native com.google.gwt.core.client.JsArray<%= gwt_type_suffix %> <%= getter_prefix(field) %><%= field.name %>0() /*-{
    return this.<%= field.json.name %>;
  }-*/;

<% if field.nullable? -%>
  private native boolean is<%= field.name %>Null0() /*-{
    return this.<%= field.json.name %> == null;
  }-*/;

<% end -%>
  private native void set<%= field.name %>( com.google.gwt.core.client.JsArray<%= gwt_type_suffix %> value ) /*-{
    this.<%= field.json.name %> = value;
  }-*/;
<%
   elsif field.date?
%>
  <%= annotated_type(field, :gwt, :boundary, :public => true) %> <%= getter_prefix(field) %><%= field.name %>()
  {
<% if field.nullable? -%>
    if ( is<%= field.name %>Null0() )
    {
      return null;
    }
<% end -%>
    return org.realityforge.gwt.datatypes.client.date.RDate.parse( <%= getter_prefix(field) %><%= field.name %>0() );
  }

  private native String <%= getter_prefix(field) %><%= field.name %>0() /*-{
    return this.<%= field.json.name %>;
  }-*/;

<% if field.nullable? -%>
  private native boolean is<%= field.name %>Null0() /*-{
    return this.<%= field.json.name %> == null;
  }-*/;

<% end -%>
  private native void set<%= field.name %>( String value ) /*-{
    this.<%= field.json.name %> = value;
  }-*/;
<%
   elsif field.enumeration?
%>
  <%= annotated_type(field, :gwt, :boundary, :public => true) %> <%= getter_prefix(field) %><%= field.name %>()
  {
<% if field.nullable? -%>
    if ( is<%= field.name %>Null0() )
    {
      return null;
    }
<% end -%>
    <% transport_value = "#{getter_prefix(field)}#{field.name}0()" -%>
    return <%= field.gwt.java_type %>.<%= field.enumeration.textual_values? ? "valueOf( #{transport_value} )" : "values()[ #{transport_value} ]" %>;
  }

  private native <%= field.enumeration.textual_values? ? "String" : "int" %> <%= getter_prefix(field) %><%= field.name %>0() /*-{
    return this.<%= field.json.name %>;
  }-*/;

<% if field.nullable? -%>
  private native boolean is<%= field.name %>Null0() /*-{
    return this.<%= field.json.name %> == null;
  }-*/;

  private native void set<%= field.name %>Null0() /*-{
    this.<%= field.json.name %> = null;
  }-*/;

<% end -%>
<% if field.enumeration.textual_values? %>
  private native void set<%= field.name %>( final java.lang.String value ) /*-{
    this.<%= field.json.name %> = value;
  }-*/;
<% else %>
  private native void set<%= field.name %>0( final int value ) /*-{
    this.<%= field.json.name %> = value;
  }-*/;

  private void set<%= field.name %>( final Integer value )
  {
<% if field.nullable? -%>
    if( null != value ) set<%= field.name %>0( value.intValue() );
    else set<%= field.name %>Null0();
<% else -%>
    set<%= field.name %>0( value.intValue() );
<% end -%>
  }
<% end -%>
<%
   elsif field.integer? && field.nullable?
%>
  <%= annotated_type(field, :gwt, :boundary, :native => true, :public => true) %> <%= getter_prefix(field) %><%= field.name %>() /*-{
    return this.<%= field.json.name %> ? @java.lang.Integer::valueOf(I)( this.<%= field.json.name %> ) : null
  }-*/;

  private void set<%= field.name %>( <%= annotated_type(field, :gwt, :boundary, :final => true) %> value )
  {
    if( null != value ) set<%= field.name %>0( value.intValue() );
    else set<%= field.name %>Null0();
  }

  private native void set<%= field.name %>Null0() /*-{
    this.<%= field.json.name %> = null;
  }-*/;
{'fraction_non_alphanumeric': 0.19959289211641085, 'fraction_numerical': 0.0020355394179457555, 'mean_word_length': 3.4850727855909205, 'pattern_counts': {'":': 0, '<': 272, '<?xml version=': 0, '>': 280, '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': '5002126', 'n_tokens_mistral': 6750, 'n_tokens_neox': 6179, 'n_words': 1160}