This file contains 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
@Active(typeof(MemoizeProcessor)) | |
annotation Memoize { | |
} | |
class MemoizeProcessor implements TransformationParticipant<MutableMethodDeclaration> { | |
override doTransform(List<? extends MutableMethodDeclaration> methods, extension TransformationContext context) { | |
methods.forEach [ | |
switch (parameters.size) { | |
case 0: new ParamterlessMethodMemoizer(it, context, methods.indexOf(it)).generate | |
case 1: new SingleParameterMethodMemoizer(it, context, methods.indexOf(it)).generate |
This file contains 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
public class FibonacciBenchmarkJava extends SimpleBenchmark { | |
@Param | |
private int n; | |
public static List<Integer> nValues = ImmutableList.of(5, 10, 20 ); | |
public void timeMemoizedFibonacci(int iterations) { | |
for (int i = 0; i < iterations; i++) { | |
new Fibonaccis().memoizedFibonacci(n); |
This file contains 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
@Benchmark | |
class FibonacciBenchmarkXtend24 { | |
List<Integer> nValues = #[5, 10, 20] | |
def timeDumbFibonacci() { | |
for (i : 1 .. iterations) { | |
new Fibonaccis().dumbFibonacci(n) | |
} | |
} |
This file contains 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
@Active(typeof(BenchmarkProcessor)) | |
annotation Benchmark { | |
} | |
class BenchmarkProcessor extends AbstractClassProcessor { | |
override doTransform(MutableClassDeclaration cls, TransformationContext context) { | |
new BenchmarkClassGenerator(context, cls).generate | |
} | |
} |
This file contains 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
class ExtractInterfaceProcessor extends AbstractClassProcessor { | |
override doRegisterGlobals(ClassDeclaration cls, RegisterGlobalsContext context) { | |
context.registerInterface(cls.qualifiedInterfaceName) | |
} | |
override doTransform(MutableClassDeclaration cls, extension TransformationContext context) { | |
findInterface(cls.qualifiedInterfaceName) => [ iface | | |
cls.declaredMethods.filter [ | |
visibility == Visibility::PUBLIC |
This file contains 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
class ImmutableProcessor extends AbstractClassProcessor { | |
override doRegisterGlobals(ClassDeclaration cls, RegisterGlobalsContext context) { | |
context.registerClass(cls.builderClassName) | |
} | |
override doTransform(MutableClassDeclaration cls, extension TransformationContext context) { | |
if(cls.extendedClass != object) cls.addError("Inheritance does not play well with immutability") | |
cls.final = true |
This file contains 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
@Immutable | |
class Address { | |
String street; | |
String city; | |
String zip; | |
String postOfficeBox | |
} | |
class AddressTest { | |
val address = Address::build[ |
This file contains 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
@CreateWith(typeof(GuiceSpecCreator)) | |
@InjectWith(typeof(EnglishModule)) | |
describe Greeter "Interface Injection"{ | |
@Inject | |
Greeter injected | |
fact "the subject is injected by Guice"{ | |
subject.greet should be "Hello" | |
} |
This file contains 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
QPerson p = QPerson.person; | |
List<Person> persons = db.from(p) | |
.where( | |
(p.firstName.loe("C").or(p.lastName.goe("T"))) | |
.and(p.age.gt(18)) | |
.and(p.gender.eq(Gender.FEMALE)) | |
) | |
.orderBy(p.firstName.asc()) | |
.list(p); |
This file contains 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
val p = QPerson.person | |
val persons = db.from(p) | |
.where( | |
(p.firstName <= "C" || p.lastName >= "T") | |
&& p.age > 18 | |
&& p.gender == Gender.FEMALE | |
) | |
.orderBy(p.firstName.asc) | |
.list(p) |