Skip to content

reddevilmidzy/java-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 

Repository files navigation

java-template

코드 템플릿


구현 기능 목록 템플릿

# 구현 기능 목록


## 기능



## 입력



## 출력



## 예외



Controller

private final InputController inputController;
private final OutputView outputView;

public Controller(InputController inputController, OutputView outputView) {
    this.inputController = inputController;
    this.outputView = outputView;
}

public void run() {
}

InputController

    private final InputView inputView;
    private final OutputView outputView;


    public InputController(InputView inputView, OutputView outputView) {
        this.inputView = inputView;
        this.outputView = outputView;
    }

	public Object getXX() {
		while (true) {
			try {
				return readXX();
			} catch (IllegalArgumentException exception) {
                outputView.printErrorMessage(exception);
            }
		}
	}

	private Object readXX() {
		String value = inputView.readXX();
		return XX.from(value);
	}

InputView

    public String readXX() {
        System.out.println("blah blah");
        String value = readLine();
        System.out.println();
        return value;
    }

    protected String readLine() {
        return Console.readLine();
    }

OutputView

    public static final String ERROR_FORM = "[ERROR] %s%n";

    public void printErrorMessage(Throwable throwable) {
        System.out.printf(ERROR_FORM, throwable.getMessage());
	System.out.println();
    }

ErrorMessge

    INVALID_XX("유효하지 않은 값입니다."),

    RETRY_INPUT("다시 입력해 주세요.");

    private final String message;

    ErrorMessage(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

Regax

public static final Pattern NUMERIC_PATTERN = Pattern.compile("^[0-9]+$");
public static final Pattern KOREAN_AND_ENGLISH_PATTERN = Pattern.compile("^[ㄱ-ㅎ가-힣A-Za-z]+$");

Separator

private static void validate(String value) {
        if (value.trim().isEmpty()) {
            throw new IllegalArgumentException();
        }
        if (value.startsWith(",") || value.endsWith(",")) {
            throw new IllegalArgumentException();
        }
        if (value.contains(",,")) {
            throw new IllegalArgumentException();
        }
    }

Range

private static void validate(String value) {
	try {
		if (Integer.parseInt(value) < 0) {
			throw new IllegalArgumentException();
		}
	} catch (NumberFormatException exception) {
		throw new IllegalArgumentException();
	}
}

equals

@Override
public boolean equals(Object obj) {
	if (this == obj) {
            return true;
        }
        if (!(obj instanceof X target)) {
            return false;
        }
	return // TODO:
}

hashCode

@Override
public int hashCode() {
	return Objects.hash(vo);
}

comma

public static final DecimalFormat NUMBER_FORMAT = new DecimalFormat("###,###");

private String formatted(Integer value) {
        return NUMBER_FORMAT.format(value);
    }

iterator

private void printValues(Iterator<Crew> iterator) {
        while (iterator.hasNext()) {
            System.out.print(iterator.next().getName());
            if (iterator.hasNext()) {
                System.out.print(" : ");
            }
        }
        System.out.println();
    }

map forEach

public void forEach(BiConsumer<? super K, ? super V> action) {
        map.forEach(action);
    }

list forEach

public void forEach(Consumer<? super T> action) {
	list.forEach(action);
}

valueof

    public static ENUM_TYPE valueOfName(String name) {
        return Arrays.stream(values())
                .filter(s -> s.cmd.equals(name))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.));
    }

About

미션 템플릿

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published