From ea47f03c4d6fba945be43d5c676075ba98b28138 Mon Sep 17 00:00:00 2001
From: Duncan Jones
Date: Fri, 24 Jan 2014 22:37:50 +0000
Subject: [PATCH] LANG-637: There should be a DifferenceBuilder with a
ReflectionDifferenceBuilder implementation
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1561215 13f79535-47bb-0310-9956-ffa450edef68
---
src/changes/changes.xml | 1 +
.../apache/commons/lang3/builder/Diff.java | 119 +++
.../commons/lang3/builder/DiffBuilder.java | 914 ++++++++++++++++++
.../commons/lang3/builder/DiffList.java | 208 ++++
.../commons/lang3/builder/Diffable.java | 54 ++
.../lang3/builder/DiffBuilderTest.java | 415 ++++++++
.../commons/lang3/builder/DiffListTest.java | 149 +++
.../commons/lang3/builder/DiffTest.java | 72 ++
8 files changed, 1932 insertions(+)
create mode 100644 src/main/java/org/apache/commons/lang3/builder/Diff.java
create mode 100644 src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
create mode 100644 src/main/java/org/apache/commons/lang3/builder/DiffList.java
create mode 100644 src/main/java/org/apache/commons/lang3/builder/Diffable.java
create mode 100644 src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
create mode 100644 src/test/java/org/apache/commons/lang3/builder/DiffListTest.java
create mode 100644 src/test/java/org/apache/commons/lang3/builder/DiffTest.java
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5803e5a5a..6c6e00907 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,7 @@
+ There should be a DifferenceBuilder with a ReflectionDifferenceBuilder implementationuncaught PatternSyntaxException in FastDateFormat on AndroidImprove JavaDoc of WordUtils.wrap methodsAdd the Jaro-Winkler string distance algorithm to StringUtils
diff --git a/src/main/java/org/apache/commons/lang3/builder/Diff.java b/src/main/java/org/apache/commons/lang3/builder/Diff.java
new file mode 100644
index 000000000..6aa0fa360
--- /dev/null
+++ b/src/main/java/org/apache/commons/lang3/builder/Diff.java
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.lang3.builder;
+
+import java.lang.reflect.Type;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.reflect.TypeUtils;
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ *
+ * A {@code Diff} contains the differences between two {@link Diffable} class
+ * fields.
+ *
+ *
+ *
+ * Typically, {@code Diff}s are retrieved by using a {@link DiffBuilder} to
+ * produce a {@link DiffList}, containing the differences between two objects.
+ *
+ *
+ *
+ * @param
+ * The type of object contained within this {@code Diff}. Differences
+ * between primitive objects are stored as their Object wrapper
+ * equivalent.
+ * @since 3.3
+ * @version $Id$
+ */
+public abstract class Diff extends Pair {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Type type;
+ private final String fieldName;
+
+ /**
+ *
+ * Constructs a new {@code Diff} for the given field name.
+ *
+ *
+ * @param fieldName
+ * the name of the field
+ */
+ protected Diff(String fieldName) {
+ this.type = ObjectUtils.defaultIfNull(
+ TypeUtils.getTypeArguments(getClass(), Diff.class).get(
+ Diff.class.getTypeParameters()[0]), Object.class);
+ this.fieldName = fieldName;
+ }
+
+ /**
+ *
+ * Returns the type of the field.
+ *
+ *
+ * @return the field type
+ */
+ public final Type getType() {
+ return type;
+ }
+
+ /**
+ *
+ * Returns the name of the field.
+ *
+ *
+ * @return the field name
+ */
+ public final String getFieldName() {
+ return fieldName;
+ }
+
+ /**
+ *
+ * Returns a {@code String} representation of the {@code Diff}, with the
+ * following format:
+ *
+ *
+ *
+ * @param value
+ * ignored
+ * @return nothing
+ */
+ @Override
+ public final T setValue(T value) {
+ throw new UnsupportedOperationException("Cannot alter Diff object.");
+ }
+}
diff --git a/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java b/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
new file mode 100644
index 000000000..8c54777b6
--- /dev/null
+++ b/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
@@ -0,0 +1,914 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.lang3.builder;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+/**
+ *
+ * Assists in implementing {@link Diffable#diff(Object)} methods.
+ *
+ *
+ *
+ * To use this class, write code as follows:
+ *
+ *
+ *
+ * public class Person implements Diffable<Person> {
+ * String name;
+ * int age;
+ * boolean smoker;
+ *
+ * ...
+ *
+ * public DiffList diff(Person obj) {
+ * // No need for null check, as NullPointerException correct if obj is null
+ * return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
+ * .append("name", this.name, obj.name)
+ * .append("age", this.age, obj.age)
+ * .append("smoker", this.smoker, obj.smoker)
+ * .build();
+ * }
+ * }
+ *
+ *
+ *
+ * The {@code ToStringStyle} passed to the constructor is embedded in the
+ * returned {@code DiffList} and influences the style of the
+ * {@code DiffList.toString()} method. This style choice can be overridden by
+ * calling {@link DiffList#toString(ToStringStyle)}.
+ *
+ * Constructs a builder for the specified objects with the specified style.
+ *
+ *
+ *
+ * If {@code lhs == rhs} or {@code lhs.equals(rhs)} then the builder will
+ * not evaluate any calls to {@code append(...)} and will return an empty
+ * {@link DiffList} when {@link #build()} is executed.
+ *
+ *
+ * @param lhs
+ * {@code this} object
+ * @param rhs
+ * the object to diff against
+ * @param style
+ * the style will use when outputting the objects, {@code null}
+ * uses the default
+ * @throws IllegalArgumentException
+ * if {@code lhs} or {@code rhs} is {@code null}
+ */
+ public DiffBuilder(final Object lhs, final Object rhs,
+ final ToStringStyle style) {
+ if (lhs == null) {
+ throw new IllegalArgumentException("lhs cannot be null");
+ }
+ if (rhs == null) {
+ throw new IllegalArgumentException("rhs cannot be null");
+ }
+
+ this.diffs = new ArrayList>();
+ this.lhs = lhs;
+ this.rhs = rhs;
+ this.style = style;
+
+ // Don't compare any fields if objects equal
+ this.objectsTriviallyEqual = (lhs == rhs || lhs.equals(rhs));
+ }
+
+ /**
+ *
+ * Test if two {@code boolean}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code boolean}
+ * @param rhs
+ * the right hand {@code boolean}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final boolean lhs,
+ final boolean rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (lhs != rhs) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Boolean getLeft() {
+ return Boolean.valueOf(lhs);
+ }
+
+ @Override
+ public Boolean getRight() {
+ return Boolean.valueOf(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code boolean[]}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code boolean[]}
+ * @param rhs
+ * the right hand {@code boolean[]}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final boolean[] lhs,
+ final boolean[] rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (!Arrays.equals(lhs, rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Boolean[] getLeft() {
+ return ArrayUtils.toObject(lhs);
+ }
+
+ @Override
+ public Boolean[] getRight() {
+ return ArrayUtils.toObject(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code byte}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code byte}
+ * @param rhs
+ * the right hand {@code byte}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final byte lhs,
+ final byte rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (lhs != rhs) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Byte getLeft() {
+ return Byte.valueOf(lhs);
+ }
+
+ @Override
+ public Byte getRight() {
+ return Byte.valueOf(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code byte[]}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code byte[]}
+ * @param rhs
+ * the right hand {@code byte[]}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final byte[] lhs,
+ final byte[] rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (!Arrays.equals(lhs, rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Byte[] getLeft() {
+ return ArrayUtils.toObject(lhs);
+ }
+
+ @Override
+ public Byte[] getRight() {
+ return ArrayUtils.toObject(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code char}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code char}
+ * @param rhs
+ * the right hand {@code char}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final char lhs,
+ final char rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (lhs != rhs) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Character getLeft() {
+ return Character.valueOf(lhs);
+ }
+
+ @Override
+ public Character getRight() {
+ return Character.valueOf(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code char[]}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code char[]}
+ * @param rhs
+ * the right hand {@code char[]}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final char[] lhs,
+ final char[] rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (!Arrays.equals(lhs, rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Character[] getLeft() {
+ return ArrayUtils.toObject(lhs);
+ }
+
+ @Override
+ public Character[] getRight() {
+ return ArrayUtils.toObject(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code double}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code double}
+ * @param rhs
+ * the right hand {@code double}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final double lhs,
+ final double rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (Double.doubleToLongBits(lhs) != Double.doubleToLongBits(rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Double getLeft() {
+ return Double.valueOf(lhs);
+ }
+
+ @Override
+ public Double getRight() {
+ return Double.valueOf(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code double[]}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code double[]}
+ * @param rhs
+ * the right hand {@code double[]}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final double[] lhs,
+ final double[] rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (!Arrays.equals(lhs, rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Double[] getLeft() {
+ return ArrayUtils.toObject(lhs);
+ }
+
+ @Override
+ public Double[] getRight() {
+ return ArrayUtils.toObject(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code float}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code float}
+ * @param rhs
+ * the right hand {@code float}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final float lhs,
+ final float rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (Float.floatToIntBits(lhs) != Float.floatToIntBits(rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Float getLeft() {
+ return Float.valueOf(lhs);
+ }
+
+ @Override
+ public Float getRight() {
+ return Float.valueOf(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code float[]}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code float[]}
+ * @param rhs
+ * the right hand {@code float[]}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final float[] lhs,
+ final float[] rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (!Arrays.equals(lhs, rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Float[] getLeft() {
+ return ArrayUtils.toObject(lhs);
+ }
+
+ @Override
+ public Float[] getRight() {
+ return ArrayUtils.toObject(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code int}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code int}
+ * @param rhs
+ * the right hand {@code int}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final int lhs,
+ final int rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (lhs != rhs) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Integer getLeft() {
+ return Integer.valueOf(lhs);
+ }
+
+ @Override
+ public Integer getRight() {
+ return Integer.valueOf(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code int[]}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code int[]}
+ * @param rhs
+ * the right hand {@code int[]}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final int[] lhs,
+ final int[] rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (!Arrays.equals(lhs, rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Integer[] getLeft() {
+ return ArrayUtils.toObject(lhs);
+ }
+
+ @Override
+ public Integer[] getRight() {
+ return ArrayUtils.toObject(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code long}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code long}
+ * @param rhs
+ * the right hand {@code long}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final long lhs,
+ final long rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (lhs != rhs) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Long getLeft() {
+ return Long.valueOf(lhs);
+ }
+
+ @Override
+ public Long getRight() {
+ return Long.valueOf(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code long[]}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code long[]}
+ * @param rhs
+ * the right hand {@code long[]}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final long[] lhs,
+ final long[] rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (!Arrays.equals(lhs, rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Long[] getLeft() {
+ return ArrayUtils.toObject(lhs);
+ }
+
+ @Override
+ public Long[] getRight() {
+ return ArrayUtils.toObject(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code short}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code short}
+ * @param rhs
+ * the right hand {@code short}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final short lhs,
+ final short rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (lhs != rhs) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Short getLeft() {
+ return Short.valueOf(lhs);
+ }
+
+ @Override
+ public Short getRight() {
+ return Short.valueOf(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code short[]}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code short[]}
+ * @param rhs
+ * the right hand {@code short[]}
+ * @return this
+ * @throws IllegalArgumentException
+ * if field name is {@code null}
+ */
+ public DiffBuilder append(final String fieldName, final short[] lhs,
+ final short[] rhs) {
+ if (fieldName == null) {
+ throw new IllegalArgumentException("Field name cannot be null");
+ }
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (!Arrays.equals(lhs, rhs)) {
+ diffs.add(new Diff(fieldName) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Short[] getLeft() {
+ return ArrayUtils.toObject(lhs);
+ }
+
+ @Override
+ public Short[] getRight() {
+ return ArrayUtils.toObject(rhs);
+ }
+ });
+ }
+ return this;
+ }
+
+ /**
+ *
+ * Test if two {@code Objects}s are equal.
+ *
+ *
+ * @param fieldName
+ * the field name
+ * @param lhs
+ * the left hand {@code Object}
+ * @param rhs
+ * the right hand {@code Object}
+ * @return this
+ */
+ public DiffBuilder append(final String fieldName, final Object lhs,
+ final Object rhs) {
+
+ if (objectsTriviallyEqual) {
+ return this;
+ }
+ if (lhs == rhs) {
+ return this;
+ }
+
+ Object objectToTest;
+ if (lhs != null) {
+ objectToTest = lhs;
+ } else {
+ // rhs cannot be null, as lhs != rhs
+ objectToTest = rhs;
+ }
+
+ if (objectToTest.getClass().isArray()) {
+ if (objectToTest instanceof boolean[]) {
+ return append(fieldName, (boolean[]) lhs, (boolean[]) rhs);
+ }
+ if (objectToTest instanceof byte[]) {
+ return append(fieldName, (byte[]) lhs, (byte[]) rhs);
+ }
+ if (objectToTest instanceof char[]) {
+ return append(fieldName, (char[]) lhs, (char[]) rhs);
+ }
+ if (objectToTest instanceof double[]) {
+ return append(fieldName, (double[]) lhs, (double[]) rhs);
+ }
+ if (objectToTest instanceof float[]) {
+ return append(fieldName, (float[]) lhs, (float[]) rhs);
+ }
+ if (objectToTest instanceof int[]) {
+ return append(fieldName, (int[]) lhs, (int[]) rhs);
+ }
+ if (objectToTest instanceof long[]) {
+ return append(fieldName, (long[]) lhs, (long[]) rhs);
+ }
+ if (objectToTest instanceof short[]) {
+ return append(fieldName, (short[]) lhs, (short[]) rhs);
+ }
+
+ return append(fieldName, (Object[]) lhs, (Object[]) rhs);
+ }
+
+ // Not array type
+ diffs.add(new Diff