S
shinya
Hi folks!
I wrote a little library, just as an exercise to grasp techniques
around DSLs and fluent interfaces, that provides a fluent layer upon
java.util.List and java.lang.String(and StringBuilder).
The project can be reached here: http://code.google.com/p/jfluent/
Here's an example of what you can do with the library, in pure Java:
import static com.jfluent.builders.BuilderFacade.*;
import com.jfluent.base.*;
public class FluentSimpleTest {
public static void main(String[] args) {
string("o hai!")
.append(" ")
.append(
list("i", "can", "has", "cheezburger", "plz", "?")
.map(new Function<String, String>() {
public String apply(String element) {
return element + " ";
}
})
.get())
.append("\n")
.append(
list(range('A', 'Z'))
.reverse()
.filter(new Predicate<Character>() {
public boolean apply(Character c) {
return c > 'M';
}
})
.join(","))
.println(System.out);
}
}
Output:
o hai! i can has cheezburger plz ?
Z,Y,X,W,V,U,T,S,R,Q,P,O,N
I don't know if it's a dream or a nightmare for you but i'd like to
hear any kind of opinions, critics, possible improvements, etc...
The library is in ALPHA stage, it lacks lots of documentation, but
your IDE should be enough since intellisense should guide you through.
Most methods are just wrapped on the java's ones.
Thanks for listening!
I wrote a little library, just as an exercise to grasp techniques
around DSLs and fluent interfaces, that provides a fluent layer upon
java.util.List and java.lang.String(and StringBuilder).
The project can be reached here: http://code.google.com/p/jfluent/
Here's an example of what you can do with the library, in pure Java:
import static com.jfluent.builders.BuilderFacade.*;
import com.jfluent.base.*;
public class FluentSimpleTest {
public static void main(String[] args) {
string("o hai!")
.append(" ")
.append(
list("i", "can", "has", "cheezburger", "plz", "?")
.map(new Function<String, String>() {
public String apply(String element) {
return element + " ";
}
})
.get())
.append("\n")
.append(
list(range('A', 'Z'))
.reverse()
.filter(new Predicate<Character>() {
public boolean apply(Character c) {
return c > 'M';
}
})
.join(","))
.println(System.out);
}
}
Output:
o hai! i can has cheezburger plz ?
Z,Y,X,W,V,U,T,S,R,Q,P,O,N
I don't know if it's a dream or a nightmare for you but i'd like to
hear any kind of opinions, critics, possible improvements, etc...
The library is in ALPHA stage, it lacks lots of documentation, but
your IDE should be enough since intellisense should guide you through.
Most methods are just wrapped on the java's ones.
Thanks for listening!