Java Java String Format toJavaEnum(String inStr)

Here you can find the source of toJavaEnum(String inStr)

Description

to Java Enum

License

Apache License

Declaration

public static String toJavaEnum(String inStr) 

Method Source Code

//package com.java2s;
/*-/*from   w  w w.j a va2  s  .c o  m*/
 * ============LICENSE_START=======================================================
 * openECOMP : SDN-C
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights
 *                   reserved.
 * ================================================================================
 * Licensed 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.
 * ============LICENSE_END=========================================================
 */

public class Main {
    public static String toJavaEnum(String inStr) {
        if (inStr == null) {
            return (null);
        } else if (inStr.length() == 0) {
            return (inStr);
        }

        //This will strip out all periods, which cannot be in a java enum
        inStr = inStr.replaceAll("\\.", "");

        String[] terms = inStr.split("-");
        StringBuffer sbuff = new StringBuffer();

        //appends an _ if the string starts with a digit to make it a valid java enum
        if (Character.isDigit(inStr.charAt(0))) {
            sbuff.append('_');
        }
        //If the string contains hyphens it will convert the string to upperCamelCase without hyphens
        for (String term : terms) {
            sbuff.append(term.substring(0, 1).toUpperCase());
            if (term.length() > 1) {
                sbuff.append(term.substring(1));
            }
        }
        return (sbuff.toString());

    }
}

Related

  1. toJavaBool(byte goBool)
  2. toJavaCasing(final String pName)
  3. toJavaClassName(String str)
  4. toJavaConstantIdentifier(String name)
  5. toJavadocComment(String comment)
  6. toJavaHex(byte in[], int len)
  7. toJavaHexCharString(final char chr)
  8. toJavaIdentifier(String name)
  9. toJavaIdentifier(String name)