Example usage for java.lang StackTraceElement hashCode

List of usage examples for java.lang StackTraceElement hashCode

Introduction

In this page you can find the example usage for java.lang StackTraceElement hashCode.

Prototype

public int hashCode() 

Source Link

Document

Returns a hash code value for this stack trace element.

Usage

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];

    System.out.println(e.hashCode());
}

From source file:com.codepunk.codepunklib.util.log.FormattingLogger.java

/**
 * Returns the concrete information from the given {@link StackTraceElement} that is represented
 * by the given Placeholder./*from   w  ww .  j a v a 2  s  . c  om*/
 * @param element The {@link StackTraceElement}.
 * @param placeholder The {@link Placeholder} to replace.
 * @return The information represented by the Placeholder.
 */
private static Object getFromElement(StackTraceElement element, Placeholder placeholder) {
    try {
        switch (placeholder) {
        case FILE_NAME:
            return element.getFileName();
        case HASH_CODE:
            return element.hashCode();
        case LINE_NUMBER:
            return element.getLineNumber();
        case METHOD_NAME:
            return element.getMethodName();
        case PACKAGE: {
            return getClass(element).getPackage().getName();
        }
        case CLASS_NAME:
        case SIMPLE_CLASS_NAME:
        default: {
            String name;
            Class cls = getClass(element);
            do {
                if (cls == null) {
                    name = UNKNOWN_CLASS_NAME;
                } else if (placeholder == Placeholder.CLASS_NAME) {
                    name = cls.getName();
                } else {
                    name = cls.getSimpleName();
                }
            } while (TextUtils.isEmpty(name));
            return name;
        }
        }
    } catch (ClassNotFoundException e) {
        return UNKNOWN_CLASS_NAME;
    }
}