code style minor fixes
This commit is contained in:
parent
78b67c7b7e
commit
5c32bbf033
|
|
@ -28,7 +28,7 @@ import org.roboswag.core.utils.ShouldNotHappenException;
|
|||
* Created by Gavriil Sitnikov on 13/11/2015.
|
||||
* TODO: fill description
|
||||
*/
|
||||
@SuppressWarnings("PMD.ShortClassName")
|
||||
@SuppressWarnings({"PMD.ShortClassName", "ClassNamingConvention", "StaticMethodNamingConvention"})
|
||||
public final class Lc {
|
||||
|
||||
/* Debug level log */
|
||||
|
|
@ -52,7 +52,7 @@ public final class Lc {
|
|||
/* Info level log with exception */
|
||||
@SuppressWarnings({"PMD.ShortMethodName", "checkstyle:methodname"})
|
||||
public static void i(@NonNull final Throwable ex, final String message, final Object... args) {
|
||||
LcHelper.logMessage(Log.INFO, message, ex);
|
||||
LcHelper.logMessage(Log.INFO, message, ex, args);
|
||||
}
|
||||
|
||||
/* Warning level log */
|
||||
|
|
|
|||
|
|
@ -36,19 +36,20 @@ public final class LcHelper {
|
|||
private static int logLevel;
|
||||
private static boolean crashOnAssertions = true;
|
||||
private static LogProcessor logProcessor;
|
||||
private static int stackTraceCodeShift;
|
||||
private static final int STACK_TRACE_CODE_SHIFT;
|
||||
|
||||
private static final ThreadLocalValue<SimpleDateFormat> DATE_TIME_FORMATTER
|
||||
= new ThreadLocalValue<>(() -> new SimpleDateFormat("HH:mm:ss.SSS", new Locale("ru")));
|
||||
|
||||
static {
|
||||
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
for (int i = 0; i < stackTrace.length; i++) {
|
||||
if (stackTrace[i].getClassName().equals(LcHelper.class.getName())) {
|
||||
stackTraceCodeShift = i + 1;
|
||||
int stackDepth;
|
||||
for (stackDepth = 0; stackDepth < stackTrace.length; stackDepth++) {
|
||||
if (stackTrace[stackDepth].getClassName().equals(LcHelper.class.getName())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
STACK_TRACE_CODE_SHIFT = stackDepth + 1;
|
||||
}
|
||||
|
||||
/* Returns if library should crash on fatal exceptions (default - true, set false for production) */
|
||||
|
|
@ -90,7 +91,7 @@ public final class LcHelper {
|
|||
final String formattedMessage;
|
||||
try {
|
||||
formattedMessage = String.format(message, args);
|
||||
} catch (Throwable exception) {
|
||||
} catch (final Throwable exception) {
|
||||
Lc.assertion(exception);
|
||||
return;
|
||||
}
|
||||
|
|
@ -99,8 +100,8 @@ public final class LcHelper {
|
|||
DATE_TIME_FORMATTER.get().format(System.currentTimeMillis()),
|
||||
Thread.currentThread().getName(), formattedMessage);
|
||||
|
||||
final StackTraceElement trace = Thread.currentThread().getStackTrace()[stackTraceCodeShift + 2 + stackTraceAdditionalDepth];
|
||||
final String tag = trace.getFileName() + ":" + trace.getLineNumber();
|
||||
final StackTraceElement trace = Thread.currentThread().getStackTrace()[STACK_TRACE_CODE_SHIFT + 2 + stackTraceAdditionalDepth];
|
||||
final String tag = trace.getFileName() + ':' + trace.getLineNumber();
|
||||
if (ex == null) {
|
||||
logProcessor.processLogMessage(priority, tag, messageExtended);
|
||||
} else {
|
||||
|
|
@ -115,7 +116,7 @@ public final class LcHelper {
|
|||
|
||||
@NonNull
|
||||
public static String getCodePoint(@Nullable final Object caller) {
|
||||
final StackTraceElement trace = Thread.currentThread().getStackTrace()[stackTraceCodeShift];
|
||||
final StackTraceElement trace = Thread.currentThread().getStackTrace()[STACK_TRACE_CODE_SHIFT];
|
||||
return (caller != null ? caller.getClass().getName() + '(' + caller.hashCode() + ") at " : "")
|
||||
+ trace.getFileName() + ':' + trace.getMethodName() + ':' + trace.getLineNumber();
|
||||
}
|
||||
|
|
@ -124,7 +125,7 @@ public final class LcHelper {
|
|||
public static void printStackTrace(final String tag) {
|
||||
if (logLevel <= Log.DEBUG) {
|
||||
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
Log.d(tag, TextUtils.join("\n", Arrays.copyOfRange(stackTrace, stackTraceCodeShift, stackTrace.length)));
|
||||
Log.d(tag, TextUtils.join("\n", Arrays.copyOfRange(stackTrace, STACK_TRACE_CODE_SHIFT, stackTrace.length)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import android.support.annotation.NonNull;
|
|||
|
||||
public class ShouldNotHappenException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 0;
|
||||
|
||||
public ShouldNotHappenException() {
|
||||
super();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ import rx.functions.Func1;
|
|||
*/
|
||||
public final class StringUtils {
|
||||
|
||||
/* Returns MD5 hash of string */
|
||||
/* Returns MD5 hash of text */
|
||||
@NonNull
|
||||
public static String md5(@NonNull final String string) {
|
||||
public static String md5(@NonNull final String text) {
|
||||
try {
|
||||
final MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
digest.update(string.getBytes("UTF-8"));
|
||||
digest.update(text.getBytes("UTF-8"));
|
||||
final byte[] messageDigestArray = digest.digest();
|
||||
|
||||
final StringBuilder hexString = new StringBuilder();
|
||||
|
|
@ -30,25 +30,25 @@ public final class StringUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean containsCharLike(@NonNull final String string, @NonNull final Func1<Character, Boolean> condition) {
|
||||
for (int i = 0; i < string.length(); i++) {
|
||||
if (condition.call(string.charAt(i))) {
|
||||
private static boolean containsCharLike(@NonNull final String text, @NonNull final Func1<Character, Boolean> condition) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (condition.call(text.charAt(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean containsNumbers(@NonNull final String string) {
|
||||
return containsCharLike(string, Character::isDigit);
|
||||
public static boolean containsNumbers(@NonNull final String text) {
|
||||
return containsCharLike(text, Character::isDigit);
|
||||
}
|
||||
|
||||
public static boolean containsLowerCase(@NonNull final String string) {
|
||||
return containsCharLike(string, Character::isLowerCase);
|
||||
public static boolean containsLowerCase(@NonNull final String text) {
|
||||
return containsCharLike(text, Character::isLowerCase);
|
||||
}
|
||||
|
||||
public static boolean containsUpperCase(@NonNull final String string) {
|
||||
return containsCharLike(string, Character::isUpperCase);
|
||||
public static boolean containsUpperCase(@NonNull final String text) {
|
||||
return containsCharLike(text, Character::isUpperCase);
|
||||
}
|
||||
|
||||
private StringUtils() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue