001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      https://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.lang3.builder;
018
019/**
020 * {@link Diffable} classes can be compared with other objects
021 * for differences. The {@link DiffResult} object retrieved can be queried
022 * for a list of differences or printed using the {@link DiffResult#toString()}.
023 *
024 * <p>
025 * The calculation of the differences is <em>consistent with equals</em> if
026 * and only if {@code d1.equals(d2)} implies {@code d1.diff(d2) == ""}.
027 * It is strongly recommended that implementations are consistent with equals
028 * to avoid confusion. Note that {@code null} is not an instance of any class
029 * and {@code d1.diff(null)} should throw a {@link NullPointerException}.
030 * </p>
031 *
032 * <p>
033 * {@link Diffable} classes lend themselves well to unit testing, in which a
034 * easily readable description of the differences between an anticipated result and
035 * an actual result can be retrieved. For example:
036 * </p>
037 * <pre>
038 * Assert.assertEquals(expected.diff(result), expected, result);
039 * </pre>
040 *
041 * @param <T> The type of objects that this object may be differentiated against
042 * @since 3.3
043 */
044@FunctionalInterface
045public interface Diffable<T> {
046
047    /**
048     * Retrieves a list of the differences between
049     * this object and the supplied object.
050     *
051     * @param obj The object to diff against, can be {@code null}
052     * @return A list of differences
053     * @throws NullPointerException Thrown if the specified object is {@code null}.
054     */
055    DiffResult<T> diff(T obj);
056}