001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.spi;
015
016public class STEUtil {
017
018    static int UNUSED_findNumberOfCommonFrames(StackTraceElement[] steArray, StackTraceElement[] otherSTEArray) {
019        if (otherSTEArray == null) {
020            return 0;
021        }
022
023        int steIndex = steArray.length - 1;
024        int parentIndex = otherSTEArray.length - 1;
025        int count = 0;
026        while (steIndex >= 0 && parentIndex >= 0) {
027            if (steArray[steIndex].equals(otherSTEArray[parentIndex])) {
028                count++;
029            } else {
030                break;
031            }
032            steIndex--;
033            parentIndex--;
034        }
035        return count;
036    }
037
038    static int findNumberOfCommonFrames(StackTraceElement[] steArray, StackTraceElementProxy[] otherSTEPArray) {
039        if (otherSTEPArray == null) {
040            return 0;
041        }
042
043        int steIndex = steArray.length - 1;
044        int parentIndex = otherSTEPArray.length - 1;
045        int count = 0;
046        while (steIndex >= 0 && parentIndex >= 0) {
047            if (steArray[steIndex].equals(otherSTEPArray[parentIndex].ste)) {
048                count++;
049            } else {
050                break;
051            }
052            steIndex--;
053            parentIndex--;
054        }
055        return count;
056    }
057}