def _generateJavaByFieldNameOrder(self, value, fieldNameOrder): content = '' isList = False count = 1 if isinstance(value, list): content += 'list(' isList = True count = len(value) ll = [] for i in xrange(count): if isList: iteration = value[i] else: iteration = value text = 'map(' l = [] for key in fieldNameOrder: if key in iteration.keys(): l.append(Util.value2javastr(key) + ', ' + Util.value2javastr(iteration[key])) text += ', '.join(l) text += ')' ll.append(text) content += ', '.join(ll) if isList: content += ')' return content
def _generateJavaText(self, iDatas, iIdentifies): content = """package {package}; import {package}.base.LData; import {package}.base.LMap; """.format(package=Util.JAVA_PACKAGE_NAME) content += '\n/**\n' for identify in iIdentifies: content += ' * ' + identify + '.csv\n' content += ' */\n' content += """public class %s extends LData { public static final LMap data = new LMap(); """ % self.javaFileName llgroup = [] ll = None for i, data in enumerate(iDatas): if ll is None or len(ll) == ConstDataWriter.JAVA_CODE_LEN: ll = [] llgroup.append(ll) text = ' ' + Util.value2javastr( data[0]) + ', ' + Util.value2javastr(data[1]) text += ', // ' + data[2] if i < len(iDatas) - 1 and \ i % ConstDataWriter.JAVA_CODE_LEN < (ConstDataWriter.JAVA_CODE_LEN - 1) else ' // ' + data[2] ll.append(text) static_content = ' static {\n' init_content = '' for index, ll in enumerate(llgroup): init_content += ' private static void init' + str( index) + '() {\n' init_content += 'data.map(\n' init_content += '\n'.join(ll) init_content += '\n);\n' init_content += ' }\n\n' static_content += ' init' + str(index) + '();\n' static_content += ' data.setFrozen(true);\n' static_content += ' }\n\n' content += static_content content += init_content content += '}' return content
def _generateJavaText(self, iDatas, iFieldNameOrders): content = """package {package}; import {package}.base.LData; import {package}.base.LMap; """.format(package=Util.JAVA_PACKAGE_NAME) content += '\n/**\n' headKeySet = set() for head in self.heads: content += ' * ' + head[Util.FILE_IDENTIFY] + '.csv\n' for i in xrange(len(head[Util.COLUMN_NAME_KEY])): if not head[Util.COLUMN_NAME_KEY][i] in headKeySet\ and self.outputComment.has_key(head[Util.COLUMN_NAME_KEY][i]): content += ' * ' + head[Util.COLUMN_NAME_KEY][ i] + ' = ' + head[Util.FIELD_NAME_KEY][i] + '\n' headKeySet.add(head[Util.COLUMN_NAME_KEY][i]) self.outputComment.pop(head[Util.COLUMN_NAME_KEY][i]) for key, value in self.outputComment.iteritems(): if not key in headKeySet: content += ' * ' + key + ' = ' + value + '\n' content += ' */\n' content += """public class %s extends LData { public static final LMap data = new LMap(); """ % self.javaFileName llgroup = [] ll = None for index, data in enumerate(iDatas): fieldNameOrder = iFieldNameOrders[index] for key, value in sorted(data.items()): if ll is None or len(ll) == DataWriter.JAVA_CODE_LEN: ll = [] llgroup.append(ll) ll.append(' ' + Util.value2javastr(key) + ', '\ + self._generateJavaByFieldNameOrder(value, fieldNameOrder)) static_content = ' static {\n' init_content = '' for index, ll in enumerate(llgroup): init_content += ' private static void init' + str( index) + '() {\n' init_content += 'data.map(\n' init_content += ',\n'.join(ll) init_content += '\n);\n' init_content += ' }\n\n' static_content += ' init' + str(index) + '();\n' static_content += ' data.setFrozen(true);\n' static_content += ' }\n\n' content += static_content content += init_content content += '}' return content