Boon
Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
Install / Use
/learn @boonproject/BoonREADME
Got a question? Ask here. Get help from the Boon community. https://groups.google.com/forum/#!forum/boonjava
__________ _____ __ .__
\______ \ ____ ____ ____ /\ / \ _____ | | _|__| ____ ____
| | _// _ \ / _ \ / \ \/ / \ / \\__ \ | |/ / |/ \ / ___\
| | ( <_> | <_> ) | \ /\ / Y \/ __ \| <| | | \/ /_/ >
|______ /\____/ \____/|___| / \/ \____|__ (____ /__|_ \__|___| /\___ /
\/ \/ \/ \/ \/ \//_____/
____. ___________ _____ ______________.___.
| |____ ___ _______ \_ _____/ / _ \ / _____/\__ | |
| \__ \\ \/ /\__ \ | __)_ / /_\ \ \_____ \ / | |
/\__| |/ __ \\ / / __ \_ | \/ | \/ \ \____ |
\________(____ /\_/ (____ / /_______ /\____|__ /_______ / / ______|
\/ \/ \/ \/ \/ \/
Status
Boon is now at version 0.26. There are a few more features to implement, and then Boon will be 1.0. This last push fixed a lot of long lived bugs. Boon now compiles (again) in JDK 1.8.
License
Apache 2
YourKit
YourKit supports Boon open source project with its full-featured Java Profiler. YourKit, LLC is the creator of innovative and intelligent tools for profiling Java and .NET applications. Take a look at YourKit's leading software products: YourKit Java Profiler and YourKit .Net profiler.


Philosophy
Use it as you wish. Give me some credit if you fork it or copy major portions of it. Use the lib or copy it into your code, tweak it. Blog about. Use it. Give me feedback. I am doing this for the street cred and to learn.
Do I like new task lists in MarkDown?
- [x] Yes
- [ ] No
- [ ] Maybe
Java Boon
Simple opinionated Java for the novice to expert level Java Programmer.
Low Ceremony. High Productivity.
Boon Home: http://richardhightower.github.io/site/Boon/Welcome.html
Boon is in maven central repo:
http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22io.fastjson%22%20AND%20a%3A%22boon%22
Brief introduction to Boon
Here are some basic Java types, list, array, veggies, primitive char array, and a primitive byte array.
//Boon works with lists, arrays, sets, maps, sorted maps, etc.
List<String> fruitList;
String [] fruitArray;
Set<String> veggiesSet;
char [] letters;
byte [] bytes;
NavigableMap <Integer, String> favoritesMap;
Map<String, Integer> map;
//In Java a TreeMap is a SortedMap and a NavigableMap by the way.
Boon comes with helper methods that allow you to easily create lists, sets, maps, concurrent maps, sorted maps, sorted sets, etc. The helper methods are safeList, list, set, sortedSet, safeSet, safeSortedSet, etc. The idea is to make Java feel more like list and maps are built in types.
veggiesSet = set( "salad", "broccoli", "spinach");
fruitList = list( "apple", "oranges", "pineapple");
fruitArray = array( "apple", "oranges", "pineapple");
letters = array( 'a', 'b', 'c');
bytes = array( new byte[]{0x1, 0x2, 0x3, 0x4});
There are even methods to create maps and sorted maps called map, sortedMap, safeMap (concurrent) and sortedSafeMap (concurrent). These were mainly created because Java does not have literals for lists, maps, etc.
favoritesMap = sortedMap(
2, "pineapple",
1, "oranges",
3, "apple"
);
map = map (
"pineapple", 2,
"oranges", 1,
"apple", 3
);
You can index maps, lists, arrays, etc. using the idx operator.
//Using idx to access a value.
assert idx( veggiesSet, "b").equals("broccoli");
assert idx( fruitList, 1 ).equals("oranges");
assert idx( fruitArray, 1 ).equals("oranges");
assert idx( letters, 1 ) == 'b';
assert idx( bytes, 1 ) == 0x2;
assert idx( favoritesMap, 2 ).equals("pineapple");
assert idx( map, "pineapple" ) == 2;
The idx operators works with negative indexes as well.
//Negative indexes
assert idx( fruitList, -2 ).equals("oranges");
assert idx( fruitArray, -2 ).equals("oranges");
assert idx( letters, -2 ) == 'b';
assert idx( bytes, -3 ) == 0x2;
Ruby, Groovy and Python have this feature. Now you can use this in Java as well. The Java version (Boon) works with primitive arrays (with no autoboxing).
Boon has the concept of universal operators similar to Python like len.
// Getting the length
assert len( veggiesSet ) == 3;
assert len( fruitList ) == 3;
assert len( fruitArray ) == 3;
assert len( letters ) == 3;
assert len( bytes ) == 4;
assert len( favoritesMap ) == 3;
assert len( map ) == 3;
Boon utility methods
Boon can read in an entire file in one line of code:
File testFile = new File(testDir, "testfile.txt");
List<String> lines = IO.readLines(testFile);
No really!
File testFile = new File(testDir, "testfile.txt");
List<String> lines = IO.readLines("~/github/boon/testfiles/testfile.txt");
There is also support for lambda expressions:
File testFile = new File(testDir, "testfile.txt");
IO.eachLine(testFile.toString(), (line, index) -> {
System.out.println(index + " " + line);
return true;
});
}
The readLines and read methods can read from URIs as well:
List<String> lines = IO.readLines("http://localhost:9666/test");
News in Boon
Boon 0.11 is out. Thanks Stephane Landelle! Boon JSON parser still faster than GSON and Jackson. Up to 3x faster.
See and fork: https://github.com/RichardHightower/json-parsers-benchmark
Added lightweight JSON DI container that supports @Inject, @PostConstruct, @Required, @Autowire, and more.
public class CoffeeApp implements Runnable {
@Inject
CoffeeMaker coffeeMaker;
@Inject
Coffee coffee;
@Inject
Sugar sugar;
@Inject
Bacon bacon;
@Inject
@Named( "brown" )
Bacon brownBacon;
JSON support now support @JsonProperty, @JsonView, and more. Learn more here: http://rick-hightower.blogspot.com/2014/01/boon-json-in-five-minutes-faster-json.html
Wrote invoker library to work JSON posts. It is a better way to do REST and WebSocket with Boon.
Wrote functional library based on work that I did with EasyJava.
You can do reflection based filters or regular Predicate filters.
List<Employee> list = list( new Employee("Bob"), new Employee("Sally") );
setListProperty( list, "salary", 200 );
list.addAll(Lists.list(new Employee("Rick"), new Employee("Joe")));
//Reflection
List<Employee> filtered = filterBy(list, new Object() {
boolean t(Employee e) { return e.salary>150; }
});
...
//Predicate based
List<Employee> filtered = filterBy(list, new Predicate<Employee>() {
@Override
public boolean test(Employee input) {
return input.salary > 150;
}
});
My goal is take some previous work that I did with invoke dynamic and make the reflection based predicate faster than the Predicate interface.
You can also filter with static or non-static methods
List<Employee> filtered = filterBy(list, ListsTest.class, "filterBySalary");
...
List<Employee> filtered = filterBy(list, this, "filterBySalaryMethod");
Also don't forget that Boon ships with a full in-memory query engine that is actually faster than the predicate based filters.
List<Employee> filtered = query( list, gt("salary", 150) );
Learn more about the Boon data repo here:
http://rick-hightower.blogspot.com/2013/11/what-if-java-collections-and-java.html
But I digress back to functional framework:
The usual suspects are here:
...
//Reflection Mapper -- Convert Employee object into HRObject
List<HRObject> wrap = (List<HRObject>) mapBy(list, new Object() {
HRObject hr(Employee e) {return new HRObject(e);}
});
...
//Reflection static or non-static methods
List<HRObject> wrap = (List<HRObject>) mapBy(list, ListsTest.class, "createHRO" );
List<HRObject> wrap = (List<HRObject>) mapBy(list, this, "createHROMethod" );
...
//Constructor mapping
List<Employee> list = list(new Employee("Bob"), new Employee("Sally"));
List<HRObject> wrap = wrap(HRObject.class, list);
...
//
List<Employee> list = list( new Employee("Bob"), new Employee("Sally"));
List<HRObject> wrap = mapBy( list, new Function<Employee, HRObject>() {
@Override
public HRObject apply(Employee employee) {
return new HRObject(employee);
}
});
Here is one you don't see much:
@Test
public void reduce() {
long sum = (int) reduceBy(Lists.list(1,2,3,4,5,6,7,8), new Object() {
int sum(int s, int b) {return s+b;}
});
boolean ok = sum == 36 || die();
puts (sum);
sum = (long) reduceBy(new Integer[]{1,2,3,4,5,6,7,8}, new Object() {
long sum(long s, int b)
