1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.contract.writer.service;
17
18 import org.kuali.student.contract.model.MessageStructure;
19 import org.kuali.student.contract.model.ServiceContractModel;
20 import org.kuali.student.contract.writer.JavaClassWriter;
21
22
23
24
25
26 public class GetterSetterNameCalculator {
27
28 private MessageStructure ms;
29 private JavaClassWriter writer;
30 private ServiceContractModel model;
31
32 public GetterSetterNameCalculator(MessageStructure ms,
33 JavaClassWriter writer,
34 ServiceContractModel model) {
35 this.ms = ms;
36 this.writer = writer;
37 this.model = model;
38 }
39
40
41
42
43 public String calcGetter() {
44 if (calcFieldTypeToUse(ms.getType()).equals("Boolean")) {
45 if (ms.getShortName().toLowerCase().startsWith("is")) {
46 return calcInitLower(ms.getShortName());
47 }
48 return "is" + calcInitUpper(ms.getShortName());
49 }
50 return "get" + calcInitUpper(ms.getShortName());
51 }
52
53
54
55
56 public String calcSetter() {
57 if (calcFieldTypeToUse(ms.getType()).equals("Boolean")) {
58 if (ms.getShortName().toLowerCase().startsWith("is")) {
59 return "set" + calcInitUpper(ms.getShortName().substring(2));
60 }
61 }
62 return "set" + calcInitUpper(ms.getShortName());
63 }
64
65 public static String dot2Camel (String name) {
66 StringBuilder sb = new StringBuilder ();
67 boolean upper = true;
68 for (char c : name.toCharArray()) {
69 if (c == '.') {
70 upper = true;
71 continue;
72 }
73 if (upper) {
74 c = Character.toUpperCase(c);
75 upper = false;
76 }
77 sb.append (c);
78 }
79 return sb.toString();
80 }
81 public static String calcInitUpper(String name) {
82 return name.substring(0, 1).toUpperCase() + name.substring(1);
83 }
84
85 public static String calcInitLower(String name) {
86 return name.substring(0, 1).toLowerCase() + name.substring(1);
87 }
88
89 public String calcFieldTypeToUse(String type) {
90 return MessageStructureTypeCalculator.calculate(writer, model, type, type, null);
91 }
92
93 public static String stripList(String str) {
94 if (str.endsWith("List")) {
95 return str.substring(0, str.length() - "List".length());
96 }
97 return str;
98 }
99 }