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 public String calcGetter() {
41 if (calcFieldTypeToUse(ms.getType()).equals("Boolean")) {
42 if (ms.getShortName().toLowerCase().startsWith("is")) {
43 return calcInitLower(ms.getShortName());
44 }
45 return "is" + calcInitUpper(ms.getShortName());
46 }
47 return "get" + calcInitUpper(ms.getShortName());
48 }
49
50 public String calcSetter() {
51 if (calcFieldTypeToUse(ms.getType()).equals("Boolean")) {
52 if (ms.getShortName().toLowerCase().startsWith("is")) {
53 return "set" + calcInitUpper(ms.getShortName().substring(2));
54 }
55 }
56 return "set" + calcInitUpper(ms.getShortName());
57 }
58
59 public static String calcInitUpper(String name) {
60 return name.substring(0, 1).toUpperCase() + name.substring(1);
61 }
62
63 public static String calcInitLower(String name) {
64 return name.substring(0, 1).toLowerCase() + name.substring(1);
65 }
66
67 public String calcFieldTypeToUse(String type) {
68 return MessageStructureTypeCalculator.calculate(writer, model, type, type, null);
69 }
70
71 public static String stripList(String str) {
72 if (str.endsWith("List")) {
73 return str.substring(0, str.length() - "List".length());
74 }
75 return str;
76 }
77 }