본문 바로가기

Android/RX

4. 공통 소스 (참고용)

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();
        }
    }
}




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;
    }
}





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);
    }
}





public class DateUtil {
    public static String getNowDate(){
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(Calendar.getInstance().getTime());
    }
}

'Android > RX' 카테고리의 다른 글

4. Simple, Maybe, Completable  (0) 2021.01.14
4. Observable, Flowable  (0) 2021.01.14
4. Reactive Streams  (0) 2021.01.14
4. 리액티브 프로그래밍이란 ?  (0) 2021.01.11