class StringUtilities {

    public static String[] explodeLineOnUnquotedCommas(String line)
    {
        if (line == null)
        {
            return null;
        }
        final List<String> valueList = new ArrayList<>();
        int lastIndex = 0;
        boolean inQuote = false;

        for (int i = 0; i < line.length(); i++)
        {
            if (line.charAt(i) == '"')
            {
                inQuote = !inQuote;
            }

            if (!inQuote)
            {
                if (line.charAt(i) == ',')
                {
                    String sub = line.substring(lastIndex, i);

                    sub = sub.trim();

                    // Remove lead and trail quotes
                    if (sub.length() > 1 && sub.charAt(0) == '"' && sub.charAt(sub.length() - 1) == '"')
                    {
                        sub = sub.substring(1, sub.length() - 1);
                    }

                    valueList.add(sub.trim());
                    lastIndex = i + 1;
                }
                if (i == line.length() - 1 && lastIndex < line.length())
                {
                    final String sub = line.substring(lastIndex);
                    valueList.add(sub.trim());
                }
            }
        }

        return !valueList.isEmpty() ? valueList.toArray(new String[valueList.size()]) : null;
    }

    private  StringUtilities();

}