Hi All:

What do you all think about this addition for Commons Text (I currently do
use it):

import java.util.Locale;

/**
 * Enumerates letter cases and converts strings.
 *
 * @author <a href="mailto:ggreg...@rocketsoftware.com";>Gary Gregory</a>
 */
public enum LetterCase {

    LOWER {
        @Override
        public char[] convert(final char[] source, final Locale locale) {
            return String.valueOf(source).toLowerCase(locale).toCharArray();
        }

        @Override
        public String convert(final String source, final Locale locale) {
            return source.toLowerCase(locale);
        }

    },
    UPPER {
        @Override
        public char[] convert(final char[] source, final Locale locale) {
            return String.valueOf(source).toUpperCase(locale).toCharArray();
        }

        @Override
        public String convert(final String source, final Locale locale) {
            return source.toUpperCase(locale);
        }
    };

    /**
     * Converts from the given {@code source} char[] to the case specified
by this enum using the default {@code locale}.
     *
     * @param source
     *            the char[] to convert
     * @param locale
     *            the locale to use for conversion.
     * @return a converted char[].
     */
    public char[] convert(final char[] source) {
        return convert(source, Locale.getDefault());
    }

    /**
     * Converts from the given {@code source} char[] to the case specified
by this enum using the given {@code locale}.
     *
     * @param source
     *            the char[] to convert
     * @param locale
     *            the locale to use for conversion.
     * @return a converted char[].
     */
    public abstract char[] convert(char[] source, Locale locale);

    /**
     * Converts from the given {@code source} string to the case specified
by this enum using the default {@code locale}.
     *
     * @param source
     *            the string to convert
     * @param locale
     *            the locale to use for conversion.
     * @return a converted string.
     */
    public String convert(final String source) {
        return convert(source, Locale.getDefault());
    }

    /**
     * Converts from the given {@code source} string to the case specified
by this enum using the given {@code locale}.
     *
     * @param source
     *            the string to convert
     * @param locale
     *            the locale to use for conversion.
     * @return a converted string.
     */
    public abstract String convert(String source, Locale locale);

}

?

Gary

Reply via email to