<commit_before>base_package = 'cz/stechy/drd/'
templates = './resources/templates/'
online_item_template = ''
base_manager_template = ''
advanced_manager_template = ''
getter_setter_property_template = ''
getter_setter_object_property_template = ''
builder_template = ''

with open(templates + 'online_item_template.txt', 'r') as online_item_template_file:
  online_item_template = online_item_template_file.read()

with open(templates + 'base_manager_template.txt', 'r') as base_manager_template_file:
  base_manager_template = base_manager_template_file.read()

with open(templates + 'advanced_manager_template.txt', 'r') as advanced_manager_template_file:
  advanced_manager_template = advanced_manager_template_file.read()

with open(templates + 'getter_setter_property_template.txt', 'r') as getter_setter_property_template_file:
  getter_setter_property_template = getter_setter_property_template_file.read()

with open(templates + 'getter_setter_object_property_template.txt', 'r') as getter_setter_object_property_template_file:
  getter_setter_object_property_template = getter_setter_object_property_template_file.read()

with open(templates + 'builder_template.txt', 'r') as builder_template_file:
  builder_template = builder_template_file.read()

def type_to_class_wrap(type):
  if type == 'int':
    return 'Integer'
  elif type == 'boolean':
    return 'Boolean'
  elif type == 'long':
    return 'Long'
  else:
    return type

def type_to_property(name, type, specialized_type=''):
  property_template = 'protected final {type}Property{specialized_type} {name} = new Simple{type}Property();\n'

  if type == 'int':
    return property_template.format(type='Integer', name=name, specialized_type='')
  elif type == 'String':
    return property_template.format(type='String', name=name, specialized_type='')
  elif type == 'boolean':
    return property_template.format(type='Boolean', name=name, specialized_type='')
  elif type == 'blob':
    return property_template.format(type='Object', name=name, specialized_type='<{}>'.format(specialized_type))
  elif type == 'money':
    return 'protected final Money {name} = new Money();'.format(name=name)

def type_to_query(type):
  if type == 'int':
    return '\n+ "%s INT NOT NULL,"'
  if type == 'String':
    return '\n+ "%s VARCHAR(255) NOT NULL,"'
  if type == 'blob':
    return '\n+ "%s BLOB,"'
  if type == 'boolean':
    return '\n+ "%s BOOLEAN NOT NULL,"'
  else:
    return 'unknown'

def format(what, dic):
  result = what
  for entry in dic:
    result = result.replace('{' + entry['name'] + '}', entry['replace'])
  return result

class ItemBuilder:

  def __init__(self):
    self.table_name = ''
    self.firebase_child_path = ''
    self.use_firebase = False
    self.generic_class = ''
    self.cols = {}

  def table(self, table):
    self.table_name = table

  def set_firebase(self, use):
    self.use_firebase = use

  def set_firebase_child_path(self, path):
    self.firebase_child_path = path

  def item_name(self, name):
    self.generic_class = name

  def columns(self, cols):
    self.cols = cols

  def build(self, source_path):
    def build_item(file):
      class_name = self.generic_class
      properties = ''
      fields_in_constructor = ''
      fields_in_constructor_params = ''
      fields_assignment = ''
      getters_and_setters = ''
      builder_fields = ''
      builder_setters = ''
      builder_constructor_fields = ''

      for col in self.cols:
        name = col['name']
        type = col['type']
        specialized_type = col.get('specialized_type', '')
        title = col['name'].title()
        is_blob = type == 'blob'
        final_type = specialized_type if is_blob else type
        properties += type_to_property(name, type, specialized_type)
        fields_in_constructor += '{} {}, '.format(final_type, name)
        fields_in_constructor_params += 'item.get{name}(), '.format(name=title)
        fields_assignment += 'this.{name}.setValue({name});\n'.format(name=name)
        getters_and_setters_template = getter_setter_object_property_template if is_blob else getter_setter_property_template
        getters_and_setters += format(getters_and_setters_template, [{'name': 'name', 'replace': name}, {'name': 'type', 'replace': type_to_class_wrap(final_type)}, {'name': 'name_title', 'replace': title}])
        builder_fields += 'private {} {};\n'.format(final_type, name)
        builder_setters += format(builder_template, [{'name': 'name', 'replace': name}, {'name': 'type', 'replace': final_type}])
        builder_constructor_fields += '{}, '.format(name)

        content = format(online_item_template, [{'name': 'class_name', 'replace': class_name},
                                                {'name': 'properties', 'replace': properties},
                                                {'name': 'fields_in_constructor', 'replace': fields_in_constructor},
                                                {'name': 'fields_in_constructor_params', 'replace': fields_in_constructor_params},
                                                {'name': 'fields_assignment', 'replace': fields_assignment},
                                                {'name': 'getters_and_setters', 'replace': getters_and_setters},
                                                {'name': 'builder_fields', 'replace': builder_fields},
                                                {'name': 'builder_setters', 'replace': builder_setters},
                                                {'name': 'builder_constructor_fields', 'replace': builder_constructor_fields},
                                                ])
      file.write(content)

    def build_manager(file):
      def build_data_snapshot(name, type):
        def get_class(type):
          if type == "String":<commit_msg>Oprava chyby ve skriptu - špatné odsazení<commit_after>base_package = 'cz/stechy/drd/'
templates = './resources/templates/'
online_item_template = ''
base_manager_template = ''
advanced_manager_template = ''
getter_setter_property_template = ''
getter_setter_object_property_template = ''
builder_template = ''

with open(templates + 'online_item_template.txt', 'r') as online_item_template_file:
  online_item_template = online_item_template_file.read()

with open(templates + 'base_manager_template.txt', 'r') as base_manager_template_file:
  base_manager_template = base_manager_template_file.read()

with open(templates + 'advanced_manager_template.txt', 'r') as advanced_manager_template_file:
  advanced_manager_template = advanced_manager_template_file.read()

with open(templates + 'getter_setter_property_template.txt', 'r') as getter_setter_property_template_file:
  getter_setter_property_template = getter_setter_property_template_file.read()

with open(templates + 'getter_setter_object_property_template.txt', 'r') as getter_setter_object_property_template_file:
  getter_setter_object_property_template = getter_setter_object_property_template_file.read()

with open(templates + 'builder_template.txt', 'r') as builder_template_file:
  builder_template = builder_template_file.read()

def type_to_class_wrap(type):
  if type == 'int':
    return 'Integer'
  elif type == 'boolean':
    return 'Boolean'
  elif type == 'long':
    return 'Long'
  else:
    return type

def type_to_property(name, type, specialized_type=''):
  property_template = 'protected final {type}Property{specialized_type} {name} = new Simple{type}Property();\n'

  if type == 'int':
    return property_template.format(type='Integer', name=name, specialized_type='')
  elif type == 'String':
    return property_template.format(type='String', name=name, specialized_type='')
  elif type == 'boolean':
    return property_template.format(type='Boolean', name=name, specialized_type='')
  elif type == 'blob':
    return property_template.format(type='Object', name=name, specialized_type='<{}>'.format(specialized_type))
  elif type == 'money':
    return 'protected final Money {name} = new Money();'.format(name=name)

def type_to_query(type):
  if type == 'int':
    return '\n+ "%s INT NOT NULL,"'
  if type == 'String':
    return '\n+ "%s VARCHAR(255) NOT NULL,"'
  if type == 'blob':
    return '\n+ "%s BLOB,"'
  if type == 'boolean':
    return '\n+ "%s BOOLEAN NOT NULL,"'
  else:
    return 'unknown'

def format(what, dic):
  result = what
  for entry in dic:
    result = result.replace('{' + entry['name'] + '}', entry['replace'])
  return result

class ItemBuilder:

  def __init__(self):
    self.table_name = ''
    self.firebase_child_path = ''
    self.use_firebase = False
    self.generic_class = ''
    self.cols = {}

  def table(self, table):
    self.table_name = table

  def set_firebase(self, use):
    self.use_firebase = use

  def set_firebase_child_path(self, path):
    self.firebase_child_path = path

  def item_name(self, name):
    self.generic_class = name

  def columns(self, cols):
    self.cols = cols

  def build(self, source_path):
    def build_item(file):
      class_name = self.generic_class
      properties = ''
      fields_in_constructor = ''
      fields_in_constructor_params = ''
      fields_assignment = ''
      getters_and_setters = ''
      builder_fields = ''
      builder_setters = ''
      builder_constructor_fields = ''

      for col in self.cols:
        name = col['name']
        type = col['type']
        specialized_type = col.get('specialized_type', '')
        title = col['name'].title()
        is_blob = type == 'blob'
        final_type = specialized_type if is_blob else type
        properties += type_to_property(name, type, specialized_type)
        fields_in_constructor += '{} {}, '.format(final_type, name)
        fields_in_constructor_params += 'item.get{name}(), '.format(name=title)
        fields_assignment += 'this.{name}.setValue({name});\n'.format(name=name)
        getters_and_setters_template = getter_setter_object_property_template if is_blob else getter_setter_property_template
        getters_and_setters += format(getters_and_setters_template, [{'name': 'name', 'replace': name}, {'name': 'type', 'replace': type_to_class_wrap(final_type)}, {'name': 'name_title', 'replace': title}])
        builder_fields += 'private {} {};\n'.format(final_type, name)
        builder_setters += format(builder_template, [{'name': 'name', 'replace': name}, {'name': 'type', 'replace': final_type}])
        builder_constructor_fields += '{}, '.format(name)

      content = format(online_item_template, [{'name': 'class_name', 'replace': class_name},
                                                {'name': 'properties', 'replace': properties},
                                                {'name': 'fields_in_constructor', 'replace': fields_in_constructor},
                                                {'name': 'fields_in_constructor_params', 'replace': fields_in_constructor_params},
                                                {'name': 'fields_assignment', 'replace': fields_assignment},
                                                {'name': 'getters_and_setters', 'replace': getters_and_setters},
                                                {'name': 'builder_fields', 'replace': builder_fields},
                                                {'name': 'builder_setters', 'replace': builder_setters},
                                                {'name': 'builder_constructor_fields', 'replace': builder_constructor_fields},
                                                ])
      file.write(content)

    def build_manager(file):
      def build_data_snapshot(name, type):
        def get_class(type):
          if type == "String":
{'fraction_non_alphanumeric': 0.12849785407725323, 'fraction_numerical': 0.0005150214592274678, 'mean_word_length': 3.315185185185185, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1178994', 'n_tokens_mistral': 3382, 'n_tokens_neox': 3357, 'n_words': 702}