Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kdstudio.snippets.tips.apache;
- import org.apache.commons.lang3.builder.EqualsBuilder;
- import org.apache.commons.lang3.builder.HashCodeBuilder;
- import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
- import org.apache.commons.lang3.builder.ToStringStyle;
- /**
- * Example of using Commons-lang3 utilities.
- *
- * Lang provides a host of helper utilities for the java.lang API, notably
- * String manipulation methods, basic numerical methods, object reflection,
- * concurrency, creation and serialization and System properties. Additionally
- * it contains basic enhancements to java.util.Date and a series of utilities
- * dedicated to help with building methods, such as hashCode, toString and
- * equals.
- *
- * @author kdelfour
- */
- public class HashCodeEqualsToStringExample {
- /**
- * Constructor
- */
- public HashCodeEqualsToStringExample() {
- }
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return ReflectionToStringBuilder.toString(this,
- ToStringStyle.MULTI_LINE_STYLE);
- }
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this);
- }
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement