LIST, ARRAY_LIST);
final String identifierMethodName = getIdentifierMethodName(field)
.getSymbolName();
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine(collectionName + " " + localEnitiesName
+ " = new " + instantiableCollection + "();");
bodyBuilder
.appendFormalLine("List<Long> longIds = new ArrayList<Long>();");
bodyBuilder.appendFormalLine("for (Key key : " + entityIdsName + ") {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("if (!longIds.contains(key.getId())) {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("longIds.add(key.getId());");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.appendFormalLine("for ("
+ collectionElementType.getSimpleTypeName() + " entity : "
+ entityCollectionName + ") {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("if (!longIds.contains(entity."
+ identifierMethodName + "())) {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("longIds.add(entity."
+ identifierMethodName + "());");
bodyBuilder.appendFormalLine(entityIdsName
+ ".add(KeyFactory.createKey("
+ collectionElementType.getSimpleTypeName()
+ ".class.getName(), entity." + identifierMethodName + "()));");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.appendFormalLine(localEnitiesName + ".add(entity);");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.appendFormalLine("this." + entityCollectionName + " = "
+ localEnitiesName + ";");
return bodyBuilder;
}