コード例 #1
0
        /**
         * Compares this instance with the specified object and indicates if they
         * are equal. In order to be equal, the following conditions must be
         * fulfilled:
         * <ul>
         * <li>{@code obj} must be a stack trace element,</li>
         * <li>the method names of this stack trace element and of {@code obj} must
         * not be {@code null},</li>
         * <li>the class, method and file names as well as the line number of this
         * stack trace element and of {@code obj} must be equal.</li>
         * </ul>
         *
         * @param obj
         *            the object to compare this instance with.
         * @return {@code true} if the specified object is equal to this
         *         {@code StackTraceElement}; {@code false} otherwise.
         * @see #hashCode
         */
        public override bool Equals(Object obj)
        {
            if (!(obj is StackTraceElement))
            {
                return(false);
            }
            StackTraceElement castObj = (StackTraceElement)obj;

            /*
             * Unknown methods are never equal to anything (not strictly to spec,
             * but spec does not allow null method/class names)
             */
            if ((methodName == null) || (castObj.methodName == null))
            {
                return(false);
            }

            if (!getMethodName().equals(castObj.getMethodName()))
            {
                return(false);
            }
            if (!getClassName().equals(castObj.getClassName()))
            {
                return(false);
            }
            String localFileName = getFileName();

            if (localFileName == null)
            {
                if (castObj.getFileName() != null)
                {
                    return(false);
                }
            }
            else
            {
                if (!localFileName.equals(castObj.getFileName()))
                {
                    return(false);
                }
            }
            if (getLineNumber() != castObj.getLineNumber())
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        /**
         * Counts the number of duplicate stack frames, starting from the
         * end of the stack.
         *
         * @param currentStack a stack to compare
         * @param parentStack a stack to compare
         *
         * @return the number of duplicate stack frames.
         */
        private static int countDuplicates(StackTraceElement[] currentStack,
                                           StackTraceElement[] parentStack)
        {
            int duplicates  = 0;
            int parentIndex = parentStack.Length;

            for (int i = currentStack.Length; --i >= 0 && --parentIndex >= 0;)
            {
                StackTraceElement parentFrame = parentStack[parentIndex];
                if (parentFrame.equals(currentStack[i]))
                {
                    duplicates++;
                }
                else
                {
                    break;
                }
            }
            return(duplicates);
        }
コード例 #3
0
ファイル: Throwable.cs プロジェクト: sailesh341/JavApi
        /// <summary>
        /// Create a new StackTraceElement [] 
        /// </summary>
        /// <returns></returns>
        private StackTraceElement[] getStackTraceImpl()
        {
            System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true);

            StackTraceElement[] result = new StackTraceElement[st.FrameCount];
            for (int i = 0; i < result.Length; i++)
            {
                StackFrame sfe = st.GetFrame(i);
                String type = null;
                if (null != sfe.GetFileName())
                {
                    int startIndex = sfe.GetFileName().LastIndexOf(java.lang.SystemJ.getProperty("file.separator")) == -1 ? 0 : sfe.GetFileName().LastIndexOf(java.lang.SystemJ.getProperty("file.separator")) + 1;
                    int endIndex = sfe.GetFileName().LastIndexOf(".") == -1 ? 0 : sfe.GetFileName().LastIndexOf(".");
                    type = sfe.GetFileName().substring(startIndex, endIndex);
                }
                else
                {
                    type = "Unknown";
                }
                StackTraceElement ste = new StackTraceElement(
                    type,
                    sfe.GetMethod().Name,
                    sfe.GetFileName(),
                    sfe.GetFileLineNumber()
                    );
                result[i] = ste;
            }
            return result;
        }
コード例 #4
0
ファイル: Throwable.cs プロジェクト: sailesh341/JavApi
 /**
  * Counts the number of duplicate stack frames, starting from the
  * end of the stack.
  *
  * @param currentStack a stack to compare
  * @param parentStack a stack to compare
  *
  * @return the number of duplicate stack frames.
  */
 private static int countDuplicates(StackTraceElement[] currentStack,
         StackTraceElement[] parentStack)
 {
     int duplicates = 0;
     int parentIndex = parentStack.Length;
     for (int i = currentStack.Length; --i >= 0 && --parentIndex >= 0; )
     {
         StackTraceElement parentFrame = parentStack[parentIndex];
         if (parentFrame.equals(currentStack[i]))
         {
             duplicates++;
         }
         else
         {
             break;
         }
     }
     return duplicates;
 }