Skip to content

Commit b532bf1

Browse files
committed
refactor: 코드리뷰 반영
사용하지 않는 테스트, main 메서드, 유틸 클래스 삭제 유틸성 메서드 Electronics 클래스에 정의
1 parent 82a9719 commit b532bf1

File tree

3 files changed

+14
-65
lines changed

3 files changed

+14
-65
lines changed

me/day05/practice/ArrayUtil.java

-15
This file was deleted.

me/day05/practice/ElectronicArrayUtil.java

-15
This file was deleted.

me/day05/practice/Electronics.java

+14-35
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
public class Electronics {
99

10-
private static final int DEFAULT_CAPACITY = 10; // Default initial capacity
1110
private static final Electronic[] EMPTY_ELECTRONIC_LIST = {};
1211

1312
private static Electronic[] electronicList;
@@ -16,7 +15,7 @@ public class Electronics {
1615
private int size;
1716
private int capacity;
1817

19-
Electronics(){
18+
private Electronics(){
2019
electronicList = EMPTY_ELECTRONIC_LIST;
2120
}
2221

@@ -41,12 +40,11 @@ public Optional<Electronic[]> groupByCompanyName(CompanyName company){
4140
List<Electronic> temp = new ArrayList<>();
4241

4342
for (Electronic electronic : electronicList)
44-
// 테스트용 임시 조건 ( electronic != null )
45-
if (electronic != null && electronic.getCompanyName().equals(company))
43+
if (electronic.getCompanyName().equals(company))
4644
temp.add(electronic);
4745

4846
Electronic[] companyNameGroup =
49-
temp.isEmpty() ? null : ElectronicArrayUtil.listToArray(temp);
47+
temp.isEmpty() ? null : listToArray(temp);
5048

5149
return Optional.ofNullable(companyNameGroup);
5250
}
@@ -65,16 +63,24 @@ public Optional<Electronic[]> groupByAuthMethod(AuthMethod authMethod){
6563
List<Electronic> temp = new ArrayList<>();
6664

6765
for (Electronic electronic : electronicList)
68-
// 테스트용 임시 조건 ( electronic != null )
69-
if (electronic != null && electronic.isContainAuthMethod(authMethod))
66+
if (electronic.isContainAuthMethod(authMethod))
7067
temp.add(electronic);
7168

7269
Electronic[] authMethodNameGroup =
73-
temp.isEmpty() ? null : ElectronicArrayUtil.listToArray(temp);
70+
temp.isEmpty() ? null : listToArray(temp);
7471

7572
return Optional.ofNullable(authMethodNameGroup);
7673
}
7774

75+
private Electronic[] listToArray(List<Electronic> list){
76+
Electronic[] array = new Electronic[list.size()];
77+
78+
for (int i = 0; i < array.length; i++)
79+
array[i] = list.get(i);
80+
81+
return array;
82+
}
83+
7884
public int getSize() {
7985
return size;
8086
}
@@ -110,31 +116,4 @@ public String toString() {
110116
", capacity=" + capacity +
111117
", electronicList= " + Arrays.toString(electronicList) + " }";
112118
}
113-
114-
//==================================== TEST CODE ====================================//
115-
public void add (Electronic electronic) {
116-
if (electronicList == EMPTY_ELECTRONIC_LIST)
117-
electronicList = new Electronic[DEFAULT_CAPACITY];
118-
/* 배열 크기 체크하고 늘리는 로직 구현 할 것 */
119-
electronicList[size++] = electronic;
120-
}
121-
122-
public static void main(String[] args) {
123-
Electronic iPhone13 = new Electronic("아이폰13", CompanyName.APPLE, new AuthMethod[]{AuthMethod.FACE, AuthMethod.PIN, AuthMethod.PATTERN});
124-
Electronic iPhone12 = new Electronic("아이폰12", CompanyName.APPLE, new AuthMethod[]{AuthMethod.FACE, AuthMethod.PIN, AuthMethod.PATTERN});
125-
Electronic galaxyS22 = new Electronic("갤럭시S22", CompanyName.SAMSUNG, new AuthMethod[]{AuthMethod.FINGERPRINT, AuthMethod.PIN, AuthMethod.PATTERN});
126-
127-
Electronics electronics = getInstance();
128-
electronics.add(iPhone13);
129-
electronics.add(iPhone12);
130-
electronics.add(galaxyS22);
131-
132-
// System.out.println(electronics);
133-
134-
Optional<Electronic[]> authMethodGroupPIN = electronics.groupByAuthMethod(AuthMethod.FACE);
135-
authMethodGroupPIN.ifPresent(value -> System.out.println(Arrays.toString(value)));
136-
137-
Optional<Electronic[]> companyNameGroupAPPLE = electronics.groupByCompanyName(CompanyName.SAMSUNG);
138-
companyNameGroupAPPLE.ifPresent(value -> System.out.println(Arrays.toString(value)));
139-
}
140119
}

0 commit comments

Comments
 (0)