for (Iterator iter = groups.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); List mygroups = (List) entry.getValue(); IntField groupField = new IntField(((Integer) entry.getKey()) .intValue()); groupField.setValue(mygroups.size()); groupField.toString(buffer); buffer.append('\001'); for (int i = 0; i < mygroups.size(); i++) { FieldMap groupFields = (FieldMap) mygroups.get(i); groupFields.calculateString(buffer, preFields, postFields); } } if (postFields != null) { for (int i = 0; i < postFields.length; i++) { Field field = getField(postFields[i], null); field.toString(buffer); buffer.append('\001'); } } }
for (Iterator iter = fields.values().iterator(); iter.hasNext();) { Field field = (Field) iter.next(); int tag = field.getField(); if (!isOrderedField(tag, preFields) && !isOrderedField(tag, postFields) && !isGroupField(tag)) { field.toString(buffer); buffer.append('\001'); } else if (isGroupField(tag) && isOrderedField(tag, fieldOrder) && getGroupCount(tag) > 0) { List groups = getGroups(tag); field.toString(buffer); buffer.append('\001'); for (int i = 0; i < groups.size(); i++) { FieldMap groupFields = (FieldMap) groups.get(i); groupFields.calculateString(buffer, preFields, postFields); } } }  for (Iterator iter = groups.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); Integer groupCountTag = (Integer) entry.getKey(); if (!isOrderedField(groupCountTag.intValue(), fieldOrder)) { List groups = (List) entry.getValue(); IntField countField = new IntField(groupCountTag.intValue(), groups.size()); countField.toString(buffer); buffer.append('\001'); for (int i = 0; i < groups.size(); i++) { FieldMap groupFields = (FieldMap) groups.get(i); groupFields.calculateString(buffer, preFields, postFields); } } }  if (postFields != null) { for (int i = 0; i < postFields.length; i++) { Field field = getField(postFields[i], null); field.toString(buffer); buffer.append('\001'); } } }
	protected void calculateString(StringBuffer buffer, int[] preFields, int[] postFields) {		if (preFields != null) {			for (int i = 0; i < preFields.length; i++) {				Field field = getField(preFields[i], null);				field.toString(buffer);				buffer.append('\001');			}		}        		for (Iterator iter = fields.values().iterator(); iter.hasNext();) {			Field field = (Field) iter.next();			if (!isOrderedField(field.getField(), preFields)					&& !isOrderedField(field.getField(), postFields)					&& !isGroupField(field.getField())) {				field.toString(buffer);				buffer.append('\001');			}		}        // TODO BUG The groups should not be written after the fields        // TODO BUG Add nested group field numbers from code generator        // TODO TEST Write test for nested group formatting (NewOrderCross/NoParties)        // This loop should be incorporated into the field iteration loop.        // Currently the code generator doesn't appear to include nested group        // count tags so this also should be fixed.		for (Iterator iter = groups.entrySet().iterator(); iter.hasNext();) {			Map.Entry entry = (Map.Entry) iter.next();			List mygroups = (List) entry.getValue();			IntField groupField = new IntField(((Integer) entry.getKey())					.intValue());			groupField.setValue(mygroups.size());			groupField.toString(buffer);			buffer.append('\001');			for (int i = 0; i < mygroups.size(); i++) {				FieldMap groupFields = (FieldMap) mygroups.get(i);				groupFields.calculateString(buffer, preFields, postFields);			}		}		if (postFields != null) {			for (int i = 0; i < postFields.length; i++) {				Field field = getField(postFields[i], null);				field.toString(buffer);				buffer.append('\001');			}		}	}