1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.devtools.generators; |
17 | |
|
18 | |
import java.util.Arrays; |
19 | |
import java.util.List; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
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 | |
|
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 | |
|
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 | |
} |