View Javadoc

1   package org.kuali.mobility.news.util;
2   
3   import org.apache.commons.collections.Predicate;
4   import org.kuali.mobility.news.entity.NewsSource;
5   
6   public class NewsSourcePredicate implements Predicate {
7   
8   	private Long parentId;
9   	private Boolean active;
10  	
11  	public NewsSourcePredicate( final Long parentId, final Boolean active )
12  	{
13  		this.setParentId(parentId);
14  		this.setActive(active);
15  	}
16  	
17  	@Override
18  	public boolean evaluate(Object obj) {
19  		boolean parentMatch = false;
20  		boolean activeMatch = false;
21  		
22  		if( null != obj
23  			&& obj instanceof NewsSource ) {
24  			if( getParentId() == null ) {
25  				parentMatch = true;
26  			} else if( ((NewsSource)obj).getParentId() == null ) {
27  				if( getParentId().intValue() == 0 ) {
28  					parentMatch = true;
29  				} else {
30  					parentMatch = false;
31  				}
32  			} else if( getParentId().compareTo( ((NewsSource)obj).getParentId() ) == 0 ) {
33  				parentMatch = true;
34  			}
35  			if( isActive() == null ) {
36  				activeMatch = true;
37  			} else if( isActive().booleanValue() == ((NewsSource)obj).isActive() ) {
38  				activeMatch = true;
39  			}
40  		}
41  		return parentMatch && activeMatch;
42  	}
43  
44  	public Long getParentId() {
45  		return parentId;
46  	}
47  
48  	public void setParentId(Long parentId) {
49  		this.parentId = parentId;
50  	}
51  
52  	public Boolean isActive() {
53  		return active;
54  	}
55  
56  	public void setActive(Boolean active) {
57  		this.active = active;
58  	}
59  
60  }