Created
May 3, 2016 16:54
-
-
Save ewized/02160425739dddd4d297ab094c649e89 to your computer and use it in GitHub Desktop.
Before and After - Shows how R/D code becomes clean Production code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AFTER | |
public static Class<?>[] after(String str) throws Exception { | |
Conditions.nonNull(str, "str"); | |
str = str.substring(1, str.lastIndexOf(")")); | |
List<Class<?>> args = Lists.newArrayList(); | |
for (int i = 0 ; i < str.length(); i++) { | |
int a = i; | |
if (str.charAt(i) == '[') { // Process arrays | |
while (str.charAt(a) == '[' && i < str.length()) { | |
a++; | |
} | |
} | |
if (str.charAt(a) == 'L') { // Grab the class from the Object type | |
int b = str.indexOf(";", a + 1); | |
args.add(toClass(str.substring(i, b + 1))); | |
i = b; | |
} else { // Handle the primitives | |
args.add(toClass(str.substring(i, a + 1))); | |
i = a; | |
} | |
} | |
return args.toArray(new Class[args.size()]); | |
} | |
// BEFORE | |
public static Class<?>[] before(String str) throws Exception { | |
str = str.substring(1, str.lastIndexOf(")")); | |
List<Class<?>> args = Lists.newArrayList(); | |
for (int i = 0 ; i < str.length(); i++) { | |
if (str.charAt(i) == '[') { | |
int a = i; | |
while (str.charAt(a) == '[' && i < str.length()) { | |
a++; | |
} | |
//System.out.println(str.charAt(a)); | |
if (str.charAt(a) == 'L') { | |
int b = a + 1; | |
while (str.charAt(b) != ';' && i < str.length()) { | |
b++; | |
} | |
//System.out.println(str.substring(i, b)); | |
args.add(toClass(str.substring(i, b + 1))); | |
i = b; | |
} else { | |
args.add(toClass(str.substring(i, a + 1))); | |
i = a; | |
} | |
} else { | |
if (str.charAt(i) == 'L') { | |
int b = i + 1; | |
while (str.charAt(b) != ';' && i < str.length()) { | |
b++; | |
} | |
//System.out.println(str.substring(i, b)); | |
args.add(toClass(str.substring(i, b + 1))); | |
i = b; | |
} | |
else if (Character.isUpperCase(str.charAt(i)) && TYPES[id(str.charAt(i))] != null) { | |
args.add(toClass(String.valueOf(str.charAt(i)))); | |
} | |
} | |
} | |
return args.toArray(new Class[args.size()]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment