Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Step2] ๐Ÿš€ 2๋‹จ๊ณ„ - ์‚ฌ๋‹ค๋ฆฌ(์ƒ์„ฑ) #1776

Open
wants to merge 16 commits into
base: simjung
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4919b56
๋žŒ๋‹ค ์‹ค์Šต 1 - ์ต๋ช… ํด๋ž˜์Šค๋ฅผ ๋žŒ๋‹ค๋กœ ์ „ํ™˜
SimJung May 12, 2023
7060fe1
๋žŒ๋‹ค ์‹ค์Šต 2 - ๋žŒ๋‹ค๋ฅผ ํ™œ์šฉํ•ด ์ค‘๋ณต ์ œ๊ฑฐ
SimJung May 12, 2023
c7a9148
map, reduce, filter ์‹ค์Šต 1 - sumOverThreeAndDouble ํ…Œ์ŠคํŠธ pass
SimJung May 12, 2023
c9f1605
map, reduce, filter ์‹ค์Šต 2 - printLongestWordTop100() ๋ฉ”์„œ๋“œ ๊ตฌํ˜„
SimJung May 12, 2023
51532c0
์š”๊ตฌ์‚ฌํ•ญ 1 - Optional์„ ํ™œ์šฉํ•ด ์กฐ๊ฑด์— ๋”ฐ๋ฅธ ๋ฐ˜ํ™˜
SimJung May 12, 2023
79be2ed
์š”๊ตฌ์‚ฌํ•ญ 2 - Optional์—์„œ ๊ฐ’์„ ๋ฐ˜ํ™˜
SimJung May 12, 2023
67146b7
์š”๊ตฌ์‚ฌํ•ญ 3 - Optional์—์„œ exception ์ฒ˜๋ฆฌ
SimJung May 12, 2023
9e2df9e
Merge branch 'simjung' into step1
SimJung May 12, 2023
793a092
Merge branch 'simjung' of https://github.com/SimJung/java-ladder intoโ€ฆ
SimJung May 14, 2023
ef3f71c
feat : Conditional์„ Predicate๋กœ ๋ณ€๊ฒฝ
SimJung May 14, 2023
d1728d4
refactor : matchExpression static ์ œ๊ฑฐ
SimJung May 14, 2023
5170347
fix : age์˜ null ์ฒดํฌ ์ถ”๊ฐ€
SimJung May 14, 2023
226645d
docs : README.md ์ถ”๊ฐ€
SimJung May 14, 2023
20e0660
feat : ์‚ฌ๋‹ค๋ฆฌ ๊ฒŒ์ž„์— ์ฐธ์—ฌํ•˜๋Š” ์‚ฌ๋žŒ์— ์ด๋ฆ„์„ ์ตœ๋Œ€ 5๊ธ€์ž ๊นŒ์ง€ ๋ถ€์—ฌํ•  ์ˆ˜ ์žˆ๋‹ค.
SimJung May 14, 2023
3bd6f44
feat : Ladder ๊ด€๋ จ ๋กœ์ง ๊ตฌํ˜„
SimJung May 17, 2023
59d1c9b
feat : LadderGenerator ๊ตฌํ˜„ ๋ฐ main ๊ตฌ์„ฑ
SimJung May 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/main/java/ladder/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ladder;

import ladder.domain.Ladder;
import ladder.domain.LadderGenerator;
import ladder.domain.player.Players;
import ladder.domain.player.PlayersGenerator;
import ladder.view.InputView;
import ladder.view.ResultView;

public class Main {
public static void main(String[] args) {
Players players = PlayersGenerator.create(InputView.getPlayerNames());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InputView.getPlayerNames() ๋Š” ๋ณ€์ˆ˜๋กœ ํ•œ๋ฒˆ ๋นผ๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š” ?

int width = players.getPlayerNumber();
System.out.println();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ค„๋ฐ”๊ฟˆ์€ ๊ผญ ์—ฌ๊ธฐ์„œ ํ•ด ์ค˜์•ผ ํ• ๊นŒ์š” ?


int height = InputView.getLadderHeight();
System.out.println();

Ladder ladder = new LadderGenerator().generate(height, width);
ResultView.showResultMessage();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ์„ธ ๊ฐœ๋ฅผ ๋ฌถ๋Š” ํ•จ์ˆ˜๋ฅผ ๋”ฐ๋กœ ์ œ๊ณตํ•ด์ฃผ๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š” ?

ResultView.showPlayers(players);
ResultView.showLadder(ladder);
}
}
14 changes: 14 additions & 0 deletions src/main/java/ladder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ๐Ÿš€2๋‹จ๊ณ„ - ์‚ฌ๋‹ค๋ฆฌ(์ƒ์„ฑ)

## ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ

- ์‚ฌ๋‹ค๋ฆฌ ๊ฒŒ์ž„์— ์ฐธ์—ฌํ•˜๋Š” ์‚ฌ๋žŒ์— ์ด๋ฆ„์„ ์ตœ๋Œ€5๊ธ€์ž๊นŒ์ง€ ๋ถ€์—ฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์‚ฌ๋‹ค๋ฆฌ๋ฅผ ์ถœ๋ ฅํ•  ๋•Œ ์‚ฌ๋žŒ ์ด๋ฆ„๋„ ๊ฐ™์ด ์ถœ๋ ฅํ•œ๋‹ค.
- ์‚ฌ๋žŒ ์ด๋ฆ„์€ ์‰ผํ‘œ(,)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค.
- ์‚ฌ๋žŒ ์ด๋ฆ„์„ 5์ž ๊ธฐ์ค€์œผ๋กœ ์ถœ๋ ฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ๋‹ค๋ฆฌ ํญ๋„ ๋„“์–ด์ ธ์•ผ ํ•œ๋‹ค.
- ์‚ฌ๋‹ค๋ฆฌ ํƒ€๊ธฐ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๋ ค๋ฉด ๋ผ์ธ์ด ๊ฒน์น˜์ง€ ์•Š๋„๋ก ํ•ด์•ผ ํ•œ๋‹ค.
- |-----|-----| ๋ชจ์–‘๊ณผ ๊ฐ™์ด ๊ฐ€๋กœ ๋ผ์ธ์ด ๊ฒน์น˜๋Š” ๊ฒฝ์šฐ ์–ด๋Š ๋ฐฉํ–ฅ์œผ๋กœ ์ด๋™ํ• ์ง€ ๊ฒฐ์ •ํ•  ์ˆ˜ ์—†๋‹ค.

## ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ์‚ฌํ•ญ

- ์ž๋ฐ” 8์˜ ์ŠคํŠธ๋ฆผ๊ณผ ๋žŒ๋‹ค๋ฅผ ์ ์šฉํ•ด ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•œ๋‹ค.
- ๊ทœ์น™ 6: ๋ชจ๋“  ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ž‘๊ฒŒ ์œ ์ง€ํ•œ๋‹ค.
43 changes: 43 additions & 0 deletions src/main/java/ladder/domain/AdjacentVerticalLines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ladder.domain;

import ladder.exception.IllegalAdjacentVerticalLinesException;

public class AdjacentVerticalLines {
private final VerticalLine leftVerticalLine;
private final VerticalLine rightVerticalLine;

public AdjacentVerticalLines(VerticalLine firstVerticalLine, VerticalLine secondVerticalLine) {
checkAdjacentVerticalLines(firstVerticalLine, secondVerticalLine);

this.leftVerticalLine = min(firstVerticalLine, secondVerticalLine);
this.rightVerticalLine = max(firstVerticalLine, secondVerticalLine);
}

public VerticalLine getLeftVerticalLine() {
return leftVerticalLine;
}

public VerticalLine getRightVerticalLine() {
return rightVerticalLine;
}

private void checkAdjacentVerticalLines(VerticalLine firstVerticalLine, VerticalLine secondVerticalLine) {
if (Math.abs(firstVerticalLine.getIndex() - secondVerticalLine.getIndex()) > 1) {
throw new IllegalAdjacentVerticalLinesException(
String.format("์ž…๋ ฅ๋œ ์ธ๋ฑ์Šค : %d, %d", firstVerticalLine.getIndex(), secondVerticalLine.getIndex())
);
}
}

private VerticalLine max(VerticalLine firstVerticalLine, VerticalLine secondVerticalLine) {
return firstVerticalLine.getIndex() > secondVerticalLine.getIndex()
? firstVerticalLine
: secondVerticalLine;
}

private VerticalLine min(VerticalLine firstVerticalLine, VerticalLine secondVerticalLine) {
return firstVerticalLine.getIndex() > secondVerticalLine.getIndex()
? secondVerticalLine
: firstVerticalLine;
}
}
44 changes: 44 additions & 0 deletions src/main/java/ladder/domain/HorizontalLine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ladder.domain;

import ladder.exception.IllegalHorizontalLineHeightException;

public class HorizontalLine {
static final int MINIMUM_HEIGHT = 0;

private final AdjacentVerticalLines adjacentVerticalLines;
private final int height;

public HorizontalLine(AdjacentVerticalLines adjacentVerticalLines, int height) {
checkHeight(height);

this.adjacentVerticalLines = adjacentVerticalLines;
this.height = height;
}

private void checkHeight(int height) {
if (height < MINIMUM_HEIGHT) {
throw new IllegalHorizontalLineHeightException(String.format("์ตœ์†Œ ๋†’์ด : %d", MINIMUM_HEIGHT));
}
}

public AdjacentVerticalLines getAdjacentVerticalLines() {
return adjacentVerticalLines;
}

public int getHeight() {
return height;
}

public VerticalLine getLeftVerticalLine() {
return adjacentVerticalLines.getLeftVerticalLine();
}

public VerticalLine getRightVerticalLine() {
return adjacentVerticalLines.getRightVerticalLine();
}

public boolean isConnected(VerticalLine verticalLine) {
return verticalLine == adjacentVerticalLines.getLeftVerticalLine()
|| verticalLine == adjacentVerticalLines.getRightVerticalLine();
}
}
44 changes: 44 additions & 0 deletions src/main/java/ladder/domain/HorizontalLines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ladder.domain;

import ladder.exception.IllegalHorizontalLineHeightException;

import java.util.Set;
import java.util.stream.Collectors;

public class HorizontalLines {
private final Set<HorizontalLine> horizontalLineSet;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜น์‹œ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ Set์œผ๋กœ ์ •ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š” ?

private final int maxHeight;

public HorizontalLines(Set<HorizontalLine> horizontalLineSet, int maxHeight) {
checkValidHorizontalLineHeight(horizontalLineSet, maxHeight);

this.horizontalLineSet = horizontalLineSet;
this.maxHeight = maxHeight;
}

private void checkValidHorizontalLineHeight(Set<HorizontalLine> horizontalLineSet, int maxHeight) {
if (horizontalLineSet.stream()
.anyMatch(it -> it.getHeight() >= maxHeight)
) {
throw new IllegalHorizontalLineHeightException(String.format("์ตœ๋Œ€ ๋†’์ด : %d", maxHeight));
}
}

public Set<HorizontalLine> getHorizontalLineSet() {
return Set.copyOf(horizontalLineSet);
}

public Set<HorizontalLine> getHorizontalLineSetByHeight(int height) {
return horizontalLineSet.stream()
.filter(it -> it.getHeight() == height)
.collect(Collectors.toSet());
}

public int getMaxHeight() {
return maxHeight;
}

public int getSize() {
return horizontalLineSet.size();
}
}
66 changes: 66 additions & 0 deletions src/main/java/ladder/domain/Ladder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package ladder.domain;

import ladder.exception.ContinuousHorizontalLineException;
import ladder.exception.NotEnoughVerticalLinesException;

import java.util.Set;

public class Ladder {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์‚ฌ๋‹ค๋ฆฌ๋ฅผ ๊ฐ€๋กœ์„  / ์„ธ๋กœ์„ ์˜ ๊ฐœ๋…์œผ๋กœ ์ ‘๊ทผํ•˜๋ฉด์„œ ๋กœ์ง์ด ๋งŽ์ด ๋ณต์žกํ•ด ์ง„ ๊ฒƒ ๊ฐ™์•„์š”!
์‚ฌ๋‹ค๋ฆฌ ํ•œ์นธ ํ•œ์นธ์„ ์ ์œผ๋กœ ๋ฐ”๋ผ๋ณด๊ณ , ๊ฐ ์ ์—์„œ ์‚ฌ๋‹ค๋ฆฌ์˜ ์œ ๋ฌด๋ฅผ ํŒ๋‹จํ•˜๋Š” ์‹์œผ๋กœ ๊ฐœ๋…์„ ์กฐ๊ธˆ ๋ฐ”๊พธ๋ฉด ์‰ฝ๊ฒŒ ์ ‘๊ทผ ํ•  ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ์š” ?
4๋ช…์˜ ํ”Œ๋ ˆ์ด์–ด, ๋†’์ด 4์˜ ์‚ฌ๋‹ค๋ฆฌ๋ผ๋ฉด
[x][o][x]
[o][x][o]
[o][x][o]
[x][x][o]
์ด๋Ÿฐ์‹์œผ๋กœ์š”!

static final int MINIMUM_VERTICAL_LINES_QUANTITY = 2;

private final VerticalLines verticalLines;
private final HorizontalLines horizontalLines;

public Ladder(VerticalLines verticalLines, HorizontalLines horizontalLines) {
checkVerticalLines(verticalLines);
checkValidLines(verticalLines, horizontalLines);

this.verticalLines = verticalLines;
this.horizontalLines = horizontalLines;
}

private void checkVerticalLines(VerticalLines verticalLines) {
if (verticalLines.getSize() < MINIMUM_VERTICAL_LINES_QUANTITY) {
throw new NotEnoughVerticalLinesException(String.format("์„ธ๋กœ์„  ๊ฐฏ์ˆ˜ : %d", verticalLines.getSize()));
}
}

private void checkValidLines(VerticalLines verticalLines, HorizontalLines horizontalLines) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์š” ์œ ํšจ์„ฑ๊ฒ€์‚ฌ ํ˜น์‹œ ๊ผญ ํ•„์š” ํ• ๊นŒ์š” ? ์•ž์— VerticalLines์™€ HorizontalLines๋ฅผ ๋งŒ๋“ค ๋•Œ ์ด๋ฏธ ๊ฒ€์ฆ ๋˜๊ณ  ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„์„œ์š”!

for (int i = 0; i < horizontalLines.getMaxHeight(); i++) {
Set<HorizontalLine> horizontalLineSet = horizontalLines.getHorizontalLineSetByHeight(i);
checkExistContinuousHorizontalLinesOnSameHeight(verticalLines, horizontalLineSet);
}
}

private void checkExistContinuousHorizontalLinesOnSameHeight(VerticalLines verticalLines, Set<HorizontalLine> horizontalLineSet) {
verticalLines.getVerticalLineSet()
.forEach(verticalLine ->
checkConnectingWithManyHorizontalLines(verticalLine, horizontalLineSet)
);
}

private void checkConnectingWithManyHorizontalLines(VerticalLine verticalLine, Set<HorizontalLine> horizontalLineSet) {
if (horizontalLineSet.stream()
.filter(it -> it.isConnected(verticalLine))
.count() > 1
) {
throw new ContinuousHorizontalLineException(String.format("์ค‘๋ณต๋˜๋Š” ์„ธ๋กœ์„  ์œ„์น˜ : %d", verticalLine.getIndex()));
}
}

public int getHeight() {
return horizontalLines.getMaxHeight();
}

public int getWidth() {
return verticalLines.getMaxWidth();
}

public VerticalLines getVerticalLines() {
return verticalLines;
}

public HorizontalLines getHorizontalLines() {
return horizontalLines;
}
}
5 changes: 5 additions & 0 deletions src/main/java/ladder/domain/LadderGenerateStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ladder.domain;

public interface LadderGenerateStrategy {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ธํ„ฐํŽ˜์ด์Šค ํ™œ์šฉ ์ข‹๋„ค์š”! ํ˜น์‹œ domain ํŒจํ‚ค์ง€ ๋‚ด๋ถ€์—์„œ๋„ ๊ด€๊ณ„์žˆ๋Š” ํด๋ž˜์Šค๋ผ๋ฆฌ ๋”ฐ๋กœ ํŒจํ‚ค์ง• ํ•  ์ˆ˜๋Š” ์—†์„๊นŒ์š” ?

boolean canGenerate();
}
71 changes: 71 additions & 0 deletions src/main/java/ladder/domain/LadderGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package ladder.domain;

import ladder.exception.IllegalLadderParameterException;

import java.util.HashSet;
import java.util.Set;

public class LadderGenerator {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ํด๋ž˜์Šค๋Š” ์œ ํ‹ธ ํด๋ž˜์Šค๋กœ ์„ ์–ธ ํ•ด ๋ณด๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š” ? Strategy๋ฅผ generate์—์„œ ๋ฐ›์•„๋„ ๋  ๊ฒƒ ๊ฐ™์•„์„œ์š”!

private static final double DEFAULT_CHANCE = 0.5;

private final LadderGenerateStrategy ladderGenerateStrategy;

public LadderGenerator() {
this.ladderGenerateStrategy = () -> Math.random() < DEFAULT_CHANCE;
}

public LadderGenerator(LadderGenerateStrategy ladderGenerateStrategy) {
this.ladderGenerateStrategy = ladderGenerateStrategy;
}

public Ladder generate(int height, int width) {
checkHeightAndWidth(height, width);

VerticalLines verticalLines = VerticalLines.create(width);
HorizontalLines horizontalLines = createHorizontalLines(verticalLines, height);

return new Ladder(verticalLines, horizontalLines);
}

private HorizontalLines createHorizontalLines(VerticalLines verticalLines, int height) {
HashSet<HorizontalLine> horizontalLineHashSet = new HashSet<>();

for (int i = 0; i < height; i++) {
Set<HorizontalLine> sameHeightHorizontalLineSet = createSameHeightHorizontalLineSet(verticalLines, i);
horizontalLineHashSet.addAll(sameHeightHorizontalLineSet);
}

return new HorizontalLines(horizontalLineHashSet, height);
}

private Set<HorizontalLine> createSameHeightHorizontalLineSet(VerticalLines verticalLines, int height) {
HashSet<HorizontalLine> sameHeightHorizontalLineHashSet = new HashSet<>();

for (int i = 0; i < verticalLines.getMaxWidth() - 1; i++) {
VerticalLine nowVerticalLine = verticalLines.getVerticalLineByIndex(i);
VerticalLine nextVerticalLine = verticalLines.getVerticalLineByIndex(i + 1);

boolean notExistPreviousHorizontalLine = sameHeightHorizontalLineHashSet.stream()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๋ ‡๊ฒŒ ๋‹ค ๋น„๊ตํ•ด์•ผ ํ• ๊นŒ์š” ? ์–ด์ฐจํ”ผ ์ˆœ์ฐจ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋Š”๊ฑฐ๋ผ๋ฉด ์ด์ „ ์นธ์—์„œ ์ƒ์„ฑ์„ ํ–ˆ๋Š”์ง€๋งŒ ํ™•์ธํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์•„์„œ์š”!

.noneMatch(horizontalLine ->
horizontalLine.getRightVerticalLine() == nowVerticalLine
);

if (notExistPreviousHorizontalLine && ladderGenerateStrategy.canGenerate()) {
sameHeightHorizontalLineHashSet.add(
new HorizontalLine(
new AdjacentVerticalLines(nowVerticalLine, nextVerticalLine),
height
)
);
}
}
return sameHeightHorizontalLineHashSet;
}

private void checkHeightAndWidth(int height, int width) {
if (height < HorizontalLine.MINIMUM_HEIGHT
|| width < Ladder.MINIMUM_VERTICAL_LINES_QUANTITY) {
throw new IllegalLadderParameterException(String.format("์ž…๋ ฅ๋œ ๋†’์ด : %d, ์ž…๋ ฅ๋œ ๋„ˆ๋น„ : %d", height, width));
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/ladder/domain/VerticalLine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ladder.domain;

public class VerticalLine {
private final int index;

public VerticalLine(int index) {
this.index = index;
}

public int getIndex() {
return index;
}
}
53 changes: 53 additions & 0 deletions src/main/java/ladder/domain/VerticalLines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ladder.domain;

import ladder.exception.IllegalVerticalLineWidthException;

import java.util.HashSet;
import java.util.Set;

public class VerticalLines {
private final Set<VerticalLine> verticalLineSet;
private final int maxWidth;

public VerticalLines(Set<VerticalLine> verticalLineSet, int maxWidth) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜น์‹œ maxWidth์™€ verticalLineSet์˜ ํฌ๊ธฐ๊ฐ€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”๊ฑธ๊นŒ์š”? ํ˜น์€ ๋‹ฌ๋ผ๋„ ๋˜๋Š”๊ฑด๊ฐ€์š” ?

checkValidVerticalLineWidth(verticalLineSet, maxWidth);

this.verticalLineSet = verticalLineSet;
this.maxWidth = maxWidth;
}

private void checkValidVerticalLineWidth(Set<VerticalLine> verticalLineSet, int maxWidth) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์š” ์œ ํšจ์„ฑ๊ฒ€์‚ฌ๊ฐ€ ์ •๋ง ํ•„์š”ํ•œ๊ฑธ๊นŒ์š” ?

if (verticalLineSet.stream()
.anyMatch(it -> it.getIndex() >= maxWidth)
) {
throw new IllegalVerticalLineWidthException(String.format("์ตœ๋Œ€ ๋„ˆ๋น„ : %d", maxWidth));
}
}

public Set<VerticalLine> getVerticalLineSet() {
return Set.copyOf(verticalLineSet);
}

public int getMaxWidth() {
return maxWidth;
}

public VerticalLine getVerticalLineByIndex(int index) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๋Ÿฐ ๋กœ์ง์ด ํ•„์š”ํ•˜๋‹ค๋ฉด Map์„ ์“ฐ๋Š”๊ฒŒ ๋‚ซ์ง€ ์•Š์„๊นŒ์š” ?

return verticalLineSet.stream()
.filter(it -> it.getIndex() == index)
.findFirst()
.orElse(null);
}

public int getSize() {
return verticalLineSet.size();
}

public static VerticalLines create(int count) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๋ถ€๋ถ„๋งŒ ๋”ฐ๋กœ ๋นผ๊ณ  ๊ทธ๋ƒฅ ์ƒ์„ฑ์ž์—์„œ count๋งŒํผ์˜ set์„ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š” ?

HashSet<VerticalLine> verticalLineHashSet = new HashSet<>();
for (int i = 0; i < count; i++) {
verticalLineHashSet.add(new VerticalLine(i));
}
return new VerticalLines(verticalLineHashSet, count);
}
}
Loading