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