code: public static String suggest(Filter<String> filter, String pattern, boolean tryEmptyVar){
          if(!pattern.contains("${i}"))
              throw new IllegalArgumentException("pattern must have ${i}");
  
          TemplateMatcher matcher = new TemplateMatcher("${", "}");
  
          if(tryEmptyVar){
              String value = matcher.replace(pattern, Collections.singletonMap("i", ""));
              if(filter.select(value))
                  return value;
          }
  
          int i = tryEmptyVar ? 2 : 1;
          while(true){
              String value = matcher.replace(pattern, Collections.singletonMap("i", String.valueOf(i)));
              if(filter.select(value))
                  return value;
              i++;
          }
      }
docs: the pattern specified must have variable part ${i}
  example: test${i}.txt
  
  it will find a string using pattern, which is accepted by the specified filter.
  if tryEmptyVar is true, it searches in order:
  test.txt, test2.txt, test3.txt and so on
  if tryEmptyVar is false, it searches in order:
  test1.txt, test2.txt, test3.txt and so on
  
  @see jlibs.core.io.FileUtil#findFreeFile(java.io.File dir, String pattern, boolean tryEmptyVar)