Take an array of strings and make a greedy disjunction regex pattern out of it,
with the longest strings first, e.g. ["sus4","sus","sus2"] -->

(sus4|sus2|sus)
@param allAliases
@return
351072
function greedyDisjunction (aliases, matchingGroup) {
  aliases = aliases.slice() // copy

  // sort by longest string first
  aliases.sort(function (a, b) {
    let lenCompare = b.length - a.length
    if (lenCompare !== 0) {
      return lenCompare < 0 ? -1 : 1
    }
    // else sort by normal string comparison
    return a < b ? -1 : 1
  })

  let res = '('

  if (!matchingGroup) {
    res += '?:' //  non-matching group
  }

  aliases.forEach(function (alias, i) {
    if (!alias) {
      return // e.g. the "major" quality can be expressed as an empty string, so skip in the regex
    }
    if (i > 0) {
      res += '|'
    }
    res += quote(alias)
  })

  return res + ')'
}
855427
public static long[] toLongArray(String pString, String pDelimiters) {
        if (isEmpty(pString)) {
            return new long[0];
        }

        // Some room for improvement here...
        String[] temp = toStringArray(pString, pDelimiters);
        long[] array = new long[temp.length];

        for (int i = 0; i < array.length; i++) {
            array[i] = Long.parseLong(temp[i]);
        }
        return array;
    }
1267081
public static Long[] transformToLong(final String[] ids) {
    if (null == ids) return new Long[0];
    Long[] idsOfLong = new Long[ids.length];
    for (int i = 0; i < ids.length; i++) {
      idsOfLong[i] = new Long(ids[i]);
    }
    return idsOfLong;
  }
459601
public static int[] getMatchNos(String[] strings, String[] s) {
        int[] nos = new int[s.length];
        for (int i = 0, j = 0; i < strings.length; i++) {
            for (int k = 0; k < s.length; k++) {
                if (s[k].equals(strings[i])) {
                    nos[j] = i;
                    j++;
                }
            }
        }
        return nos;
    }
1371034
public static String join(String[] strings) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < strings.length; i++) {
            builder.append(strings[i]);
            if (i + 1 < strings.length) builder.append(",");
        }
        return builder.toString();
    }
808045
static String[] splitOnTokens(String text)
    {
        // used by wildcardMatch
        // package level so a unit test may run on this

        if (text.indexOf('?') == -1 && text.indexOf('*') == -1)
        {
            return new String[]
                    {
                        text
                    };
        }

        char[] array = text.toCharArray();
        ArrayList<String> list = new ArrayList<String>();
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < array.length; i++)
        {
            if (array[i] == '?' || array[i] == '*')
            {
                if (buffer.length() != 0)
                {
                    list.add(buffer.toString());
                    buffer.setLength(0);
                }
                if (array[i] == '?')
                {
                    list.add("?");
                }
                else if (list.isEmpty()
                        || i > 0 && list.get(list.size() - 1).equals("*") == false)
                {
                    list.add("*");
                }
            }
            else
            {
                buffer.append(array[i]);
            }
        }
        if (buffer.length() != 0)
        {
            list.add(buffer.toString());
        }

        return list.toArray(new String[list.size()]);
    }
188388
public static String[] decodeLemmas(final String[] tokens,
      final Span[] preds) {
    final List<String> lemmas = new ArrayList<>();
    for (final Span span : preds) {
      String lemma = decodeShortestEditScript(
          span.getCoveredText(tokens).toLowerCase(), span.getType());
      // System.err.println("-> DEBUG: " + toks[i].toLowerCase() + " " +
      // preds[i] + " " + lemma);
      if (lemma.length() == 0) {
        lemma = "_";
      }
      lemmas.add(lemma);
    }
    return lemmas.toArray(new String[lemmas.size()]);
  }
170995
public int[] buildSuffixArray(T[] tokens) {
        final int length = tokens.length;
        /*
         * Allocate slightly more space, some suffix construction strategies need it and
         * we don't want to waste space for multiple symbol mappings.
         */
        input = new int[length + SuffixArrays.MAX_EXTRA_TRAILING_SPACE];

        //System.out.println("Assigning token ids ...");

        /*
         * We associate every token to an id, all `equal´ tokens to the same id.
         * The suffix array is built using only the the ids.
         */
        tokIDs = new TreeMap<>(comparator);

        for (int i = 0; i < length; i++) {
            tokIDs.putIfAbsent(tokens[i], i);
            input[i] = tokIDs.get(tokens[i]);
        }

        //System.out.println("Token ids assigned.");

        return delegate.buildSuffixArray(input, 0, length);
    }
1082836
private static String pickDelimiter(String[] strings) {
    boolean allLength1 = true;
    for (String s : strings) {
      if (s.length() != 1) {
        allLength1 = false;
        break;
      }
    }

    if (allLength1) {
      return "";
    }

    String[] delimiters = new String[]{" ", ";", ",", "{", "}", null};
    int i = 0;
    NEXT_DELIMITER: for (; delimiters[i] != null; i++) {
      for (String cur : strings) {
        if (cur.contains(delimiters[i])) {
          continue NEXT_DELIMITER;
        }
      }
      break;
    }
    return delimiters[i];
  }
965032
public static String join(CharSequence delimiter, Iterable tokens) {
        StringBuilder sb = new StringBuilder();
        boolean firstTime = true;
        for (Object token: tokens) {
            if (firstTime) {
                firstTime = false;
            } else {
                sb.append(delimiter);
            }
            sb.append(token);
        }
        return sb.toString();
    }
175
public static String[] trimAll(final String[] strings) {
        if (null == strings) {
            return null;
        }

        return Arrays.stream(strings).map(StringUtils::trim).toArray(size -> new String[size]);
    }
232625
public function longestCommonSubsequence(array $a, array $b)
    {
        $c = array();

        $m = count($a);
        $n = count($b);

        for ($i = 0; $i <= $m; $i++) {
            $c[$i][0] = 0;
        }

        for ($j = 0; $j <= $n; $j++) {
            $c[0][$j] = 0;
        }

        for ($i = 1; $i <= $m; $i++) {
            for ($j = 1; $j <= $n; $j++) {
                if ($this->matchStrategy->isMatch($a[$i - 1], $b[$j - 1])) {
                    $c[$i][$j] = 1 + (isset($c[$i - 1][$j - 1]) ? $c[$i - 1][$j - 1] : 0);
                } else {
                    $c[$i][$j] = max(
                        isset($c[$i][$j - 1]) ? $c[$i][$j - 1] : 0,
                        isset($c[$i - 1][$j]) ? $c[$i - 1][$j] : 0
                    );
                }
            }
        }

        $lcs = array_pad(array(), $m + 1, 0);
        $this->compileMatches($c, $a, $b, $m, $n, $lcs);

        return $lcs;
    }
513039
protected static Pattern[] commaDelimitedListToPatternArray(String commaDelimitedPatterns) {
        String[] patterns = commaDelimitedListToStringArray(commaDelimitedPatterns);
        List<Pattern> patternsList = new ArrayList<Pattern>();
        for (String pattern : patterns) {
            try {
                patternsList.add(Pattern.compile(pattern));
            } catch (PatternSyntaxException e) {
                throw new IllegalArgumentException("Illegal pattern syntax '" + pattern + "'", e);
            }
        }
        return patternsList.toArray(new Pattern[0]);
    }
1322660
static String[] split( String selectors ) {
        ArrayList<String> result = null;
        int length = selectors.length();
        char quote = 0;
        int off = 0;
        for( int i = 0; i < length; i++ ) {
            char ch = selectors.charAt( i );
            switch( ch ) {
                case ',':
                    if( result == null ) {
                        result = new ArrayList<>();
                    }
                    result.add( selectors.substring( off, i ).trim() );
                    off = i + 1;
                    break;
                case '\'':
                case '\"':
                    do {
                        i++;
                    } while( i < length && selectors.charAt( i ) != ch );
            }
        }
        if( result == null ) {
            return new String[] { selectors.trim() };
        }
        result.add( selectors.substring( off, length ).trim() );
        return result.toArray( new String[result.size()] );
    }
82504
public Splitter trim(char[] chars) {
    Matcher matcher = new CharsMatcher(chars);
    return new Splitter(pairSeparator, keyValueSeparator, matcher, matcher);
  }
835345
public static List<int[]> longestCommonSubsequence(String s0, String s1) {
        int[][] lengths = new int[s0.length() + 1][s1.length() + 1];
        for (int i = 0; i < s0.length(); i++)
            for (int j = 0; j < s1.length(); j++)
                if (s0.charAt(i) == (s1.charAt(j)))
                    lengths[i + 1][j + 1] = lengths[i][j] + 1;
                else
                    lengths[i + 1][j + 1] = Math.max(lengths[i + 1][j], lengths[i][j + 1]);

        return extractIndexes(lengths, s0.length(), s1.length());
    }
1365499
public static String[] minus(String[] arr1, String[] arr2) {
		LinkedList<String> list = new LinkedList<String>();
		LinkedList<String> history = new LinkedList<String>();
		String[] longerArr = arr1;
		String[] shorterArr = arr2;
		if (arr1.length > arr2.length) {
			longerArr = arr2;
			shorterArr = arr1;
		}
		for (String str : longerArr) {
			if (!list.contains(str)) {
				list.add(str);
			}
		}
		for (String str : shorterArr) {
			if (list.contains(str)) {
				history.add(str);
				list.remove(str);
			} else {
				if (!history.contains(str)) {
					list.add(str);
				}
			}
		}

		String[] result = {};
		return list.toArray(result);
	}