Exjali : Features

This page contains most of Exjali's features with sample codes.


Range of integers

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 :

Lopping on a range of integers :

for (int i : range(1, 23)) {
    // Do something
}

Testing if an integer is in a range :

if (range(2, 45).contains(myInt)) {
    // Do something
}


SQL's in and not in functions

Exjali provides a way to use statements similar to this functions :

in (request(line).in(line1, line2)) {
    // Do something
}


Expressive I/O

Exjali provides a few classes to make file parsing more expressive.

Iterate over the lines of a text file :

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
}

Iterates over serialized objects

In the same spirit ObjectFileReader allow you to iterate over serialized objects :

for(User user : objects("users.obj")) {
    // Do something
}


Functors (closures)

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 :

  1. You can define a simple interface, and build an inner class implementing that interface when using a method that use this interface.
  2. You can use reflexion, but loose compiler's checking.

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"));


Collections shortcuts

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

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
}