Skip to content

Commit c727b99

Browse files
committed
Fix : Rectangle 예외 메시지 수정 및 접근 제어자 변경
1 parent 589b963 commit c727b99

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main/java/coordinate/domain/Rectangle.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public Rectangle(String expression) {
1818
}
1919

2020
if (expression.split(REGEX).length != 4) {
21-
throw new IllegalArgumentException("좌표는 두개 만 들어가야 합니다.");
21+
throw new IllegalArgumentException("좌표는 네 개 만 들어가야 합니다.");
2222
}
2323

2424
List<Coordinate> coordinateList = Arrays.asList(
@@ -28,16 +28,18 @@ public Rectangle(String expression) {
2828
new Coordinate(expression.split(REGEX)[3])
2929
);
3030

31-
if (coordinateList.stream().map(Coordinate::getX).distinct().count() != 2) {
32-
throw new IllegalArgumentException();
33-
}
31+
List<Double> distanceList = Arrays.asList(
32+
getDistance(coordinateList.get(0), coordinateList.get(1)),
33+
getDistance(coordinateList.get(1), coordinateList.get(2)),
34+
getDistance(coordinateList.get(2), coordinateList.get(3)),
35+
getDistance(coordinateList.get(3), coordinateList.get(0))
36+
);
3437

35-
if (coordinateList.stream().map(Coordinate::getY).distinct().count() != 2) {
38+
if (distanceList.stream().distinct().count() != 2) {
3639
throw new IllegalArgumentException();
3740
}
3841

3942
this.coordinates = coordinateList;
40-
4143
}
4244

4345
@Override
@@ -62,7 +64,7 @@ public List<Coordinate> findCoordinates() {
6264
return new ArrayList<>(coordinates);
6365
}
6466

65-
public double getDistance(Coordinate coordinate, Coordinate otherCoordinate) {
67+
private double getDistance(Coordinate coordinate, Coordinate otherCoordinate) {
6668
return Math.sqrt(
6769
abs((coordinate.getX() - otherCoordinate.getX()) * (coordinate.getX() - otherCoordinate.getX())
6870
+ (coordinate.getY() - otherCoordinate.getY()) * (coordinate.getY() - otherCoordinate.getY())));

0 commit comments

Comments
 (0)