JBEL - Java Boolean Expression Library Project summary on Source Forge.
Download from Source Forge

JBEL is a small, efficient Java library enabling programmers to create simple, easily understandable expressions to perform collection filtering and/or sorting.  The following benefits are realized through consistent use of JBEL:
  • No more cut-n-paste coding for comparing and filtering.
  • Reduce duplicated code and code size.
  • Improve filter and sort clarity and readability.
  • Increase application reliability by reducing bug introduction.
The following examples should get you going on your understanding and justification for use of JBEL.  After a look, the benefits are obvious, especially when considering the amount of cut-n-paste coding that often happens around comparing and filtering.

Filtering

Before JBEL:

After JBEL:

private Collection filterCollection(Collection toFilter)
{ Collection results = new Vector(); Iterator iterator = toFilter.iterator(); while (iterator.hasNext()) { (SomeInstance) instance = (SomeInstance) iterator.next(); if (instance.getAccountBalance() > 10000 && instance.isNewCustomer()) { results.add(instance); } } return results; } Collection results = filterCollection(toFilter);
SelectExpressionBuilder builder = new SelectExpressionBuilder();
builder.attribute("accountBalance").greaterThan(10000)
  .and(builder.attribute("isNewCustomer").equalTo(true));

Collection results = Expressions.select(toFilter, builder.getExpression());
		  

Sorting

Before JBEL:

After JBEL:

public class PersonNameComparator
implements Comparator
{
  public int compare(Object obj1, Object obj2)
  {
    Person person1 = (Person) obj1;
    Person person2 = (Person) obj2;
    int result = person1.getLastName()
      .compareTo(person2.getLastName());

    if (result == 0)
    {
      result = person1.getFirstName()
        .compareTo(person2.getFirstName());
    }

    if (result == 0)
    {
      result = person1.getMiddleInitial()
        .compareTo(person2.getMiddleInitial());
    }

    return result;
  }
}

Collections.sort(peopleToSort, new PersonNameComparator());
OrderByExpressionBuilder
orderBy = new OrderByExpressionBuilder();
orderBy.attribute("lastName")
  .attribute("firstName")
  .attribute("middleInitial");

Collections.sort(peopleToSort, orderBy.getExpression());