+++ /dev/null
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.binding.generator.util;\r
-\r
-public class CodeGeneratorHelper {\r
-\r
- public static String parseToClassName(String token) {\r
- String correctStr = parseToCamelCase(token);\r
-\r
- // make first char upper-case\r
- char first = Character.toUpperCase(correctStr.charAt(0));\r
- correctStr = first + correctStr.substring(1);\r
- return correctStr;\r
- }\r
-\r
- public static String parseToParamName(String token) {\r
- String correctStr = parseToCamelCase(token);\r
-\r
- // make first char lower-case\r
- char first = Character.toLowerCase(correctStr.charAt(0));\r
- correctStr = first + correctStr.substring(1);\r
- return correctStr;\r
- }\r
-\r
- private static String parseToCamelCase(String token) {\r
- if (token == null) {\r
- throw new NullPointerException("Name can not be null");\r
- }\r
-\r
- String correctStr = token.trim();\r
- if (correctStr.length() == 0) {\r
- throw new IllegalArgumentException("Name can not be emty");\r
- }\r
-\r
- correctStr = replaceWithCamelCase(correctStr, ' ');\r
- correctStr = replaceWithCamelCase(correctStr, '-');\r
- correctStr = replaceWithCamelCase(correctStr, '_');\r
- return correctStr;\r
- }\r
-\r
- private static String replaceWithCamelCase(String text, char removalChar) {\r
- StringBuilder sb = new StringBuilder(text);\r
- String toBeRemoved = String.valueOf(removalChar);\r
-\r
- int toBeRemovedPos = sb.indexOf(toBeRemoved);\r
- while (toBeRemovedPos != -1) {\r
- sb.replace(toBeRemovedPos, toBeRemovedPos + 1, "");\r
- // check if 'toBeRemoved' character is not the only character in\r
- // 'text'\r
- if (sb.length() == 0) {\r
- throw new IllegalArgumentException("Name can not be '"\r
- + toBeRemoved + "'");\r
- }\r
- String replacement = String.valueOf(sb.charAt(toBeRemovedPos))\r
- .toUpperCase();\r
- sb.setCharAt(toBeRemovedPos, replacement.charAt(0));\r
- toBeRemovedPos = sb.indexOf(toBeRemoved);\r
- }\r
- return sb.toString();\r
- }\r
-\r
-}\r