-
Notifications
You must be signed in to change notification settings - Fork 56
Experience the Athenizer and Spartanizer
Yuval Simon edited this page Jun 16, 2017
·
1 revision
In order to experience the usage of the Athenizer and the Spartanizer this wiki provides a compiling example code, and new users can copy it and try athenize/spartanize themselves.
The original code:
public class Example {
public static void main(String[] args) {
Fluent f = new Fluent().self().setX(Integer.valueOf(fibonacci(5)));
}
static int fibonacci(int n) {
return n == 1 || n == 2 ? 1 : (n <= 0 ? -1 : fibonacci(n-1) + fibonacci(n-2));
}
static And benEl(int n) {
if(n == 1)
return And.of(5);
return n > 8 ? And.of(fibonacci(n)) :
n < 6 ? And.of(n) : And.of(fibonacci(n-1)) ;
}
static int complex(Integer n) {
if(n == null)
return 0;
if(n == 1)
return 5;
if(n == 2)
return 6;
if(n == 3)
return 7;
return n;
}
}
class And {
int x;
And(int n) {
x = n;
}
static And of(int n) {
return new And(n);
}
}
class Fluent {
int x;
Fluent self() {
return this;
}
Fluent setX(int n) {
x = n;
return this;
}
int getX() {
return x;
}
}
Try to athenize and spartanize it in your environment.
For example the method "main" would be athenized to:
public static void main(String[] args) {
Fluent f;
Fluent f1;
Fluent f2;
f2 = new Fluent();
f1 = f2.self();
Integer i1;
int i2;
i2 = fibonacci(5);
i1 = Integer.valueOf(i2);
f = f1.setX(i1);
}
The method "complex" would be spartanized to:
static int complex(Integer ¢) {
return ¢ == null ? 0 : ¢ == 1 ? 5 : ¢ == 2 ? 6 : ¢ == 3 ? 7 : ¢;
}