This page contains most of Exjali's features with sample codes.
Exjali provides a method that builds an immutable collection from a range of integer, giving you the ability to loop over that range with a foreach loop and test if a given integer is within the range :
for (int i : range(1, 23)) {
// Do something
}
if (range(2, 45).contains(myInt)) {
// Do something
}
Exjali provides a way to use statements similar to this functions :
in (request(line).in(line1, line2)) {
// Do something
}
Exjali provides a few classes to make file parsing more expressive.
Exjali provides a TextFileReader class that allow you to iterate over the lines of a text file :
for (String line : lines("test.txt")) {
// Do something
}
In the same spirit ObjectFileReader allow you to iterate over serialized objects :
for(User user : objects("users.obj")) {
// Do something
}
Closures in java have been, and are still discussed a lot. For the time being, there's two ways to "pass" functions to a method :
I don't see any way to simplify the first method without altering the language (although I think it's most of the time a better choice), but I can provide a mini internal DSL to simplify the second. so Exjali provides a Functor class that allow reflexive method calling :
// Method declaration, using a functor as parameter
methodUsingPseudoClosure(Functor functor) {
functor.run();
}
// Using that method
methodUsingPseudoClosure(call("setName").on(new Person()).with("Jackson"));
Exjali provides shortcuts for building collections, immutable collections (including maps) and arrays from a small number of objects :
Map<String, Integer> map = roMap(
entry("one", 1),
entry("two", 2)
);
Named parameters are parameters that can be labelled while calling the method. There is absolutly no way to do this in Java. In groovy the syntaxic sugar for map building allow programmers to write code that looks similar to named parameters.
In the same spirit, Exjali provides a parameter object and factory methods that allow client code to use "named parameters" :
// Example of such call
method(params(param("name", "michael"), param("age", 21)));
}
The compiler can't check the number and types of these parameters, so a method is provided in the parameter object to do this checking.
Declaration of the method :
// Method declaration
void method(NamedParameters params) {
// The client code should verify the parameters
params.verify(paramVerify("name", String.class), paramVerify("age", Integer.class));
// Parameters retrieval
String name = params.get("name", String.class);
Integer age = params.get("age", Integer.class);
// actual code
}