Posts

Showing posts from September, 2011

Developer Notes: Apache Commons FilterIterator

Image
Filtering the collection based on the criteria is a great advantage of FilterIterator. package com.blogspot.ojitha.commonexamples; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.commons.collections.Predicate; import org.apache.commons.collections.iterators.FilterIterator; public class ListFilteringExample { /** * @param args */ public static void main(String[] args) { Person a = new Person("Smith", "Wills"); a.setAge(39); Person b = new Person("Kris", "Torano"); b.setAge(15); Person c = new Person("Mark","Anthony"); c.setAge(25); Person d = new Person("Mad", "Max"); d.setAge(19); List<Person> persons = new ArrayList<Person>(); persons.add(a); persons.add(b); persons.add(c); persons.add(d); Predicate predicate = new AdultFilter(18); Iterator<Person> adults = new FilterIterator(persons.iterator()

Apache Commons Collections: Object equality using Predicate

The method equals() is the way to check the object equality in Java. You need to override equals() and hashCode() method to makes objects equals. However, in this blog, instead of obj1.equals(obj2) method, I am going to use more powerful Predicate from the Apache commons collection. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.blogspot.ojitha.commonexamples</groupId> <artifactId>Apache-common-example</artifactId> <version>1.0</version> <packaging>jar</packaging> <name>Apache-common-example</name> <url>http://ojitha.blogspot.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties&g

Developer Notes: Spring Web Workflow 1.0.6 Maven 2 environment for development

Version 1.0.9 is very old version. However, almost all the examples found in the google search is based on Ant and IVY configuration. Therefore, I thought this blog will be beneficial to the people who are still in Ant configuration.  Time to move to Maven. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ojitha.swffirst</groupId> <artifactId>swf-first</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>swf-first Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version>