com.squeakysand.commons.valueobjects.AbstractValueObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of squeakysand-commons Show documentation
Show all versions of squeakysand-commons Show documentation
Classes, interfaces and enums that assist with everyday Java development tasks.
The newest version!
/*
* Copyright 2010-2012 Craig S. Dickson (http://craigsdickson.com)
*
* 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.squeakysand.commons.valueobjects;
import com.squeakysand.commons.lang.CompareToHelper;
import com.squeakysand.commons.lang.EqualsHelper;
import com.squeakysand.commons.lang.HashCodeHelper;
import com.squeakysand.commons.lang.ToStringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Abstract implementation of the {@link ValueObject} interface, providing implementations of many methods.
*/
public abstract class AbstractValueObject implements ValueObject {
private static final long serialVersionUID = -1146115384085055275L;
private static final Logger LOG = LoggerFactory.getLogger(AbstractValueObject.class);
/**
* Provided to comply with requirements of the {@link java.lang.Serializable} interface - should not be used outside of the serialization process.
*/
public AbstractValueObject() {
}
/**
* {@inheritDoc}.
*/
@Override
public Object clone() {
Object result = null;
try {
result = super.clone();
} catch (CloneNotSupportedException e) {
LOG.error("Object.clone() threw an unexpected exception", e);
}
return result;
}
@Override
public int compareTo(ValueObject vo) {
return CompareToHelper.compareTo(this, vo);
}
/**
* {@inheritDoc}.
*
*
* This is a naive implementation of the equals contract where this VO and the passed in argument are treated as JavaBeans and their exposed properties are
* just compared for equality. You should override this method in subclasses if performance becomes an issue.
*
*
* @see EqualsHelper#equalsAsJavaBean(java.lang.Object, java.lang.Object)
*/
@Override
public boolean equals(Object o) {
return EqualsHelper.equalsAsJavaBean(this, o);
}
/**
* {@inheritDoc}.
*
* @see HashCodeHelper#hashAsJavaBean(Object)
*/
@Override
public int hashCode() {
return HashCodeHelper.hashAsJavaBean(this);
}
/**
* {@inheritDoc}.
*
* @see ToStringHelper#toString(Object)
*/
@Override
public String toString() {
return ToStringHelper.toString(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy