<commit_before>/* DO NOT EDIT: File is auto-generated */
package <%= data_module.imit.entity_package %>;

import org.realityforge.replicant.client.EntityChangeBroker;
import org.realityforge.replicant.client.EntityRepository;

/**
 * Utility class to map a change to an entity ensuring that the repository is updated as required.
 */
@javax.annotation.Generated( "Domgen" )
@SuppressWarnings( { "UnusedDeclaration", "JavaDoc" } )
public class <%= data_module.imit.mapper_name %>
{
  private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger( <%= data_module.imit.mapper_name %>.class.getName() );

  private final EntityRepository _repository;
  private final EntityChangeBroker _broker;

  @javax.inject.Inject
  public <%= data_module.imit.mapper_name %>( final @javax.annotation.Nonnull EntityRepository repository, final @javax.annotation.Nonnull EntityChangeBroker broker )
  {
    _repository = repository;
    _broker = broker;
  }

<% data_module.imit.client_side_entities.each do |entity| %>
<% if !entity.abstract? %>
  public Object applyChangeTo<%= entity.name %>( final Object id, final java.util.Map<String, java.io.Serializable> attributes )
  {
    <%= entity.imit.name %> entity = _repository.findByID( <%= entity.imit.name %>.class, id );
    // If change is a delete...
    if( null == attributes )
    {
      if( null != entity )
      {
        if( _broker.isEnabled() && LOG.isLoggable( java.util.logging.Level.FINE ) )
        {
          LOG.log( java.util.logging.Level.FINE, "applyChangeTo<%= entity.name %>('" + id + "') is deleting local entity" );
        }
        // It is in the local repository so we need to delete it
        _repository.deregisterEntity( <%= entity.imit.name %>.class, id );
         entity.invalidate();
      }
    }
    else
    {
      boolean fullUpdate = false;
      if( null == entity )
      {
        entity = new <%= entity.imit.name %>( _repository, _broker );
        _repository.registerEntity( <%= entity.imit.name %>.class, id, entity );
        fullUpdate = true;
        if( _broker.isEnabled() && LOG.isLoggable( java.util.logging.Level.FINE ) )
        {
          LOG.log( java.util.logging.Level.FINE, "applyChangeTo<%= entity.name %>('" + id + "') is creating local entity" );
        }
      }
      else
      {
        if( _broker.isEnabled() && LOG.isLoggable( java.util.logging.Level.FINE ) )
        {
          LOG.log( java.util.logging.Level.FINE, "applyChangeTo<%= entity.name %>('" + id + "') is updating local entity" );
        }
      }
      updateAttributes<%= entity.name %>( entity, attributes, fullUpdate );
    }
    return entity;
  }

<% end %>
  private void updateAttributes<%= entity.name %>( final <%= entity.imit.name %> entity, final java.util.Map<String, java.io.Serializable> attributes, final boolean fullUpdate )
  {
<% if entity.extends
   other = entity.data_module.entity_by_name(entity.extends)
%>    updateAttributes<%= other.name %>( entity, attributes, fullUpdate );
<% end %>
<% entity.declared_attributes.select{|attribute| attribute.imit.client_side? }.each do |attribute|
    value_converter =
        if attribute.imit.characteristic_type(:transport) == :datetime || attribute.imit.characteristic_type(:transport) == :date
          "new java.util.Date( ( (Number) value ).longValue() )"
        elsif attribute.imit.characteristic_type(:transport) == :integer
          "( (Number) value ).intValue()"
        elsif attribute.imit.characteristic_type(:transport) == :real
          "( (Double) value ).doubleValue()"
        elsif attribute.imit.characteristic_type(:transport) == :boolean
          "( (Boolean) value ).booleanValue()"
        elsif attribute.imit.characteristic_type(:transport) == :text
          "( (String) value )"
        elsif attribute.imit.characteristic_type(:transport) == :enumeration && attribute.enumeration.textual_values?
          "( (String) value )"
        elsif attribute.imit.characteristic_type == :enumeration && attribute.enumeration.numeric_values?
          "( null == value ? null : ( (Number) value ).intValue() )"
        else
          raise "Unable to convert data type #{attribute.imit.characteristic_type(:transport)} on #{attribute.qualified_name}"
        end
%>    if( attributes.containsKey( <%= entity.name %>.<%= uppercase_constantize( attribute.name ) %> ) )
    {
      <% if attribute.primary_key? %>if( fullUpdate )
      {<% end %>
      @javax.annotation.Nonnull final Object value = attributes.get( <%= entity.name %>.<%= uppercase_constantize(attribute.name) %> );
      assert null != value;
      set<%= attribute.imit.name(:transport) %>_On_<%= entity.name %>( entity, <%= attribute.nullable? ? "( null != value ? #{value_converter} : null )" : value_converter %> );
      <% if attribute.primary_key? %>
      }<% end %>
    }
<% end %>
  }
<% end %>

<% data_module.entities.select{|entity| entity.imit.client_side?}.each do |entity| %>
<% entity.declared_attributes.select{|attribute| attribute.imit.client_side?}.each do |attribute| %>
  private void set<%= attribute.imit.name(:transport) %>_On_<%= entity.name %>( @javax.annotation.Nonnull final <%= entity.imit.name %> entity, @javax.annotation.Nonnull final <%= attribute.imit.java_type(:transport) %> value )
  {
<%
   getter_text = "entity.get#{attribute.imit.name(:transport)}()"
   equal_check =
       if attribute.primary_key?
         "true"
       elsif attribute.enumeration? && attribute.enumeration.numeric_values?
         "(null == #{getter_text} || #{getter_text}.ordinal() != value)"
       elsif attribute.enumeration? && attribute.enumeration.numeric_values?
         "(null == #{getter_text} || !#{getter_text}.name().equals( value ) )"
         #"#{attribute.enumeration.imit.qualified_name}.valueOf( (String) value )"
       elsif attribute.imit.primitive?(:transport)
         "#{getter_text} != value"
       else
         "!( (null == value && null == #{getter_text}) || (null != #{getter_text} && null != value && #{getter_text}.equals( value ) ) )"
       end
%>
    if( <%= equal_check %> )
    {
      entity.set<%= attribute.imit.name(:transport) %>( value );
    }
  }
<% end %>
<% end %>
}
<commit_msg>Improve nullability handling in generated mapper<commit_after>/* DO NOT EDIT: File is auto-generated */
package <%= data_module.imit.entity_package %>;

import org.realityforge.replicant.client.EntityChangeBroker;
import org.realityforge.replicant.client.EntityRepository;

/**
 * Utility class to map a change to an entity ensuring that the repository is updated as required.
 */
@javax.annotation.Generated( "Domgen" )
@SuppressWarnings( { "UnusedDeclaration", "JavaDoc" } )
public class <%= data_module.imit.mapper_name %>
{
  private static final java.util.logging.Logger LOG = java.util.logging.Logger.getLogger( <%= data_module.imit.mapper_name %>.class.getName() );

  private final EntityRepository _repository;
  private final EntityChangeBroker _broker;

  @javax.inject.Inject
  public <%= data_module.imit.mapper_name %>( final @javax.annotation.Nonnull EntityRepository repository, final @javax.annotation.Nonnull EntityChangeBroker broker )
  {
    _repository = repository;
    _broker = broker;
  }

<% data_module.imit.client_side_entities.each do |entity| %>
<% if !entity.abstract? %>
  public Object applyChangeTo<%= entity.name %>( final Object id, final java.util.Map<String, java.io.Serializable> attributes )
  {
    <%= entity.imit.name %> entity = _repository.findByID( <%= entity.imit.name %>.class, id );
    // If change is a delete...
    if( null == attributes )
    {
      if( null != entity )
      {
        if( _broker.isEnabled() && LOG.isLoggable( java.util.logging.Level.FINE ) )
        {
          LOG.log( java.util.logging.Level.FINE, "applyChangeTo<%= entity.name %>('" + id + "') is deleting local entity" );
        }
        // It is in the local repository so we need to delete it
        _repository.deregisterEntity( <%= entity.imit.name %>.class, id );
         entity.invalidate();
      }
    }
    else
    {
      boolean fullUpdate = false;
      if( null == entity )
      {
        entity = new <%= entity.imit.name %>( _repository, _broker );
        _repository.registerEntity( <%= entity.imit.name %>.class, id, entity );
        fullUpdate = true;
        if( _broker.isEnabled() && LOG.isLoggable( java.util.logging.Level.FINE ) )
        {
          LOG.log( java.util.logging.Level.FINE, "applyChangeTo<%= entity.name %>('" + id + "') is creating local entity" );
        }
      }
      else
      {
        if( _broker.isEnabled() && LOG.isLoggable( java.util.logging.Level.FINE ) )
        {
          LOG.log( java.util.logging.Level.FINE, "applyChangeTo<%= entity.name %>('" + id + "') is updating local entity" );
        }
      }
      updateAttributes<%= entity.name %>( entity, attributes, fullUpdate );
    }
    return entity;
  }

<% end %>
  private void updateAttributes<%= entity.name %>( final <%= entity.imit.name %> entity, final java.util.Map<String, java.io.Serializable> attributes, final boolean fullUpdate )
  {
<% if entity.extends
   other = entity.data_module.entity_by_name(entity.extends)
%>    updateAttributes<%= other.name %>( entity, attributes, fullUpdate );
<% end %>
<% entity.declared_attributes.select{|attribute| attribute.imit.client_side? }.each do |attribute|
    value_converter =
        if attribute.imit.characteristic_type(:transport) == :datetime || attribute.imit.characteristic_type(:transport) == :date
          "new java.util.Date( ( (Number) value ).longValue() )"
        elsif attribute.imit.characteristic_type(:transport) == :integer
          "( (Number) value ).intValue()"
        elsif attribute.imit.characteristic_type(:transport) == :real
          "( (Double) value ).doubleValue()"
        elsif attribute.imit.characteristic_type(:transport) == :boolean
          "( (Boolean) value ).booleanValue()"
        elsif attribute.imit.characteristic_type(:transport) == :text
          "( (String) value )"
        elsif attribute.imit.characteristic_type(:transport) == :enumeration && attribute.enumeration.textual_values?
          "( (String) value )"
        elsif attribute.imit.characteristic_type == :enumeration && attribute.enumeration.numeric_values?
          "( null == value ? null : ( (Number) value ).intValue() )"
        else
          raise "Unable to convert data type #{attribute.imit.characteristic_type(:transport)} on #{attribute.qualified_name}"
        end
%>    if( attributes.containsKey( <%= entity.name %>.<%= uppercase_constantize( attribute.name ) %> ) )
    {
      <% if attribute.primary_key? %>if( fullUpdate )
      {<% end %>
      <%= nullability_annotation(attribute.nullable?) %> final Object value = attributes.get( <%= entity.name %>.<%= uppercase_constantize(attribute.name) %> );
      <% if !attribute.nullable? %>assert null != value;<% end %>
      set<%= attribute.imit.name(:transport) %>_On_<%= entity.name %>( entity, <%= attribute.nullable? ? "( null != value ? #{value_converter} : null )" : value_converter %> );
      <% if attribute.primary_key? %>
      }<% end %>
    }
<% end %>
  }
<% end %>

<% data_module.entities.select{|entity| entity.imit.client_side?}.each do |entity| %>
<% entity.declared_attributes.select{|attribute| attribute.imit.client_side?}.each do |attribute| %>
  private void set<%= attribute.imit.name(:transport) %>_On_<%= entity.name %>( @javax.annotation.Nonnull final <%= entity.imit.name %> entity, @javax.annotation.Nonnull final <%= attribute.imit.java_type(:transport) %> value )
  {
<%
   getter_text = "entity.get#{attribute.imit.name(:transport)}()"
   equal_check =
       if attribute.primary_key?
         "true"
       elsif attribute.enumeration? && attribute.enumeration.numeric_values?
         "(null == #{getter_text} || #{getter_text}.ordinal() != value)"
       elsif attribute.enumeration? && attribute.enumeration.numeric_values?
         "(null == #{getter_text} || !#{getter_text}.name().equals( value ) )"
         #"#{attribute.enumeration.imit.qualified_name}.valueOf( (String) value )"
       elsif attribute.imit.primitive?(:transport)
         "#{getter_text} != value"
       else
         "!( (null == value && null == #{getter_text}) || (null != #{getter_text} && null != value && #{getter_text}.equals( value ) ) )"
       end
%>
    if( <%= equal_check %> )
    {
      entity.set<%= attribute.imit.name(:transport) %>( value );
    }
  }
<% end %>
<% end %>
}

{'fraction_non_alphanumeric': 0.1563598593799936, 'fraction_numerical': 0.0, 'mean_word_length': 3.2647359454855196, 'pattern_counts': {'":': 0, '<': 104, '<?xml version=': 0, '>': 104, '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': '112090', 'n_tokens_mistral': 3914, 'n_tokens_neox': 3695, 'n_words': 768}