public static void main(String[] args) {
    if (args == null || args.length < 2) {
      printHelp();
      throw new IllegalArgumentException("Minimum 2 file pathes needed");
    }
    List<String> inputFileNames = new ArrayList<String>();
    for (int i = 0; i < args.length - 1; i++ ) {
      inputFileNames.add(args[i]);
    }
    String outputFileName = args[args.length - 1];
    FileFormat inputFileFormat = checkFileFormat(inputFileNames);
    FileFormat outputFileFormat = checkFileFormat(outputFileName);
    if (inputFileFormat == FileFormat.CSV) {
      if (outputFileFormat == FileFormat.CSV) {
        new TicketService(new CsvReader(), new CsvWriter()).merge(inputFileNames, outputFileName);
      } else if (outputFileFormat == FileFormat.XML) {
        new TicketService(new CsvReader(), new JdomXmlWriter()).merge(inputFileNames, outputFileName);
      } else {
        printHelp();
        throw new IllegalArgumentException("Output file has unsupported format");
      }
    } else if (inputFileFormat == FileFormat.XML) {
      if (outputFileFormat == FileFormat.XML) {
        new TicketService(new StaxReader(), new JdomXmlWriter()).merge(inputFileNames, outputFileName);
      } else {
        printHelp();
        throw new IllegalArgumentException("XML have to merge in XML");
      }
    } else {
      printHelp();
      throw new IllegalArgumentException("Input file have invalid format");
    }
  }