Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
- package org.apache.commons.text;
- import java.util.Locale;
- /**
- * Enumerates letter cases and converts strings.
- *
- * @author <a href="mailto:ggregory@rocketsoftware.com">Gary Gregory</a>
- */
- public enum LetterCase {
- LOWER {
- @Override
- public char[] toCaseString(final char[] source, final Locale locale) {
- return String.valueOf(source).toLowerCase(locale).toCharArray();
- }
- @Override
- public String toCaseString(final String source, final Locale locale) {
- return source.toLowerCase(locale);
- }
- },
- UPPER {
- @Override
- public char[] toCaseString(final char[] source, final Locale locale) {
- return String.valueOf(source).toUpperCase(locale).toCharArray();
- }
- @Override
- public String toCaseString(final String source, final Locale locale) {
- return source.toUpperCase(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 char[] toCaseString(final char[] source) {
- return toCaseString(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[] toCaseString(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 toCaseString(final String source) {
- return toCaseString(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 toCaseString(String source, Locale locale);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement