From 6a4a4e2ce623d30cddf034bb0f811ff34c5ba125 Mon Sep 17 00:00:00 2001 From: ribeaudc <ribeaudc> Date: Fri, 11 Jan 2008 09:29:13 +0000 Subject: [PATCH] fix: - Removing dependencies: move 'AbstractHashable' to 'common' project. SVN: 3448 --- .../common/utilities/AbstractHashable.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 common/source/java/ch/systemsx/cisd/common/utilities/AbstractHashable.java diff --git a/common/source/java/ch/systemsx/cisd/common/utilities/AbstractHashable.java b/common/source/java/ch/systemsx/cisd/common/utilities/AbstractHashable.java new file mode 100644 index 00000000000..15dc6ab3683 --- /dev/null +++ b/common/source/java/ch/systemsx/cisd/common/utilities/AbstractHashable.java @@ -0,0 +1,60 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * 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 ch.systemsx.cisd.common.utilities; + +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + + +/** + * If you want your class to behave correctly when used in {@link Map}s or {@link Set}s, you can do this by: + * <ol> + * <li>Extending this class</li> + * <li>Ensuring that all used field types implement <code>equals()</code> and <code>hashCode()</code> (e.g. by + * extending this class)</li> + * </ol> + * + * @author Tomasz Pylak on Oct 26, 2007 + */ +public abstract class AbstractHashable +{ + // + // Object + // + + @Override + public final boolean equals(final Object obj) + { + return EqualsBuilder.reflectionEquals(this, obj); + } + + @Override + public final int hashCode() + { + return HashCodeBuilder.reflectionHashCode(this); + } + + @Override + public final String toString() + { + return ToStringBuilder.reflectionToString(this, ModifiedShortPrefixToStringStyle.MODIFIED_SHORT_PREFIX_STYLE); + } +} -- GitLab