1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.contract.writer; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class JavaEnumConstantCalculator |
23 | |
{ |
24 | |
|
25 | |
private String name; |
26 | |
|
27 | |
public JavaEnumConstantCalculator (String name) |
28 | 0 | { |
29 | 0 | this.name = name; |
30 | 0 | } |
31 | |
|
32 | |
public String calc () |
33 | |
{ |
34 | 0 | StringBuilder buf = new StringBuilder (name.length () + 3); |
35 | |
|
36 | 0 | char c = Character.toUpperCase (name.charAt (0)); |
37 | 0 | buf.append (c); |
38 | 0 | boolean lastUpper = Character.isUpperCase (c); |
39 | 0 | for (int i = 1; i < name.length (); i ++) |
40 | |
{ |
41 | 0 | c = name.charAt (i); |
42 | 0 | if (Character.isUpperCase (c)) |
43 | |
{ |
44 | 0 | if ( ! lastUpper) |
45 | |
{ |
46 | 0 | buf.append ('_'); |
47 | |
} |
48 | 0 | lastUpper = true; |
49 | |
} |
50 | |
else |
51 | |
{ |
52 | 0 | lastUpper = false; |
53 | |
} |
54 | |
|
55 | 0 | buf.append (Character.toUpperCase (c)); |
56 | |
} |
57 | |
|
58 | 0 | return buf.toString (); |
59 | |
} |
60 | |
|
61 | |
public String reverse () |
62 | |
{ |
63 | 0 | StringBuffer buf = new StringBuffer (name.length ()); |
64 | 0 | boolean uppercase = true; |
65 | 0 | for (int i = 0; i < name.length (); i ++) |
66 | |
{ |
67 | 0 | char c = name.charAt (i); |
68 | 0 | if (uppercase) |
69 | |
{ |
70 | 0 | c = Character.toUpperCase (c); |
71 | 0 | uppercase = false; |
72 | |
} |
73 | |
else |
74 | |
{ |
75 | 0 | c = Character.toLowerCase (c); |
76 | |
} |
77 | 0 | if (c == '_') |
78 | |
{ |
79 | 0 | uppercase = true; |
80 | 0 | continue; |
81 | |
} |
82 | 0 | buf.append (c); |
83 | |
} |
84 | |
|
85 | 0 | return buf.toString (); |
86 | |
} |
87 | |
|
88 | |
} |