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