public static String generateUniqueExpressionName(final DataSchema dataSchema,
final String pattern,
final AbstractReportDefinition extraColumns)
throws ReportProcessingException
{
final FastMessageFormat fastMessageFormat = new FastMessageFormat(pattern);
if (fastMessageFormat.getSubFormatCount() == 0)
{
throw new IllegalArgumentException();
}
final HashSet<String> names = new HashSet<String>(Arrays.asList(dataSchema.getNames()));
final Expression[] expressions = extraColumns.getExpressions().getExpressions();
for (int i = 0; i < expressions.length; i++)
{
final Expression expression = expressions[i];
names.add(expression.getName());
}
final Object[] data = new Object[1];
int i = 0;
// call me at any time if you have more than 32000 functions of the same name-pattern in a single report.
while (i < Short.MAX_VALUE)
{
data[0] = IntegerCache.getInteger(i);
final String s = fastMessageFormat.format(data);
if (names.contains(s) == false)
{
return s;
}
i += 1;