org.springmodules.validation.util.condition.bean.EqualPropertiesBeanCondition Maven / Gradle / Ivy
/* * Copyright 2004-2005 the original author or authors. * * 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 org.springmodules.validation.util.condition.bean; import org.springframework.beans.BeanWrapper; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** * An {@link AbstractBeanCondition} implementation that checks whether specific properties of the checked bean * have the same value. * * @author Uri Boness */ public class EqualPropertiesBeanCondition extends AbstractBeanCondition { private String[] propertyNames; /** * Constructs a new EqualPropertiesBeanCondition with a given list of names of the properties to be compared. * * @param propertyNames The name of the properties to be compared. * @throws IllegalArgumentException when the given property names array contains zero or one names. */ public EqualPropertiesBeanCondition(String[] propertyNames) { Assert.notNull(propertyNames, getClass().getName() + " cannot be initialized with null array of property names"); Assert.notEmpty(propertyNames, getClass().getName() + " cannot be initialized with less then 2 property names"); for (int i=0; i
if all the compared properties are equal,true false
otherwise. */ protected boolean checkBean(BeanWrapper bean) { Object value = bean.getPropertyValue(propertyNames[0]); for (int i=1; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy