Last active
July 28, 2019 03:52
-
-
Save Guilherme-HRamos/2e2799a145dbafb2d2d4a6022eb99b17 to your computer and use it in GitHub Desktop.
Medium - Android/Java Interfaces like a Boss! - Default Functionalities l
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface LoggerComponent { | |
String TAG = "LoggerComponent"; | |
default void printJustMessage(final String inf) { | |
if (BuildConfig.DEBUG) | |
Log.d(TAG, inf); | |
} | |
default void printMethodCall(final StackTraceElement thread) { | |
final boolean isThreadValid = thread != null && thread.getFileName() != null && thread.getFileName().contains("."); | |
final String pattern; | |
if (isThreadValid) { | |
final String filename = thread.getFileName(); | |
final String className = filename.substring(0, filename.lastIndexOf('.')); | |
pattern = "@" + className + "." + thread.getMethodName() + "()"; | |
} else { | |
pattern = "@ClassNameUndefined.UndefinedThread!!!"; | |
} | |
if (BuildConfig.DEBUG) | |
Log.d(TAG, pattern); | |
} | |
default void printMethodCall(final String inf, final StackTraceElement thread) { | |
final boolean isThreadValid = thread != null && thread.getFileName() != null && thread.getFileName().contains("."); | |
final String pattern; | |
if (isThreadValid) { | |
final String filename = thread.getFileName(); | |
final String className = filename.substring(0, filename.lastIndexOf('.')); | |
pattern = "@" + className + "." + thread.getMethodName() + "()"; | |
} else { | |
pattern = "@ClassNameUndefined.UndefinedThread!!!"; | |
} | |
if (BuildConfig.DEBUG) | |
Log.d(TAG, pattern + " -> " + inf); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment