code: public static String generateUnionStatement(List<String> patterns) {
          // Check the input and exit immediately if null
          if (patterns == null || patterns.isEmpty()) {
              return "";
          }
  
          // This is a trivial UNION
          if (patterns.size() == 1) {
              return patterns.get(0);
          }
  
          // General case
          StringBuffer query = new StringBuffer();
          // Add the first one as a special case and then loop over the rest
          query.append("  {" + NL);
          query.append(patterns.get(0));
          query.append("  }" + NL);
  
          for (int i = 1; i < patterns.size(); i++) {
              query.append("  UNION {" + NL);
              query.append(patterns.get(i));
              query.append("  }" + NL);
          }
  
          return query.toString();
      }
docs: Generates a UNION SPARQL statement for the patterns passed in the input
  
  @param patterns the patterns to make a UNION of
  @return the UNION SPARQL statement