com.discovery.darchrow.util.predicate.ArrayContainsPredicate.java Source code

Java tutorial

Introduction

Here is the source code for com.discovery.darchrow.util.predicate.ArrayContainsPredicate.java

Source

/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.discovery.darchrow.util.predicate;

import org.apache.commons.collections.Predicate;

import com.discovery.darchrow.bean.PropertyUtil;
import com.discovery.darchrow.lang.ArrayUtil;

/**
 *  {@link PropertyUtil#getProperty(Object, String)}  <code>propertyName</code>? {@link ArrayUtil#isContain(Object[], Object)} 
 * <code>values</code>.
 *
 * @author feilong
 * @version 1.2.0 2015427 ?3:12:32
 * @since 1.2.0
 * @see com.baozun.nebulaplus.bean.PropertyUtil#getProperty(Object, String)
 * @see com.baozun.nebulaplus.lang.ArrayUtil#isContain(Object[], Object)
 */
public class ArrayContainsPredicate implements Predicate {

    /** The value. */
    private final Object[] values;

    /** The property name. */
    private final String propertyName;

    /**
     * The Constructor.
     *
     * @param propertyName
     *            the property name
     * @param values
     *            the values
     */
    public ArrayContainsPredicate(String propertyName, Object... values) {
        this.values = values;
        this.propertyName = propertyName;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
     */
    @Override
    public boolean evaluate(Object object) {
        Object property = PropertyUtil.getProperty(object, propertyName);
        return ArrayUtil.isContain(values, property);
    }
}