Skip to content

260630_16_이혁#99

Open
hlee971001-rgb wants to merge 3 commits into
SurvivalCodingCampus:student/16_이혁from
hlee971001-rgb:master
Open

260630_16_이혁#99
hlee971001-rgb wants to merge 3 commits into
SurvivalCodingCampus:student/16_이혁from
hlee971001-rgb:master

Conversation

@hlee971001-rgb

@hlee971001-rgb hlee971001-rgb commented Jun 30, 2026

Copy link
Copy Markdown

260630_16_이혁

📝 과제 정보

인스턴스 기본 조작 연습문제 및 TIL

  • 교육 주제:

인스턴스 기본 조작

📋 체크리스트

  • 코드 컨벤션 준수 (Formatter 적용)
  • 모든 테스트 케이스 통과 (JUnit)

📷 실행 결과 (또는 테스트 결과)

4

❓질문 및 어려웠던 점

연습문제 코드를 만들려면 수업시간에 배운 내용을 바탕으로 새로운 것을 추가해야 하는데 추가를 해도 더 추가해야 하는 것들이 많아서 힘들었습니다.
또한 테스트 코드도 기존의 아는 수준에서는 완벽하게 코드를 만들 수 없어서 힘들었습니다.

🔄 자체 평가 & 회고

수업시간에 배운 내용을 바탕으로 추가해도 또 추가해야 할 내용들이 계속 나와서 어려운 것 같습니다.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

이번 PR에서는 인스턴스 기본 조작을 주제로 Book 클래스와 관련 테스트, 학습 정리 문서를 추가했습니다.

주요 변경

  • Book 클래스 추가

    • title, publishDate, comment 필드와 getter/setter 제공
    • equals()hashCode()titlepublishDate 기준으로 동등성 판단
    • compareTo()publishDate 기준 정렬 가능하도록 구현
    • clone()에서 publishDate는 깊은 복사되도록 처리
  • BookTest 추가

    • equals()/hashCode() 동작 검증
    • HashSet, HashMap에서의 동등성 처리 검증
    • Collections.sort()를 통한 정렬 결과 검증
    • clone() 복제 시 값 복사와 참조 분리, 날짜의 깊은 복사 검증
  • TIL 문서 추가

    • toString(), equals(), hashCode()의 역할 정리
    • List/Set 컬렉션 특징 정리
    • Comparable, compareTo()와 정렬 개념 정리
    • 얕은 복사/깊은 복사 개념과 Book 예시 정리

확인 사항

  • JUnit 테스트 실행이 성공적으로 완료되었습니다.

Walkthrough

Book 클래스를 새로 추가하여 Cloneable, Comparable<Book>을 구현했다. equals/hashCodetitlepublishDate만 사용하며, compareTo는 출간일 내림차순, clonepublishDate를 깊은 복사한다. 이를 검증하는 BookTest와 관련 TIL 문서가 함께 추가되었다.

Changes

Book 클래스 구현 및 테스트

Layer / File(s) Summary
Book 클래스 구현
2026-06-30/src/main/java/com/survivalcoding/Book.java
title, publishDate, comment 필드와 getter/setter를 추가하고, equals/hashCodetitle+publishDate 기준, compareTo는 출간일 내림차순, clonepublishDate 깊은 복사로 구현한다.
BookTest 및 TIL 문서
2026-06-30/src/test/java/com/survivalcoding/BookTest.java, TIL/sample/2026-06-30-인스턴스 기본 조작.md
equals/hashCode 동작, HashSet·HashMap 키 중복 처리, Collections.sort() 내림차순 정렬, clone() 얕은/깊은 복사 여부를 테스트하고, 관련 개념을 TIL 문서로 정리한다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive 제목은 과제 식별자와 이름만 있어 변경 내용을 설명하지 못해 다소 모호합니다. 주요 변경을 드러내도록 예: 'Book 클래스와 BookTest 추가'처럼 핵심 기능을 한 문장으로 적어주세요.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed 필수 섹션들이 대부분 채워져 있고 체크리스트, 실행 결과, 질문/회고까지 포함되어 템플릿을 잘 따릅니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@2026-06-30/src/main/java/com/survivalcoding/Book.java`:
- Around line 49-52: `Book.compareTo()` currently orders only by `publishDate`,
which can make different books compare as equal and also throws on null dates.
Update `compareTo(Book other)` in `Book` to use a null-safe, multi-field
comparison that includes `title` as a tiebreaker and aligns better with
`equals()`. Keep the comparison logic centralized in `Book` so
`TreeSet`/`TreeMap` won’t collapse distinct books with the same publish date.
- Around line 7-8: `Book`의 `title`과 `publishDate`가
`equals()`/`hashCode()`/`compareTo()` 기준인데 외부에서 변경될 수 있으니 불변으로 고정하세요. `Book`
클래스의 필드를 `final`로 만들고, `publishDate`는 생성 시 방어적 복사를 적용하며 getter에서도 내부 `Date` 원본을
직접 반환하지 않도록 수정하세요. 필요하면 `Book` 생성자와 `getPublishDate()`를 함께 조정해 컬렉션에 들어간 뒤 상태가
바뀌지 않게 하세요.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ff623dd7-73e5-4081-9cee-8637021f43e9

📥 Commits

Reviewing files that changed from the base of the PR and between 998ecfa and a9e00b1.

📒 Files selected for processing (3)
  • 2026-06-30/src/main/java/com/survivalcoding/Book.java
  • 2026-06-30/src/test/java/com/survivalcoding/BookTest.java
  • TIL/sample/2026-06-30-인스턴스 기본 조작.md

Comment on lines +7 to +8
private String title;
private Date publishDate;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

git ls-files '2026-06-30/src/main/java/com/survivalcoding/Book.java' \
             '2026-06-30/src/test' \
             '2026-06-30/src/main/java/com/survivalcoding' | sed -n '1,200p'

echo '--- Book.java outline ---'
ast-grep outline 2026-06-30/src/main/java/com/survivalcoding/Book.java --view expanded || true

echo '--- Book.java excerpt ---'
wc -l 2026-06-30/src/main/java/com/survivalcoding/Book.java
sed -n '1,220p' 2026-06-30/src/main/java/com/survivalcoding/Book.java

echo '--- usages of Book in tests/source ---'
rg -n --hidden --glob '!**/target/**' --glob '!**/build/**' '\bBook\b' 2026-06-30/src/main/java 2026-06-30/src/test || true

echo '--- Set/Map usage around Book ---'
rg -n --hidden --glob '!**/target/**' --glob '!**/build/**' 'new (HashSet|HashMap|TreeSet|TreeMap)<|Set<|Map<' 2026-06-30/src/main/java 2026-06-30/src/test || true

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 5266


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- BookTest outline ---'
ast-grep outline 2026-06-30/src/test/java/com/survivalcoding/BookTest.java --view expanded || true

echo '--- BookTest excerpt ---'
wc -l 2026-06-30/src/test/java/com/survivalcoding/BookTest.java
sed -n '1,260p' 2026-06-30/src/test/java/com/survivalcoding/BookTest.java

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 6130


title/publishDate는 불변으로 고정하세요. equals()/hashCode()/compareTo() 기준인데 둘 다 외부에서 바뀔 수 있고, 특히 publishDate는 getter가 Date 원본을 그대로 노출합니다. HashSet/HashMap/정렬된 컬렉션에 들어간 뒤 값이 바뀌면 조회와 정렬 기준이 깨집니다.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@2026-06-30/src/main/java/com/survivalcoding/Book.java` around lines 7 - 8,
`Book`의 `title`과 `publishDate`가 `equals()`/`hashCode()`/`compareTo()` 기준인데 외부에서
변경될 수 있으니 불변으로 고정하세요. `Book` 클래스의 필드를 `final`로 만들고, `publishDate`는 생성 시 방어적 복사를
적용하며 getter에서도 내부 `Date` 원본을 직접 반환하지 않도록 수정하세요. 필요하면 `Book` 생성자와
`getPublishDate()`를 함께 조정해 컬렉션에 들어간 뒤 상태가 바뀌지 않게 하세요.

Comment on lines +49 to +52
@Override
public int compareTo(Book other) {
return other.publishDate.compareTo(this.publishDate);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the file and map its structure first
git ls-files '2026-06-30/src/main/java/com/survivalcoding/Book.java'
ast-grep outline 2026-06-30/src/main/java/com/survivalcoding/Book.java --view expanded || true

# Show the file with line numbers
wc -l 2026-06-30/src/main/java/com/survivalcoding/Book.java
cat -n 2026-06-30/src/main/java/com/survivalcoding/Book.java

# Search for usages/related methods in the same package
rg -n "compareTo\\(|equals\\(|publishDate|title" 2026-06-30/src/main/java/com/survivalcoding -g '*.java'

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 4242


compareTo()equals()와 다른 기준을 쓰고 publishDate null도 처리하지 않습니다.
publishDate만 비교해서 같은 날짜의 서로 다른 책이 0이 될 수 있어 TreeSet/TreeMap에서 항목이 합쳐집니다. other.publishDate.compareTo(this.publishDate)는 양쪽 값이 null이면 바로 NPE도 발생합니다. title까지 포함한 null-safe 비교로 맞추세요.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@2026-06-30/src/main/java/com/survivalcoding/Book.java` around lines 49 - 52,
`Book.compareTo()` currently orders only by `publishDate`, which can make
different books compare as equal and also throws on null dates. Update
`compareTo(Book other)` in `Book` to use a null-safe, multi-field comparison
that includes `title` as a tiebreaker and aligns better with `equals()`. Keep
the comparison logic centralized in `Book` so `TreeSet`/`TreeMap` won’t collapse
distinct books with the same publish date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant