Java Stacktrace stackTraceEquals(StackTraceElement[] ta1, StackTraceElement[] ta2)

Here you can find the source of stackTraceEquals(StackTraceElement[] ta1, StackTraceElement[] ta2)

Description

Compares two stack traces and checks if they are equal

License

Open Source License

Parameter

Parameter Description
ta1 First stack trace
ta2 Second stack trace

Return

true if they are equal, false otherwise.

Declaration

public static boolean stackTraceEquals(StackTraceElement[] ta1, StackTraceElement[] ta2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w  ww  .j a v a 2 s.c  o m
     * Compares two stack traces and checks if they are equal
     * @param ta1 First stack trace
     * @param ta2 Second stack trace
     * @return true if they are equal, false otherwise.
     */
    public static boolean stackTraceEquals(StackTraceElement[] ta1, StackTraceElement[] ta2) {
        // First check if the addresses are the same, if so, early exit
        if (ta1 == ta2) {
            return true;
        }
        if (ta1.length == ta2.length) {
            for (int i = 0, lnLength = ta1.length; i < lnLength; i++) {
                if (!equals(ta1[i], ta2[i])) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /**
     * Compares two stack trace elements
     * @param toA first stack trace
     * @param toB second stack trace
     * @return returns true if they are equal
     */
    public static boolean equals(StackTraceElement toA, StackTraceElement toB) {
        return toA == toB || (toA != null && toA.equals(toB));
    }
}

Related

  1. stackTraceAsString(Throwable t)
  2. stackTraceContainsCause(Throwable throwable, Class searchedCause)
  3. stackTraceElementToString( StackTraceElement element)
  4. stackTraceElementWithLinenumber( StackTraceElement stackTraceElement)
  5. stackTraceElementWithLinenumberAsString(StackTraceElement stackTraceElement)
  6. stackTraceGenerate()