github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/StringUtil.mustache (about)

     1  {{>licenseInfo}}
     2  
     3  package {{invokerPackage}};
     4  
     5  {{>generatedAnnotation}}
     6  public class StringUtil {
     7    /**
     8     * Check if the given array contains the given value (with case-insensitive comparison).
     9     *
    10     * @param array The array
    11     * @param value The value to search
    12     * @return true if the array contains the value
    13     */
    14    public static boolean containsIgnoreCase(String[] array, String value) {
    15      for (String str : array) {
    16        if (value == null && str == null) {
    17          return true;
    18        }
    19        if (value != null && value.equalsIgnoreCase(str)) {
    20          return true;
    21        }
    22      }
    23      return false;
    24    }
    25  
    26    /**
    27     * Join an array of strings with the given separator.
    28     * <p>
    29     * Note: This might be replaced by utility method from commons-lang or guava someday
    30     * if one of those libraries is added as dependency.
    31     * </p>
    32     *
    33     * @param array     The array of strings
    34     * @param separator The separator
    35     * @return the resulting string
    36     */
    37    public static String join(String[] array, String separator) {
    38      int len = array.length;
    39      if (len == 0) {
    40        return "";
    41      }
    42  
    43      StringBuilder out = new StringBuilder();
    44      out.append(array[0]);
    45      for (int i = 1; i < len; i++) {
    46        out.append(separator).append(array[i]);
    47      }
    48      return out.toString();
    49    }
    50  }