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 *      http://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 * <p>{@code 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()}.</p>
023 *
024 * <p>The calculation of the differences is <i>consistent with equals</i> if
025 * and only if {@code d1.equals(d2)} implies {@code d1.diff(d2) == ""}.
026 * It is strongly recommended that implementations are consistent with equals
027 * to avoid confusion. Note that {@code null} is not an instance of any class
028 * and {@code d1.diff(null)} should throw a {@code NullPointerException}.</p>
029 *
030 * <p>
031 * {@code Diffable} classes lend themselves well to unit testing, in which a
032 * easily readable description of the differences between an anticipated result and
033 * an actual result can be retrieved. For example:
034 * </p>
035 * <pre>
036 * Assert.assertEquals(expected.diff(result), expected, result);
037 * </pre>
038 *
039 * @param <T> the type of objects that this object may be differentiated against
040 * @since 3.3
041 */
042@FunctionalInterface
043public interface Diffable<T> {
044
045    /**
046     * <p>Retrieves a list of the differences between
047     * this object and the supplied object.</p>
048     *
049     * @param obj the object to diff against, can be {@code null}
050     * @return a list of differences
051     * @throws NullPointerException if the specified object is {@code null}
052     */
053    DiffResult<T> diff(T obj);
054}