Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions TIL/sample/2026-06-30-정리.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 2026-06-30

## 오늘 배운 내용
검색이 LISt는 느려 || SET/MAP은 빠르다
h1 == h2 는 서로 다른 주소이므로 '=='가 들어갔어도 비교는 equals로 한다
ㄴ> 비교하는 코드 틀 :: [h1.compareTo(h2)]
[equals() 특징] :: equals가 있으면 같은 내용은 지워진다
Comment on lines +5 to +7

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

equals, compareTo, Set 중복 규칙 설명이 서로 섞여 있습니다.

compareTo() 는 정렬 기준 비교이고, "같은 내용은 지워진다" 는 Set 에서 equals()hashCode() 가 함께 일관될 때의 동작입니다. 지금 문구대로면 Book2 같은 예제의 동등성 계약을 잘못 학습하기 쉽습니다.

✏️ 문구 예시
-h1 == h2 는 서로 다른 주소이므로 '=='가 들어갔어도 비교는  equals로 한다
-ㄴ> 비교하는 코드 틀 :: [h1.compareTo(h2)]
-[equals() 특징] :: equals가 있으면 같은 내용은 지워진다
+h1 == h2 는 참조 비교이고, 내용 비교는 equals()를 사용한다
+ㄴ> compareTo()는 정렬/대소 비교가 필요할 때 사용한다
+[equals()/hashCode() 특징] :: Set/Map에서 같은 값으로 취급되려면 둘 다 일관되어야 한다
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
h1 == h2 는 서로 다른 주소이므로 '=='가 들어갔어도 비교는 equals로 한다
ㄴ> 비교하는 코드 틀 :: [h1.compareTo(h2)]
[equals() 특징] :: equals가 있으면 같은 내용은 지워진다
h1 == h2 는 참조 비교이고, 내용 비교는 equals()를 사용한다
ㄴ> compareTo()는 정렬/대소 비교가 필요할 때 사용한다
[equals()/hashCode() 특징] :: Set/Map에서 같은 값으로 취급되려면 둘 다 일관되어야 한다
🤖 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 `@TIL/sample/2026-06-30-정리.md` around lines 5 - 7, 정리 문구가 equals, compareTo,
Set 중복 규칙을 혼동하고 있으니, 해당 메모에서 각 개념을 분리해 수정하세요. compareTo는 정렬/비교 기준 설명으로만 남기고, “같은
내용은 지워진다”는 문장은 Set에서 equals와 hashCode가 함께 일관될 때의 중복 제거로 바꿔 쓰세요. Book2 같은 예제가 있다면
equals/compareTo/HashSet 동작을 각각 구분해서 설명하도록 문구를 정리하세요.


[얕은 복사 (주소만 복사) || 깊은 복사(주소 달라, 내용 같아)]
[얕은 복사 코드의 틀 ] :: Book h2 = h1.clone();
[깊은 복사 코드의 틀 ] :: copy.author = this.author.clone();

[ 단축키 ]

- Ctrl+Alt :: 함수가 작성된 실제 위치로 이동
- Ctrl+B :: 함수 자세히 보기
- Ctrl+H :: 상속관계 보기
- shift + F6 :: 이미 정해진 클래스 함수의 이름을 전체 변경하려 할때
- Alt+Enter :: 자동생성
- ctrl+shift+T :: TEST 파일 생성

## 실습 코드

```java
public class Cleric {


}
2 changes: 1 addition & 1 deletion game/june22th.puml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@startuml
scale 1
scale 0.7
abstract class Asset {
- String name;
+ Asset(String name)
Expand Down
80 changes: 80 additions & 0 deletions game/june23th.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@startuml
'https://plantuml.com/sequence-diagram
size 0.5


class Medic{
- int healing
}
class Marine{
-int damege
}
class Trank{
-int damage
}
class Vulture{
-int damage
}
class Scv{
-int damage
}
class Zergling{
-int damage
}
class Hydra{
- int damege
}
class Dragun{
-int damege
}
class Zealot{
- int damege
Comment on lines +9 to +31

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

클래스/필드 이름 오타가 다이어그램 의미를 흐립니다.

Trank, Dragun, damege 같은 표기가 여러 군데 섞여 있어 렌더링 결과만 봐도 도메인 용어가 불안정해 보입니다. 학습용 산출물이라도 용어를 한 번 정리해 두는 편이 이후 코드/테스트 이름과 맞추기 쉽습니다.

🤖 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 `@game/june23th.puml` around lines 9 - 31, The UML names and field identifiers
are inconsistent and contain typos, so clean up the domain terminology across
the class declarations in this diagram. Rename the misspelled class names and
attributes in the PlantUML snippet (for example, align symbols like
Trank/Dragun/damege with the intended game-unit and damage naming) so the
diagram uses one stable vocabulary throughout. Keep the changes localized to the
affected class definitions so the rendered model matches the corrected
identifiers everywhere.

}


interface cure{
+ int getHeal()
+ void setHeal(int healing)
}

interface unit{}

interface Mechanic{
+repairable()
}

interface Fix{
+int getFix()
+void setFix(int damege)
}

interface Attack{}

abstract Terran{
-String name
-int HP
}

abstract Zerg{
-String name
-int HP
}

abstract Protoss{
-String name
-int HP
}

interface Bionic{}

interface Mineral{}

interface NoLiving{}

interface Structure{}

interface Moveable{}



@enduml
19 changes: 19 additions & 0 deletions game/june30th.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@startuml


+ class Book2 {
- String title;
- Data publishDate;
- String comment;

+ String getTitle()
+ void setTitle(String title)
+ Data getPublishDate()
+ void setPublishDate(Data publishDate)
+ String getComment()
+ void setComment(String comment)


}

@enduml
78 changes: 78 additions & 0 deletions game/src/main/java/com/survivalcoding/Book2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.survivalcoding;
import javax.xml.crypto.Data;
import java.util.Objects;
Comment on lines +2 to +3

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

printf '\n== Book2.java ==\n'
sed -n '1,220p' game/src/main/java/com/survivalcoding/Book2.java

printf '\n== UML files mentioning Book2 or publishDate ==\n'
rg -n --hidden --glob '!*node_modules*' --glob '!*.class' --glob '!*.jar' 'Book2|publishDate' game/src/main/java game/src/main/resources . || true

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 4149


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== JDK Data type lookup in source and docs hints ==\n'
rg -n 'javax\.xml\.crypto\.Data|publishDate|equals\(' game/src/main/java game/src/main/resources . || true

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 2772


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== Book2.java =='
nl -ba game/src/main/java/com/survivalcoding/Book2.java | sed -n '1,220p'

echo
echo '== References to Book2 / publishDate / equals =='
rg -n --hidden --glob '!*node_modules*' 'Book2|publishDate|equals\(' game/src/main/java game/src/main/resources . || true

Repository: SurvivalCodingCampus/polytech_java2

Length of output: 230


publishDate를 날짜 타입으로 바꾸세요.

javax.xml.crypto.Data는 XML 암호화용 인터페이스라 출판일 의미와 맞지 않습니다. 생성자·게터·세터와 game/june30th.puml까지 같은 타입으로 묶여 있으니 java.time.LocalDate 같은 날짜 타입으로 정리하세요.

🤖 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 `@game/src/main/java/com/survivalcoding/Book2.java` around lines 2 - 3, Replace
the incorrect javax.xml.crypto.Data import in Book2 with a real date type such
as java.time.LocalDate, then update the publishDate field, constructor, getter,
and setter in Book2 to use that same type consistently. Also make sure any
related UML mapping in game/june30th.puml is updated to match the new date type
so the model stays aligned with the code.




public class Book2 {
private String title;
private Data publishDate;
private String comment;

Book2(String title, Data publishDate, String comment) {
this.title = title;
this.publishDate = publishDate;
this.comment = comment;
}




public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public Data getPublishDate() {
return publishDate;
}

public void setPublishDate(Data publishDate) {
this.publishDate = publishDate;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}





@Override
public boolean equals(Object obj) {

if (!(obj instanceof Book2)) return false;
Book2 bb = (Book2) obj;
String Data;
return title == bb.title && Data(equals(bb.Data));
title.equals(Data);

//boolean Object;
}
Comment on lines +49 to +59

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 | 🔴 Critical | ⚡ Quick win

equals() 구현은 현재 상태로 컴파일되지 않습니다.

Line 54-56에서 지역 변수 Data 가 타입명을 가리고, bb.Data 는 존재하지 않는 멤버이며, return 뒤의 title.equals(Data); 는 도달 불가 코드입니다. Objects.equals(...) 로 실제 필드들을 비교하도록 정리해야 hashCode() 와의 계약도 맞습니다.

🔧 수정 예시
 `@Override`
 public boolean equals(Object obj) {
-
-    if (!(obj instanceof Book2)) return false;
-    Book2 bb = (Book2) obj;
-    String Data;
-    return title == bb.title && Data(equals(bb.Data));
-    title.equals(Data);
-
-    //boolean Object;
+    if (this == obj) return true;
+    if (!(obj instanceof Book2)) return false;
+    Book2 other = (Book2) obj;
+    return Objects.equals(title, other.title)
+            && Objects.equals(publishDate, other.publishDate)
+            && Objects.equals(comment, other.comment);
 }
🧰 Tools
🪛 PMD (7.25.0)

[Medium] 55-55: UseEqualsToCompareStrings (Error Prone): Use equals() to compare strings instead of '==' or '!='

(UseEqualsToCompareStrings (Error Prone))


[Medium] 56-56: UselessPureMethodCall (Error Prone): Do not call pure method equals if the result is not used.

(UselessPureMethodCall (Error Prone))

🤖 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 `@game/src/main/java/com/survivalcoding/Book2.java` around lines 49 - 59, The
Book2.equals(Object) implementation is broken and does not compile; fix it by
comparing the actual Book2 fields instead of the invalid local Data variable and
nonexistent bb.Data member. Update equals in Book2 to use proper null-safe field
comparisons (for example via Objects.equals) for title and the other real member
fields, remove the unreachable statement after return, and keep the logic
consistent with hashCode().

Source: Linters/SAST tools


@Override
public int hashCode() {
return Objects.hash(title, publishDate, comment);
}

@Override
public String toString() {
return "Book2{" +
"title='" + title + '\'' +
", publishDate=" + publishDate +
", comment='" + comment + '\'' +
'}';
}
}




22 changes: 22 additions & 0 deletions post-oop/june30th.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@startuml
enum KeyType {
PADLOCK,
BUTTON,
DIAL,
FINGER
}
class StrongBox<K> {

- K data
- int cnt
- KeyType keyType

+ StrongBox(KeyType keyType)
+ void put(K data)
+ K get()
}

StrongBox -- KeyType
@enduml


63 changes: 56 additions & 7 deletions post-oop/src/main/java/com/survivalcoding/StrongBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,66 @@
import org.w3c.dom.ls.LSOutput;

//제너릭 클래스 선언
public class StrongBox<K extends KeyType >
{
public class StrongBox<K> {
/*
private final int PADLOCK = 1024;
private final int BUTTON = 10000;
private final int DIAL = 30000;
private final int FINGER = 1000000;
*/
private K data;
private int cnt = 0; //0을 안해도 프리미엄 타입은 자동으로 0으로 설정되어있음
// private int maxCnt=0;
private KeyType keyType;

public void put(K date){
this. data = date;

public void put(K date) {
this.data = date;
Comment on lines +19 to +20

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

null 저장을 허용하면 잠금 상태와 해제 상태를 구분할 수 없습니다.

get()이 잠겨 있을 때 null을 반환하는데, 여기서 put(null)도 허용하면 해제된 뒤에도 동일하게 null이 반환되어 API 의미가 깨집니다. put()에서 null을 거부하거나 반환 계약을 바꿔야 합니다.

예시 수정
+import java.util.Objects;
+
 public void put(K date) {
-    this.data = date;
+    this.data = Objects.requireNonNull(date, "data");
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void put(K date) {
this.data = date;
import java.util.Objects;
public void put(K date) {
this.data = Objects.requireNonNull(date, "data");
🤖 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 `@post-oop/src/main/java/com/survivalcoding/StrongBox.java` around lines 19 -
20, StrongBox.put(K data)에서 null 저장을 허용하면 get()의 잠김 상태 반환값과 구분이 깨집니다. StrongBox
클래스의 put 메서드에서 null 인자를 명시적으로 거부하도록 수정하고, 잠금/해제 상태를 나타내는 get()의 계약은 유지하세요. put,
get, StrongBox 식별자를 기준으로 null 처리 정책을 일관되게 맞추면 됩니다.

//count ++;
}
public K get(){
return this.data;

public StrongBox(KeyType keyType) {
this.keyType = keyType;
Comment on lines +24 to +25

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 | 🟡 Minor | ⚡ Quick win

keyType는 생성자에서 바로 검증하는 편이 안전합니다.

지금은 new StrongBox<>(null)이 가능해서 get()이 어떤 분기도 타지 못하고 영구적으로 null만 반환합니다. 이 경우는 조용히 실패시키기보다 생성 시점에 막는 편이 낫습니다.

예시 수정
+import java.util.Objects;
+
 public StrongBox(KeyType keyType) {
-    this.keyType = keyType;
+    this.keyType = Objects.requireNonNull(keyType, "keyType");
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public StrongBox(KeyType keyType) {
this.keyType = keyType;
import java.util.Objects;
public StrongBox(KeyType keyType) {
this.keyType = Objects.requireNonNull(keyType, "keyType");
🤖 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 `@post-oop/src/main/java/com/survivalcoding/StrongBox.java` around lines 24 -
25, The StrongBox constructor currently accepts a null keyType, which leaves
StrongBox.get() unable to match any branch and causes silent, permanent null
returns. Update the StrongBox(KeyType) constructor to validate keyType
immediately and reject null at creation time, using the StrongBox and get()
logic as the reference points to keep the invalid state from being constructed.

}
}


public K get() {
cnt++;
//KeyType keyType = KeyType.PADLOCK; //private로 존재하고 생성자로도 저장해놓았으므로 필요 없다.
/*문법은 맞으나 문제의 요구 사항에 충족되지 않아 안되
if (cnt == PADLOCK)
{
return this.data;
}
else if(cnt == BUTTON)
{
return this.data;
}
else if(cnt == DIAL)
{
return this.data;
}
else if(cnt == FINGER)

*/
if (keyType == KeyType.PADLOCK) {
if (cnt >= 1024) {
return data;
}
} else if (keyType == KeyType.BUTTON) {
if (cnt >= 10000) {
return data;
}
} else if (keyType == KeyType.DIAL) {
if (cnt >= 30000) {
return data;
}
} else if (keyType == KeyType.FINGER) {
if (cnt >= 1000000) {
return data;
}
}

return null; //이 부분이 else가 되므로 else를 안 쓴다
}
}
26 changes: 14 additions & 12 deletions post-oop/src/test/java/com/survivalcoding/StrongBoxTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package com.survivalcoding;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;


import static org.junit.jupiter.api.Assertions.*;

class StrongBoxTest
{
class StrongBoxTest {

@Test
void main() {
StrongBox strongBox = new StrongBox();
class StrongBox<integer> {
integer sb;
void put(integer sb) { this.sb=sb;}
integer get() { return this.sb;}
void test() {

StrongBox<Integer> box =
new StrongBox<>(KeyType.PADLOCK);

box.put(100);

for (int i = 0; i < 1023; i++) {
assertNull(box.get());
}

assertEquals(100, box.get());

}
assertEqauls();

}
}
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
rootProject.name = 'polytech_java2'
include 'day01-basic'
include 'game'
include 'game:post-oop'
include 'post-oop'