-
Notifications
You must be signed in to change notification settings - Fork 18
260630_22_진미 #101
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
base: student/22_진미
Are you sure you want to change the base?
260630_22_진미 #101
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # 2026-06-30 | ||
|
|
||
| ## 오늘 배운 내용 | ||
| 검색이 LISt는 느려 || SET/MAP은 빠르다 | ||
| h1 == h2 는 서로 다른 주소이므로 '=='가 들어갔어도 비교는 equals로 한다 | ||
| ㄴ> 비교하는 코드 틀 :: [h1.compareTo(h2)] | ||
| [equals() 특징] :: equals가 있으면 같은 내용은 지워진다 | ||
|
|
||
| [얕은 복사 (주소만 복사) || 깊은 복사(주소 달라, 내용 같아)] | ||
| [얕은 복사 코드의 틀 ] :: 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 { | ||
|
|
||
|
|
||
| } | ||
| 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) | ||
|
|
||
| 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
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. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 클래스/필드 이름 오타가 다이어그램 의미를 흐립니다.
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
| 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 | ||
| 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 |
| 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
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. 🗄️ 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 . || trueRepository: 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 . || trueRepository: 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 . || trueRepository: SurvivalCodingCampus/polytech_java2 Length of output: 230
🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
|
|
||
| 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
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. 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Line 54-56에서 지역 변수 🔧 수정 예시 `@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 AgentsSource: 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 + '\'' + | ||
| '}'; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| 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 | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
예시 수정+import java.util.Objects;
+
public void put(K date) {
- this.data = date;
+ this.data = Objects.requireNonNull(date, "data");
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| //count ++; | ||||||||||||||
| } | ||||||||||||||
| public K get(){ | ||||||||||||||
| return this.data; | ||||||||||||||
|
|
||||||||||||||
| public StrongBox(KeyType keyType) { | ||||||||||||||
| this.keyType = keyType; | ||||||||||||||
|
Comment on lines
+24
to
+25
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
지금은 예시 수정+import java.util.Objects;
+
public StrongBox(KeyType keyType) {
- this.keyType = keyType;
+ this.keyType = Objects.requireNonNull(keyType, "keyType");
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| 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를 안 쓴다 | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| 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(); | ||
|
|
||
| } | ||
| } |
| 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' |
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
equals,compareTo, Set 중복 규칙 설명이 서로 섞여 있습니다.compareTo()는 정렬 기준 비교이고, "같은 내용은 지워진다" 는Set에서equals()와hashCode()가 함께 일관될 때의 동작입니다. 지금 문구대로면Book2같은 예제의 동등성 계약을 잘못 학습하기 쉽습니다.✏️ 문구 예시
📝 Committable suggestion
🤖 Prompt for AI Agents