Coverage Report - org.kuali.rice.devtools.generators.Util
 
Classes in this File Line Coverage Branch Coverage Complexity
Util
0%
0/21
0%
0/6
1.333
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.devtools.generators;
 17  
 
 18  
 import java.util.Arrays;
 19  
 import java.util.List;
 20  
 
 21  
 /**
 22  
  * This is a description of what this class does - ewestfal don't forget to fill this in. 
 23  
  * 
 24  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 25  
  *
 26  
  */
 27  0
 final class Util {
 28  
         
 29  
         static final String VERSION_NUMBER_FIELD = "versionNumber";
 30  
         static final String OBJECT_ID_FIELD = "objectId";
 31  
         
 32  
         static final String CONSTANTS_CLASS_NAME = "Constants";
 33  
         static final String ROOT_ELEMENT_NAME_FIELD = "ROOT_ELEMENT_NAME";
 34  
         static final String TYPE_NAME_FIELD = "TYPE_NAME";
 35  
         static final String TYPE_NAME_SUFFIX = "Type";
 36  
         static final String HASH_CODE_EQUALS_EXCLUDE_FIELD = "HASH_CODE_EQUALS_EXCLUDE";
 37  
         static final String COMMON_ELEMENTS_CLASS = "CommonElements";
 38  
         static final String FUTURE_ELEMENTS_FIELD = "FUTURE_ELEMENTS";
 39  
         static final String CONSTANTS_CLASS_JAVADOC = "Defines some internal constants used on this class.";
 40  
         
 41  
         static final String ELEMENTS_CLASS_NAME = "Elements";
 42  
         static final String ELEMENTS_CLASS_JAVADOC = "A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.";
 43  0
         static final List<String> COMMON_ELEMENTS = Arrays.asList(VERSION_NUMBER_FIELD, OBJECT_ID_FIELD);
 44  
         
 45  
         static final String BUILDER_CLASS_NAME = "Builder";
 46  
         
 47  
         static String toLowerCaseFirstLetter(String value) {
 48  0
                 return value.substring(0, 1).toLowerCase() + value.substring(1);
 49  
         }
 50  
         
 51  
         static String toUpperCaseFirstLetter(String value) {
 52  0
                 return value.substring(0, 1).toUpperCase() + value.substring(1);
 53  
         }
 54  
         
 55  
         static String toConstantsVariable(String fieldName) {
 56  0
                 StringBuilder constantVariable = new StringBuilder();
 57  
                 // just to be safe
 58  0
                 fieldName = toLowerCaseFirstLetter(fieldName);
 59  0
                 StringBuilder segAccum = new StringBuilder();
 60  0
                 for (char character : fieldName.toCharArray()) {
 61  0
                         if (Character.isUpperCase(character)) {
 62  0
                                 constantVariable.append(segAccum.toString().toUpperCase());
 63  0
                                 constantVariable.append("_");
 64  0
                                 segAccum = new StringBuilder();
 65  
                         }
 66  0
                         segAccum.append(character);
 67  
                 }
 68  
                 // do the last bit
 69  0
                 constantVariable.append(segAccum.toString().toUpperCase());
 70  0
                 return constantVariable.toString();
 71  
         }
 72  
         
 73  
         static String generateGetterName(String fieldName, boolean is) {
 74  0
                 return (is ? "is" : "get") + Util.toUpperCaseFirstLetter(fieldName);
 75  
         }
 76  
         
 77  
         static String generateGetter(String fieldName, boolean is) {
 78  0
                 return generateGetterName(fieldName, is) + "()";
 79  
         }
 80  
         
 81  
         static String generateSetterName(String fieldName) {
 82  0
                 return "set" + Util.toUpperCaseFirstLetter(fieldName);
 83  
         }
 84  
         
 85  
         static String generateSetter(String fieldName, String valueToSet) {
 86  0
                 return generateSetterName(fieldName) + "(" + valueToSet + ")";
 87  
         } 
 88  
         
 89  
         
 90  
         static boolean isCommonElement(String fieldName) {
 91  0
                 return COMMON_ELEMENTS.contains(fieldName);
 92  
         }
 93  
                 
 94  
         static String generateBuilderJavadoc(String simpleClassName, String simpleContractClassName) {
 95  0
                 return "A builder which can be used to construct {@link " + simpleClassName + "} instances.  " +
 96  
                         "Enforces the constraints of the {@link " + simpleContractClassName + "}.";
 97  
         }
 98  
 
 99  
 }