-
Notifications
You must be signed in to change notification settings - Fork 708
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
π 2λ¨κ³ - μ¬λ€λ¦¬(μμ±) #2120
base: sang5c
Are you sure you want to change the base?
Changes from 30 commits
f851cb7
f887f8a
0c09d1e
f6311a6
066ce9d
1adfd82
dff1072
85f0fcc
ad63923
2368cef
7f26af3
7b8e81d
fab1fe5
9427f15
6929a1f
53309ed
e3bdceb
5f53b78
73d2e59
99c8db7
d10073d
e4da849
a241c10
9d2ef6c
82cb335
82abe22
6aaabc1
7e1e4ec
1b2b225
30de861
439d1cc
6498f49
a8a84a8
9ad91e8
9a91a2f
4a9ad30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,48 @@ | ||
# μ¬λ€λ¦¬ κ²μ | ||
|
||
## μ§ν λ°©λ² | ||
|
||
* μ¬λ€λ¦¬ κ²μ κ²μ μꡬμ¬νμ νμ νλ€. | ||
* μꡬμ¬νμ λν ꡬνμ μλ£ν ν μμ μ github μμ΄λμ ν΄λΉνλ λΈλμΉμ Pull Request(μ΄ν PR)λ₯Ό ν΅ν΄ μ½λ 리뷰 μμ²μ νλ€. | ||
* μ½λ 리뷰 νΌλλ°±μ λν κ°μ μμ μ νκ³ λ€μ PUSHνλ€. | ||
* λͺ¨λ νΌλλ°±μ μλ£νλ©΄ λ€μ λ¨κ³λ₯Ό λμ νκ³ μμ κ³Όμ μ λ°λ³΅νλ€. | ||
|
||
## μ¨λΌμΈ μ½λ 리뷰 κ³Όμ | ||
* [ν μ€νΈμ μ΄λ―Έμ§λ‘ μ΄ν΄λ³΄λ μ¨λΌμΈ μ½λ 리뷰 κ³Όμ ](https://github.com/nextstep-step/nextstep-docs/tree/master/codereview) | ||
|
||
* [ν μ€νΈμ μ΄λ―Έμ§λ‘ μ΄ν΄λ³΄λ μ¨λΌμΈ μ½λ 리뷰 κ³Όμ ](https://github.com/nextstep-step/nextstep-docs/tree/master/codereview) | ||
|
||
--- | ||
|
||
## Step 2. μ¬λ€λ¦¬(μμ±) | ||
|
||
### κΈ°λ₯ μꡬμ¬ν | ||
|
||
- μ¬λ€λ¦¬ κ²μμ μ°Έμ¬νλ μ¬λμ μ΄λ¦μ μ΅λ5κΈμκΉμ§ λΆμ¬ν μ μλ€. μ¬λ€λ¦¬λ₯Ό μΆλ ₯ν λ μ¬λ μ΄λ¦λ κ°μ΄ μΆλ ₯νλ€. | ||
- μ¬λ μ΄λ¦μ μΌν(,)λ₯Ό κΈ°μ€μΌλ‘ ꡬλΆνλ€. | ||
- μ¬λ μ΄λ¦μ 5μ κΈ°μ€μΌλ‘ μΆλ ₯νκΈ° λλ¬Έμ μ¬λ€λ¦¬ νλ λμ΄μ ΈμΌ νλ€. | ||
- μ¬λ€λ¦¬ νκΈ°κ° μ μμ μΌλ‘ λμνλ €λ©΄ λΌμΈμ΄ κ²ΉμΉμ§ μλλ‘ ν΄μΌ νλ€. | ||
- |-----|-----| λͺ¨μκ³Ό κ°μ΄ κ°λ‘ λΌμΈμ΄ κ²ΉμΉλ κ²½μ° μ΄λ λ°©ν₯μΌλ‘ μ΄λν μ§ κ²°μ ν μ μλ€. | ||
|
||
### νλ‘κ·Έλλ° μꡬμ¬ν | ||
|
||
- μλ° 8μ μ€νΈλ¦Όκ³Ό λλ€λ₯Ό μ μ©ν΄ νλ‘κ·Έλλ°νλ€. | ||
- κ·μΉ 6: λͺ¨λ μν°ν°λ₯Ό μκ² μ μ§νλ€. | ||
|
||
### μꡬμ¬ν λΆμ | ||
|
||
- [X] μ°Έκ°μλ μ΄λ¦μ κ°λλ€. | ||
- [X] μ΄λ¦μ μ΅λ 5μμ΄λ€. | ||
- [X] μ΄λ¦μ΄ λΉμ΄μκ±°λ 6μ μ΄μμ΄λ©΄ μμΈκ° λ°μνλ€. | ||
- [ ] μ¬λ€λ¦¬ | ||
- [X] μ¬λ€λ¦¬μ κ°λ‘ λΌμΈμ μλ₯Ό μ€μ ν μ μλ€. (λμ΄) | ||
- [X] μ¬λ€λ¦¬μ μΈλ‘ λΌμΈμ μ¬λ μ λ§νΌ μμ±λλ€. (λλΉ) | ||
- [X] μ¬λ€λ¦¬μ κ° κ°λ‘ λΌμΈμλ μ¬λ μ λ§νΌ ν¬μΈνΈ(μ )κ° μμ±λλ€. | ||
- [X] μ’, μ°μ ν¬μΈνΈκ° μ‘΄μ¬νλ κ²½μ° μ΄λν μ μλ€. | ||
- [X] κ°μ₯ μΌμͺ½ ν¬μΈνΈμμλ μ’λ‘ μ΄λ λΆκ°νλ€. | ||
- [X] κ°μ₯ μ€λ₯Έμͺ½ ν¬μΈνΈμμλ μ°λ‘ μ΄λ λΆκ°νλ€. | ||
- [X] μ°μμΌλ‘ μ΄λ κ°λ₯ν ν¬μΈνΈλ μ‘΄μ¬ν μ μλ€. -> μ’ μ° λͺ¨λ μ΄λ κ°λ₯ν ν¬μΈνΈλ μ‘΄μ¬ν μ μλ€ | ||
- [ ] ν¬μΈνΈ | ||
- [X] μ’, μ° λͺ¨λ μ΄λ κ°λ₯ν ν¬μΈνΈλ μ‘΄μ¬ν μ μλ€. μΈ κ°μ§ κ²½μ°λ§ μ‘΄μ¬νλ€. | ||
- [X] μ’ μ΄λ λΆκ°, μ° μ΄λ λΆκ° | ||
- [X] μ’ μ΄λ κ°λ₯, μ° μ΄λ λΆκ° | ||
- [X] μ’ μ΄λ λΆκ°, μ° μ΄λ κ°λ₯ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#Sat Apr 06 16:04:18 KST 2024 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package nextstep.ladder; | ||
|
||
import nextstep.ladder.domain.LadderGame; | ||
import nextstep.ladder.util.ConsoleUtil; | ||
|
||
import java.util.List; | ||
|
||
public class LadderGameApplication { | ||
|
||
public static void main(String[] args) { | ||
List<String> playerNames = ConsoleUtil.inputPlayerNames(); | ||
int height = ConsoleUtil.inputHeight(); | ||
|
||
LadderGame ladderGame = LadderGame.start(playerNames, height); | ||
|
||
ConsoleUtil.printGameResults(ladderGame); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package nextstep.ladder.domain; | ||
|
||
import java.util.List; | ||
|
||
public class LadderGame { | ||
|
||
private final Players players; | ||
private final Lines lines; | ||
|
||
private LadderGame(final Players players, final Lines lines) { | ||
this.players = players; | ||
this.lines = lines; | ||
} | ||
|
||
public static LadderGame start(List<String> playerNames, int height) { | ||
Players players = Players.of(playerNames); | ||
Lines lines = Lines.of(players.count(), height); | ||
|
||
return new LadderGame(players, lines); | ||
} | ||
|
||
public Players getPlayers() { | ||
return players; | ||
} | ||
|
||
public Lines getLines() { | ||
return lines; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package nextstep.ladder.domain; | ||
|
||
import java.util.List; | ||
|
||
public class Line { | ||
private final List<Point> points; | ||
|
||
Line(List<Point> points) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν©ν λ¦¬λ‘ μ¬μ©νκΈ° μν΄ default λ‘ μ μΈνμ κ±ΈκΉμ? π There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. κ°μ¬ν©λλ€ |
||
validate(points); | ||
this.points = points; | ||
} | ||
|
||
private void validate(List<Point> points) { | ||
validatePointsListSize(points); | ||
validatePointMovements(points); | ||
} | ||
|
||
private void validatePointsListSize(List<Point> points) { | ||
if (points == null || points.isEmpty()) { | ||
throw new IllegalArgumentException("μ μ΄ μμ΅λλ€."); | ||
} | ||
|
||
if (points.size() < 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ¬κΈ°λ 맀μ§λλ²κ° μ¬μ©λμμ΄μ. λ€λ§ ν΄λΉ κ°μ μ¬λ€λ¦¬ κ²μμμλ λΆλ³μ μ§λ¦¬μ κ°κΉμ΄ κ°μ΄λΌ κ΅¬μ§ μμλ‘ μ μΈν΄μΌν κΉ κ³ λ―Όμ΄ μλ€μ. μμλ‘ μ μΈνμλ μ€νλ € λ€μ΄λ°μ μ νμ§ μμμ κ²½μ° νκ°λ¦΄ μ μμ§ μμκΉ μΆμ΄μμ! μμ€λ μκ°μ΄ κΆκΈνλ€μ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ½λ μΌκ΄μ±κ³Ό μλ¬ λ©μμ§ (μ§μ μ name.legnth()μ κ°μ μ΄μ λ‘)μμ λμΌν κ°μ΄ μ°μΌ μ μλλ‘ μμλ‘ λΆλ¦¬νμ΅λλ€. μλ₯Ό λ€μ΄ "μ°Έμ¬μκ° νλͺ
μΌ μ μλ€" λλ "μΈ λͺ
μ΄μμ΄μ΄μΌ κ²μμ΄ κ°λ₯νλ€"λ±μΌλ‘ μΆκ° μꡬμ¬νμ΄ μκΈ΄λ€λ©΄ μ£Όμ
λ°λ ννλ‘ κ΅¬μ±ν΄μΌ νλ€κ³ λκΌμ΅λλ€. |
||
throw new IllegalArgumentException("μ μ΄ λ κ° μ΄μ μμ΄μΌ ν©λλ€."); | ||
} | ||
} | ||
|
||
private void validatePointMovements(List<Point> points) { | ||
if (firstPoint(points).canMoveLeft() || lastPoint(points).canMoveRight()) { | ||
throw new IllegalArgumentException("첫 μ μμλ μΌμͺ½μΌλ‘ μ΄λν μ μκ³ , λ§μ§λ§ μ μμλ μ€λ₯Έμͺ½μΌλ‘ μ΄λν μ μμ΅λλ€."); | ||
} | ||
|
||
for (int i = 0; i < points.size() - 1; i++) { | ||
assertConsecutivePointsAreMovable(points, i); | ||
} | ||
} | ||
|
||
private void assertConsecutivePointsAreMovable(List<Point> points, int i) { | ||
if (points.get(i).canMoveRight() && !points.get(i + 1).canMoveLeft()) { | ||
throw new IllegalArgumentException("μ°μλ μ μμλ μλ‘ μ΄λ κ°λ₯ν΄μΌ ν©λλ€."); | ||
} | ||
} | ||
|
||
private Point firstPoint(List<Point> points) { | ||
return points.get(0); | ||
} | ||
|
||
private Point lastPoint(List<Point> points) { | ||
return points.get(points.size() - 1); | ||
} | ||
|
||
public int width() { | ||
return points.size(); | ||
} | ||
|
||
public Point getPoint(int index) { | ||
return points.get(index); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package nextstep.ladder.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class LineBuilder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LineBuilder ν΄λμ€μ μμΉμ λν΄ κ³ λ―Όμ΄ λ§μμ΅λλ€. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν©ν 리λ₯Ό μ¨μ μ»κ³ μ νλ μ΄λμ΄ λ¬΄μμΈκ°μ? π€ π There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ κ° μκ°νλ ν©ν 리μ μ₯μ μ μλ μ λμΈλ° ν΄λΉμ¬νμ΄ μλκ² κ°μμμ π€ κ°μ²΄ μμ±μ μ‘°κ±΄μ΄ μμ λ: κ°μ²΄λ₯Ό μμ±ν λ 쑰건μ λ°λΌ λ€λ₯Έ μ’ λ₯μ κ°μ²΄λ₯Ό μμ±ν΄μΌ νλ κ²½μ°, ν©ν 리 ν¨ν΄μ μ¬μ©νμ¬ μ‘°κ±΄μ λ°λΌ μ μ ν κ°μ²΄λ₯Ό λ°νν μ μμ΅λλ€. ꡬνμ λ³κ²½ν νμκ° μμ λ: μΈν°νμ΄μ€λ₯Ό ν΅ν΄ μ¬λ¬ ꡬν ν΄λμ€ μ€ νλλ₯Ό μ νν΄μ μ¬μ©ν μ μλλ‘ νμ¬, μΆν ꡬνμ λ³κ²½ν λ κΈ°μ‘΄ μ½λλ₯Ό μμ νμ§ μκ³ λ μλ‘μ΄ κ΅¬νμ μ½κ² μΆκ°ν μ μμ΅λλ€. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν΄λΉ ν΄λμ€λ₯Ό ν΅ν΄ λ κ°μ§λ₯Ό ν λ²μ λ¬μ€νλ €κ³ νμμ΅λλ€ π
μ΄λ° μνμμ λμ€μ μ΄λμ΄ μ§μ κ°λ₯ν Lineμ λ§λ€ μꡬμ¬νμ΄ μκΈ°μ§ μμκΉ? λΌλ μκ°μΌλ‘ μ 맀λͺ¨νΈν ν΄λμ€κ° νμνλ κ² κ°μ΅λλ€. μ΄ λΆλΆμ μ± μμ λΆλ¦¬(RandomGenerator, Builder)νμ¬ μλ‘ κ΅¬μ±νμΌλ νμΈ λΆνλ립λλ€! |
||
|
||
private static final Random RANDOM = new Random(); | ||
|
||
private final List<Point> points = new ArrayList<>(); | ||
|
||
public static Line buildWithRandomPoints(int count) { | ||
return new LineBuilder().initRandomMoveablePoint() | ||
.addRandomMoveablePoints(count - 2) | ||
.build(); | ||
} | ||
|
||
private Line build() { | ||
points.add(lastPoint().createRightmost()); | ||
return new Line(points); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν΄λμ€μ μ΄λ¦μ΄ λΉλμΈλ° λΉλν¨μκ° private νκ² μ μΈλλ©΄ μ¬μ©ν λ νκ°λ¦¬μ§ μμκΉμ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ΄μ λ¦¬λ·°μΈ #2120 (comment) μ λκΈμ΄ μλ¬λ € μ΄κ³³μ νλ²μ λ΅λ³λ립λλ€!
μ΅μ΄ μμ± μλλ ν©ν 리λ₯Ό ν΅ν΄ μνλ ννλ‘(manual) μμ±νκ±°λ, λλ€(auto)νκ² μμ±νλ€. λ₯Ό λͺ©νλ‘ νμμ΅λλ€.
νμ¬λ μνλ ννλ‘ μμ±(manual)μ λν μꡬμ¬νμ΄ μμΌλ λ§μμΌ νμ§ μμκΉ? λΌλ μκ°κ³Ό λμ€μ μ§μ λΌμΈμ ꡬμ±ν μ μλ€λ μꡬμ¬νμ΄ μκ²Όμ λλ₯Ό μν΄ build()λ₯Ό λκ³ μ΄λ₯Ό publicμΌλ‘ μ΄λ©΄ λμ§ μμκΉ? λΌλ μ¬λ¬κ°μ§ μκ°μ΄ κ²°ν©λμ΄ μ 맀ν μ½λκ° λμμ΅λλ€ γ γ κ²°κ΅ λΉλμ μ λλ μ΄ν°μ μ± μμ λΆλ¦¬νκ³ build() λ©μλλ publicμΌλ‘ μ μ©νμ΅λλ€ :) |
||
|
||
private LineBuilder addRandomMoveablePoints(int numberOfMiddlePoints) { | ||
for (int i = 0; i < numberOfMiddlePoints; i++) { | ||
Point point = lastPoint().createNext(RANDOM.nextBoolean()); | ||
points.add(point); | ||
} | ||
return this; | ||
} | ||
|
||
private LineBuilder initRandomMoveablePoint() { | ||
points.add(Point.createLeftmost(RANDOM.nextBoolean())); | ||
return this; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ λ¨κ³λ₯Ό λλ μ΄μ κ° κΆκΈν΄μ! μλμκ°μ΄ νλ¨κ³λ‘ μ¬μ©νλκ²μ΄ λ νΈλ¦¬νμ§ μμκΉμ? π€ (μ κ° μλ°λ₯Ό μ€λλ§μ μ°κ³ + IDEμ΄ νκ²½μ΄ μλλΌμ λ¬Έλ²μ€λ₯ μν΄λΆνλ릴κ²μ) private LineBuilder create(int count) {
Point current = Point.createLeftmost(RANDOM.nextBoolean())
potins.add(current)
for (int i = 0; i < count - 2; i++) {
current = current.next()
potins.add(current()
}
}
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 첫 λ²μ§Έ ν¬μΈνΈμ μΆκ° λ°©μμ΄ λ€λ₯΄λ€λ κ²μ λͺ μμ μΌλ‘ λνλ΄κ³ μΆμμ΅λλ€. μ΄μ λκΈκ³Ό λ§μ°¬κ°μ§λ‘ builder λΆλ¦¬λ₯Ό μ§ννκ³ λ‘μ§μ΄ νλλ‘ ν΅ν©λμμ΅λλ€! |
||
|
||
private Point lastPoint() { | ||
return points.get(points.size() - 1); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||
package nextstep.ladder.domain; | ||||||||
|
||||||||
import java.util.List; | ||||||||
import java.util.stream.Collectors; | ||||||||
import java.util.stream.IntStream; | ||||||||
|
||||||||
public class Lines { | ||||||||
|
||||||||
private final List<Line> lines; | ||||||||
|
||||||||
private Lines(List<Line> lines) { | ||||||||
validate(lines); | ||||||||
this.lines = lines; | ||||||||
} | ||||||||
|
||||||||
private void validate(List<Line> lines) { | ||||||||
if (lines == null || lines.isEmpty()) { | ||||||||
throw new IllegalArgumentException("μ¬λ€λ¦¬ λμ΄λ 1 μ΄μμ΄μ΄μΌ ν©λλ€."); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
public static Lines of(int numberOfPlayers, int height) { | ||||||||
List<Line> lines = IntStream.range(0, height) | ||||||||
.mapToObj(i -> LineBuilder.buildWithRandomPoints(numberOfPlayers)) | ||||||||
.collect(Collectors.toList()); | ||||||||
return new Lines(lines); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ κ° μλ°λ₯Ό μμ΄μ§ μ€λλμ κ°λ¬Ό κ°λ¬Όνμ§λ§.... μλμ κ°μ΄ νλ²μ μ¬μ©ν μ μμ΄μ.
Suggested change
|
||||||||
} | ||||||||
|
||||||||
public int getHeight() { | ||||||||
return lines.size(); | ||||||||
} | ||||||||
|
||||||||
public Line getLine(int targetHeight) { | ||||||||
return lines.get(targetHeight); | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package nextstep.ladder.domain; | ||
|
||
public class Player { | ||
private final String name; | ||
|
||
public Player(String name) { | ||
validate(name); | ||
this.name = name; | ||
} | ||
|
||
private void validate(String name) { | ||
if (name == null || name.isEmpty()) { | ||
throw new IllegalArgumentException("μ΄λ¦μ λΉμ΄μμ μ μμ΅λλ€."); | ||
} | ||
|
||
if (name.length() > 5) { | ||
throw new IllegalArgumentException("μ΄λ¦μ 5μ μ΄νμ¬μΌ ν©λλ€."); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ§€μ§ λλ²κ° μ¬μ©λμλ€μ. "μ΄λ¦μ " + MAX_NAME_LENGTH +"μ μ΄νμ¬μΌ ν©λλ€." μ μ²λΌ μμΈμμλ μ¬μ©νλ€λ©΄ μ¬μ΄λ μ΄ννΈλ μ€μΌ μ μκ² λ€μ! |
||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package nextstep.ladder.domain; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class Players { | ||
private final List<Player> players; | ||
|
||
private Players(List<Player> players) { | ||
validate(players); | ||
this.players = players; | ||
} | ||
|
||
private void validate(List<Player> players) { | ||
if (players == null || players.isEmpty()) { | ||
throw new IllegalArgumentException("μ°Έκ°μκ° μμ΅λλ€."); | ||
} | ||
} | ||
|
||
public static Players of(List<String> playerNames) { | ||
List<Player> players = playerNames.stream() | ||
.map(Player::new) | ||
.collect(Collectors.toList()); | ||
|
||
return new Players(players); | ||
} | ||
|
||
public int count() { | ||
return players.size(); | ||
} | ||
|
||
public Player getPlayer(int index) { | ||
return players.get(index); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package nextstep.ladder.domain; | ||
|
||
public class Point { | ||
private final boolean left; | ||
private final boolean right; | ||
|
||
public Point(boolean left, boolean right) { | ||
validate(left, right); | ||
this.left = left; | ||
this.right = right; | ||
} | ||
|
||
private void validate(boolean left, boolean right) { | ||
if (left && right) { | ||
throw new IllegalArgumentException("μ’ μ° λͺ¨λ μ΄λ κ°λ₯ν Point μμ± λΆκ°"); | ||
} | ||
} | ||
|
||
public static Point createLeftmost(boolean canMoveRight) { | ||
return new Point(false, canMoveRight); | ||
} | ||
|
||
public Point createRightmost() { | ||
return new Point(this.right, false); | ||
} | ||
|
||
public Point createNext(boolean canMoveRight) { | ||
return new Point(this.right, !this.right && canMoveRight); | ||
} | ||
|
||
public boolean canMoveLeft() { | ||
return left; | ||
} | ||
|
||
public boolean canMoveRight() { | ||
return right; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ―Έμ λ€μ μμν λ 리뷰μμ²μ μΌλμ λμ§ μκ³ μ§νν΄μ μλ° λ²μ μ λ°κΏ¨μλλ°μ!
νΉμ λ²μ λ€μ΄μ΄ νμνλ©΄ λ΄λ¦¬κ³ λ€μ μμ²λλ¦¬κ² μ΅λλ€!