protected String getValueWithPadding(String value, Field field) { int paddingLength = field.getFixedLength() - value.length(); StringBuilder valueWithPadding = new StringBuilder(); for (int i = 0; i < paddingLength; i++) { valueWithPadding.append(field.getPadding()); } return valueWithPadding.append(value).toString(); }
@Override public String randomValueAsString(Field<TYPE> field) { TYPE randomValue = randomValue(field); String stringValue = randomValue.toString(); if (field.getPadding() != null) { long maxLength = field.getMaxLength() != 0 ? field.getMaxLength() : field.getFixedLength(); stringValue = paddedRandomValue(field.getPadding(), randomValue, maxLength); } return stringValue; }
@Override public TYPE randomValue(Field<TYPE> field) { TYPE value = null; if (field.getConstantValue() != null) { value = valueFromString(field.getConstantValue()); return value; } if (field.getRange() != null) { List<TYPE> values = (List<TYPE>) Arrays.asList(field.getRange().split(",")); value = randomValueFromRange(values); return value; } // If min max values are specified they take precedence over length if (field.getMinValue() != null && field.getMaxValue() != null) { TYPE minValue = valueFromString(field.getMinValue()); TYPE maxValue = valueFromString(field.getMaxValue()); value = randomValueFromRange(minValue, maxValue); return value; } long minLength = field.getMinLength() != 0 ? field.getMinLength() : field.getFixedLength(); long maxLength = field.getMaxLength() != 0 ? field.getMaxLength() : field.getFixedLength(); if (field.getPrefix() != null) { value = randomValueWithPrefix(minLength, maxLength, field.getPrefix()); return value; } if (field.getSuffix() != null) { value = randomValueWithSuffix(minLength, maxLength, field.getSuffix()); return value; } value = randomValue(minLength, maxLength); return value; }