/* * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 4634390 * @summary Tests contract for equals and hashCode methods * @author Mark Davidson
*/
publicstaticvoid main(String[] args) { for (Class type : CLASSES) {
test(type);
}
}
privatestaticvoid test(Class type) { for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(type)) {
PropertyDescriptor pdCopy = create(pd); if (pdCopy != null) { // XXX - hack! The Introspector will set the bound property // since it assumes that propertyChange event set descriptors // infers that all the properties are bound
pdCopy.setBound(pd.isBound());
String name = pd.getName();
System.out.println(" - " + name);
if (!compare(pd, pdCopy)) thrownew Error("property delegates are not equal");
if (!pd.equals(pdCopy)) thrownew Error("equals() failed");
if (pd.hashCode() != pdCopy.hashCode()) thrownew Error("hashCode() failed");
}
}
}
privatestaticboolean compare(PropertyDescriptor pd1, PropertyDescriptor pd2) { if (!compare(pd1.getReadMethod(), pd2.getReadMethod())) {
System.out.println("read methods not equal"); returnfalse;
} if (!compare(pd1.getWriteMethod(), pd2.getWriteMethod())) {
System.out.println("write methods not equal"); returnfalse;
} if (pd1.getPropertyType() != pd2.getPropertyType()) {
System.out.println("property type not equal"); returnfalse;
} if (pd1.getPropertyEditorClass() != pd2.getPropertyEditorClass()) {
System.out.println("property editor class not equal"); returnfalse;
} if (pd1.isBound() != pd2.isBound()) {
System.out.println("bound value not equal"); returnfalse;
} if (pd1.isConstrained() != pd2.isConstrained()) {
System.out.println("constrained value not equal"); returnfalse;
} returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.