Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Medium - Android/Java Interfaces like a Boss! - Default Functionalities l
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