Apache Commons
toString
public String toString() { return new ToStringBuilder(this,ToStringStyle.SHORT_PREFIX_STYLE). append("offeringPrice", offeringPrice). append("productOffering", productOffering). toString(); }
Filtering collections
You can use predicates. It is like having where clause in a collection.
CollectionUtils.filter(list, PredicateUtils.instanceofPredicate(SomeClass.class)); CollectionUtils.filter(list, new MyOwnPredicate()); CollectionUtils.filter(theList, new Predicate(){ public boolean evaluate(Object object) {//If the predicate returns false, remove the element. XX product = (XX)object; if(...) return true; else return false; } });
Also you can use CollectionUtils.select where we can select all elements from input collection which match the given predicate into an output collection.
Closure
Executes the given closure on each element in the collection.
CollectionUtils.forAllDo(a_list, new MyClosureClass(passing_params));
Exist
Answers true if a predicate is true for at least one element of a collection.
boolean exist = CollectionUtils.exists(list, new Predicate(){//true if predicate is true
public boolean evaluate(Object object) {
XX product = (XX)object;
if(...) return true;
else return false;
}
});
References
page_revision: 11, last_edited: 1256011671|%e %b %Y, %H:%M %Z (%O ago)





