/** * Truncates or pads the string value of the specified object as necessary * to ensure that the returned string's length equals the specified cell size. * @param obj the value to be put in the 'cell' * @param cellsize the size of the cell into which the object must be placed * @param suffix the suffix to put at the end of any values that need truncating * to indicate that they've been truncated * @return truncated/padded string */ public String cell(Object obj, int cellsize, String suffix) { if (obj == null || cellsize <= 0) { return null; } String value = String.valueOf(obj); if (value.length() == cellsize) { return value; } else if (value.length() > cellsize) { return truncate(value, cellsize, suffix); } else { return value + space(cellsize - value.length()); } }