2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.transforms;
23 * <b>LowerHyphenToLowerCamelConverter</b> is the converter to use
24 * for converting from the lower hyphen to lower camel case
27 * lower-test => lowerTest
28 * lower-Test => lowerTest
29 * lowerTest => lowerTest
30 * lower-test-val => lowerTestVal
34 public class LowerHyphenToLowerCamelConverter implements Converter {
37 * Converts the dash formatted string into a camel case string
38 * Ensure that the capitalization is not lost during this conversion
40 * Loops through each character in the string
41 * checks if the current character is '-' and if it is then sets the
42 * boolean isPreviousCharDash to true and continues to the next iteration
43 * If the character is not '-', then checks if the previous character is dash
44 * If it is, then it will upper case the current character and appends to the builder
45 * Otherwise, it will just append the current character without any modification
47 * @param input the input string to convert to camel case
48 * @return a string that is converted to camel case
49 * if the input is null, then it returns null
52 public String convert(String input) {
57 int size = input.length();
58 StringBuilder builder = new StringBuilder(size);
60 boolean isPreviousCharDash = false;
62 for(int index = 0; index < size; ++index){
63 char ch = input.charAt(index);
66 isPreviousCharDash = true;
69 if(isPreviousCharDash){
70 builder.append(Character.toUpperCase(ch));
71 isPreviousCharDash = false;
77 return builder.toString();