/* * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * A difference between two arrays, which can be pretty formatted. * For the calculated difference, user can request if the two arrays * are equal (in terms of {@link Object#equals Object.equals()} for their * elements). For the arrays that differ, a human-readable difference can * be provided. * * <p>The difference is represented as a four-line text block, comprising of the * first different element index, arrays printouts in the difference area, * and a difference mark. For Primitive and Object elements in the source * arrays their C-style escaped {@link String#valueOf String.valueOf()} are * printed, element in String[] arrays are additionally surrounded with quotes. * Additional formatting parameters, like maximum allowed width and number of * elements printed before difference, can be specified. * * <p>Output examples: * * <p> two int arrays: </p> * <pre> * Arrays differ starting from [index: 4]: * ... 3, 4, 5, 6, 7] * ... 3, 4, 225, 6, 7] * ^^^^ * </pre> * <p> two String arrays: </p> * <pre> * Arrays differ starting from [index: 2]: * ["first", "second", "third", "u\nprintable"] * ["first", "second", "incorrect", "u\nprintable"] * ^^^^^^^^^^^^ * </pre> * <p> two char arrays: </p> * <pre> * Arrays differ starting from [index: 7]: * ... \u0001, \u0002, \u0007, a, b, \n, ... * ... \u0001, \u0002, }, a, b, \n, ... * ^^^^^^^ * </pre>
*/ publicclass ArrayDiff<E> implements Diff {
/** * Creates an ArrayDiff fom two arrays and default limits. The given arguments must be of the same * component type. * * @param first the first array * @param second the second array * @return an ArrayDiff instance for the two arrays
*/ publicstatic ArrayDiff<?> of(Object first, Object second) { return ArrayDiff.of(first, second, Diff.Defaults.WIDTH, Diff.Defaults.CONTEXT_BEFORE);
}
/** * Creates an ArrayDiff fom two arrays with the given limits. The given arguments must be of the same * component type. * * @param first the first array * @param second the second array * @param width the maximum allowed width in characters for the formatting * @param contextBefore maximum number of elements to print before those that differ * @throws IllegalArgumentException if component types of arrays is not supported or are not the same * @throws NullPointerException if at least one of the arrays is null * @return an ArrayDiff instance for the two arrays and formatting parameters provided
*/
@SuppressWarnings("rawtypes") publicstatic ArrayDiff<?> of(Object first, Object second, int width, int contextBefore) {
Objects.requireNonNull(first);
Objects.requireNonNull(second);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.