Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / main / java / org / onap / aai / transforms / LowerHyphenToLowerCamelConverter.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.aai.transforms;
21
22 /**
23  * <b>LowerHyphenToLowerCamelConverter</b> is the converter to use
24  * for converting from the lower hyphen to lower camel case
25  * <p>
26  * Examples:
27  *  lower-test => lowerTest
28  *  lower-Test => lowerTest
29  *  lowerTest  => lowerTest
30  *  lower-test-val => lowerTestVal
31  * <p>
32  *
33  */
34 public class LowerHyphenToLowerCamelConverter implements Converter {
35
36     /**
37      * Converts the dash formatted string into a camel case string
38      * Ensure that the capitalization is not lost during this conversion
39      * <p>
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
46      *
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
50      */
51     @Override
52     public String convert(String input) {
53         if(input == null){
54             return null;
55         }
56
57         int size = input.length();
58         StringBuilder builder = new StringBuilder(size);
59
60         boolean isPreviousCharDash = false;
61
62         for(int index = 0; index < size; ++index){
63             char ch = input.charAt(index);
64
65             if(ch == '-'){
66                 isPreviousCharDash = true;
67                 continue;
68             }
69             if(isPreviousCharDash){
70                 builder.append(Character.toUpperCase(ch));
71                 isPreviousCharDash = false;
72             } else{
73                 builder.append(ch);
74             }
75         }
76
77         return builder.toString();
78     }
79
80 }