Package org.beangle.commons.collection.predicates

Source Code of org.beangle.commons.collection.predicates.PropertyEqualPredicate

/* Copyright c 2005-2012.
* Licensed under GNU  LESSER General Public License, Version 3.
* http://www.gnu.org/licenses
*/
package org.beangle.commons.collection.predicates;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.UnhandledException;
import org.apache.commons.lang.Validate;

/**
* Property Equals Predicate
*
* @author chaostone
*/
public class PropertyEqualPredicate {
  private String propertyName;
  private Object propertyValue;

  public PropertyEqualPredicate(String propertyName, Object propertyValue) {
    Validate.notEmpty(propertyName, "propertyName");
    this.propertyName = propertyName;
    this.propertyValue = propertyValue;
  }

  public boolean evaluate(Object arg0) {
    try {
      return ObjectUtils.equals(PropertyUtils.getProperty(arg0, propertyName), propertyValue);
    } catch (Exception e) {
      throw new UnhandledException(e);
    }
  }

}
TOP

Related Classes of org.beangle.commons.collection.predicates.PropertyEqualPredicate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.