#36 rxjava: utils
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package org.example.utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class DateUtil {
|
||||
public static String getNowDate(){
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||
.format(Calendar.getInstance().getTime());
|
||||
}
|
||||
}
|
||||
26
RxJava/practice/src/main/java/org/example/utils/LogType.java
Normal file
26
RxJava/practice/src/main/java/org/example/utils/LogType.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.example.utils;
|
||||
|
||||
public enum LogType {
|
||||
ON_SUBSCRIBE("onSubscribe()"),
|
||||
ON_NEXT("onNext()"),
|
||||
ON_ERROR("onERROR()"),
|
||||
ON_COMPLETE("onComplete()"),
|
||||
ON_SUCCESS("onSuccess()"),
|
||||
DO_ON_SUBSCRIBE("doOnSubscribe()"),
|
||||
DO_ON_NEXT("doOnNext()"),
|
||||
DO_ON_COMPLETE("doOnComplete()"),
|
||||
DO_ON_EACH("doOnEach()"),
|
||||
DO_ON_DISPOSE("doOnDispose()"),
|
||||
DO_ON_ERROR("donOnError()"),
|
||||
PRINT("print()");
|
||||
|
||||
private String logType;
|
||||
|
||||
LogType(String logType) {
|
||||
this.logType = logType;
|
||||
}
|
||||
|
||||
public String getLogType() {
|
||||
return logType;
|
||||
}
|
||||
}
|
||||
23
RxJava/practice/src/main/java/org/example/utils/Logger.java
Normal file
23
RxJava/practice/src/main/java/org/example/utils/Logger.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.example.utils;
|
||||
|
||||
public class Logger {
|
||||
public static void log(String msg){
|
||||
String time = TimeUtil.getCurrentTimeFormatted();
|
||||
System.out.println(msg + " | " + Thread.currentThread().getName() + " | " + time);
|
||||
}
|
||||
|
||||
public static void log(String msg, Object obj){
|
||||
String time = TimeUtil.getCurrentTimeFormatted();
|
||||
System.out.println(msg + " | " + Thread.currentThread().getName() + " | " + time + " | " +obj);
|
||||
}
|
||||
|
||||
public static void log(LogType logType){
|
||||
String time = TimeUtil.getCurrentTimeFormatted();
|
||||
System.out.println(logType.getLogType() + " | " + Thread.currentThread().getName() + " | " + time);
|
||||
}
|
||||
|
||||
public static void log(LogType logType, Object obj){
|
||||
String time = TimeUtil.getCurrentTimeFormatted();
|
||||
System.out.println(logType.getLogType() + " | " + Thread.currentThread().getName() + " | " + time + " | " +obj);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.example.utils;
|
||||
|
||||
public class NumberUtil {
|
||||
public static int randomRange(int min, int max){
|
||||
return (int)(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.example.utils;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class TimeUtil {
|
||||
public static long start;
|
||||
public static long end;
|
||||
final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
|
||||
|
||||
public static long start(){
|
||||
start = System.currentTimeMillis();
|
||||
return start;
|
||||
}
|
||||
|
||||
public static void end(){
|
||||
end = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static void takeTime(){
|
||||
System.out.println("# 실행시간: " + (end - start) + " ms");
|
||||
}
|
||||
public static String getCurrentTimeFormatted(){
|
||||
return LocalTime.now().format(formatter);
|
||||
}
|
||||
public static long getCurrentTime(){
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
public static void sleep(long interval){
|
||||
try {
|
||||
Thread.sleep(interval);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user