Skip to content

Commit a52510f

Browse files
committed
add Test2, reformat all code
1 parent 25ad9e4 commit a52510f

File tree

171 files changed

+4164
-4380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+4164
-4380
lines changed

src/main/java/Advances/CalendarApi/demo1.java

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,73 @@
22

33
// https://www.youtube.com/watch?v=aPgJYCIc-fM&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=482
44

5-
6-
/** CalendarApi demo1 :
5+
/**
6+
* CalendarApi demo1 :
77
*
8-
* Calendar class use class intro
8+
* <p>Calendar class use class intro
99
*/
10-
1110
import java.util.Calendar;
1211
import java.util.Date;
1312
import org.junit.jupiter.api.Test;
1413

1514
/**
16-
* 1) Calendar is an abstract class
15+
* 1) Calendar is an abstract class
1716
*
18-
* 2) there are 2 ways to instantiate it
17+
* <p>2) there are 2 ways to instantiate it
1918
*
20-
* - 2-1) create its sub-class' class (GregorianCalendar)
21-
* - 2-2) call its static method : getInstance()
19+
* <p>- 2-1) create its sub-class' class (GregorianCalendar) - 2-2) call its static method :
20+
* getInstance()
2221
*
23-
* // these 2 methods are the same actually
22+
* <p>// these 2 methods are the same actually
2423
*
25-
* 3) frequent used methods
24+
* <p>3) frequent used methods
2625
*
27-
* - 3-1) get()
28-
* - 3-2) set()
29-
* - 3-3) add()
30-
* - 3-4) getTime()
31-
* - 3-5) setTime()
26+
* <p>- 3-1) get() - 3-2) set() - 3-3) add() - 3-4) getTime() - 3-5) setTime()
3227
*/
3328
public class demo1 {
3429

35-
@Test
36-
public void test1(){
37-
// 2-2) call its static method : getInstance()
38-
Calendar calendar = Calendar.getInstance();
39-
System.out.println(calendar.getClass()); // still class java.util.GregorianCalendar
40-
}
30+
@Test
31+
public void test1() {
32+
// 2-2) call its static method : getInstance()
33+
Calendar calendar = Calendar.getInstance();
34+
System.out.println(calendar.getClass()); // still class java.util.GregorianCalendar
35+
}
4136

42-
@Test
43-
public void test2(){
44-
Calendar calendar = Calendar.getInstance();
37+
@Test
38+
public void test2() {
39+
Calendar calendar = Calendar.getInstance();
4540

46-
// get()
47-
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
48-
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
49-
System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
50-
System.out.println(calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
41+
// get()
42+
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
43+
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
44+
System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
45+
System.out.println(calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
5146

52-
System.out.println("--------------------------");
47+
System.out.println("--------------------------");
5348

54-
// set() : change DAY_OF_MONTH or ... in Calendar
55-
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
56-
calendar.set(Calendar.DAY_OF_MONTH, 1);
57-
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
49+
// set() : change DAY_OF_MONTH or ... in Calendar
50+
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
51+
calendar.set(Calendar.DAY_OF_MONTH, 1);
52+
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
5853

59-
System.out.println("--------------------------");
54+
System.out.println("--------------------------");
6055

61-
// add()
62-
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
63-
calendar.add(Calendar.DAY_OF_MONTH, 3);
64-
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
56+
// add()
57+
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
58+
calendar.add(Calendar.DAY_OF_MONTH, 3);
59+
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
6560

66-
System.out.println("--------------------------");
61+
System.out.println("--------------------------");
6762

68-
// getTime() : Calendar dtype -> Date dtype
69-
Date date = calendar.getTime();
70-
System.out.println(date);
63+
// getTime() : Calendar dtype -> Date dtype
64+
Date date = calendar.getTime();
65+
System.out.println(date);
7166

72-
System.out.println("--------------------------");
67+
System.out.println("--------------------------");
7368

74-
// setTime() : Date dtype -> Calendar dtype
75-
Date date1 = new Date();
76-
calendar.setTime(date1); // set calendar from date1
77-
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
78-
}
69+
// setTime() : Date dtype -> Calendar dtype
70+
Date date1 = new Date();
71+
calendar.setTime(date1); // set calendar from date1
72+
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
73+
}
7974
}

src/main/java/Advances/ClassLoader/demo1.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
// https://www.youtube.com/watch?v=rePjvHVWnQ0&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=643
44
// https://www.youtube.com/watch?v=bpP8CE98MhE&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=644
55

6-
import org.junit.jupiter.api.Test;
7-
8-
import java.io.File;
96
import java.io.FileInputStream;
10-
import java.io.FileNotFoundException;
117
import java.io.InputStream;
128
import java.util.Properties;
9+
import org.junit.jupiter.api.Test;
1310

1411
public class demo1 {
1512

src/main/java/Advances/CollectionDemo/IteratorDemo1.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
// https://www.youtube.com/watch?v=HA7LSr6-xls&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=525
44

55
/** Iterator demo 1 */
6-
import org.junit.jupiter.api.Test;
7-
86
import java.util.ArrayList;
97
import java.util.Collection;
108
import java.util.Iterator;
9+
import org.junit.jupiter.api.Test;
1110

1211
/**
1312
* Iterator Demo1 -> collection iteration op, via Iterator interface
@@ -27,7 +26,7 @@ public void test1() {
2726
col1.add(456);
2827
col1.add(789);
2928
col1.add("yooooo");
30-
col1.add(new String("kate"));
29+
col1.add("kate");
3130
col1.add(new Person("kyo", 19));
3231

3332
Iterator iterator = col1.iterator();

src/main/java/Advances/CollectionDemo/LinkedHashSetDemo1.java

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,48 @@
33
// https://www.youtube.com/watch?v=z8nlH3W1sBU&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=538
44

55
/** LinkedHashSet demo 1 */
6-
76
import java.util.Iterator;
87
import java.util.LinkedHashSet;
98
import java.util.Set;
109
import org.junit.jupiter.api.Test;
1110

1211
public class LinkedHashSetDemo1 {
1312

14-
@Test
15-
public void test1(){
16-
/**
17-
* LinkedHashSet demo 1
18-
*
19-
* 1) LinkedHashSet is HashSet's sub class
20-
*
21-
* 2) maintain 2 references when adding new element : pre element and next element
22-
*
23-
* 3) pros : good performance in looping, adding, deletion
24-
*
25-
* 4) cons :
26-
*/
27-
28-
Set set = new LinkedHashSet();
29-
set.add(456);
30-
set.add(123);
31-
set.add(123); // only storage one "123", since HashSet is non-duplicated
32-
set.add("aa");
33-
set.add("bb");
34-
set.add(new Person("tim",11));
35-
set.add(new Person("tim",11)); // NOTE : will storage 2 "Person("tim",11)" since we haven't overwrote "equals", "hashCode" methods in Person class
36-
set.add(new User("ann",20));
37-
set.add(new User("ann",20)); // NOTE : only storage 1 "User("ann",20)" if we overwrite "equals", "hashCode" methods in User class
13+
@Test
14+
public void test1() {
15+
/**
16+
* LinkedHashSet demo 1
17+
*
18+
* <p>1) LinkedHashSet is HashSet's sub class
19+
*
20+
* <p>2) maintain 2 references when adding new element : pre element and next element
21+
*
22+
* <p>3) pros : good performance in looping, adding, deletion
23+
*
24+
* <p>4) cons :
25+
*/
26+
Set set = new LinkedHashSet();
27+
set.add(456);
28+
set.add(123);
29+
set.add(123); // only storage one "123", since HashSet is non-duplicated
30+
set.add("aa");
31+
set.add("bb");
32+
set.add(new Person("tim", 11));
33+
set.add(
34+
new Person(
35+
"tim",
36+
11)); // NOTE : will storage 2 "Person("tim",11)" since we haven't overwrote "equals",
37+
// "hashCode" methods in Person class
38+
set.add(new User("ann", 20));
39+
set.add(
40+
new User(
41+
"ann",
42+
20)); // NOTE : only storage 1 "User("ann",20)" if we overwrite "equals", "hashCode"
43+
// methods in User class
3844

39-
Iterator iterator = set.iterator();
40-
while (iterator.hasNext()){
41-
System.out.println(iterator.next());
42-
}
45+
Iterator iterator = set.iterator();
46+
while (iterator.hasNext()) {
47+
System.out.println(iterator.next());
4348
}
49+
}
4450
}

src/main/java/Advances/CollectionDemo/ListDemo1.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
// https://www.youtube.com/watch?v=KptmLcdTECg&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=531
77

88
/** List demo 1 */
9-
import org.junit.jupiter.api.Test;
10-
119
import java.util.ArrayList;
1210
import java.util.Arrays;
1311
import java.util.List;
12+
import org.junit.jupiter.api.Test;
1413

1514
/**
1615
* List Demo1 |-- List interface : storage ordering, duplicated record -> "dynamic" array |---

src/main/java/Advances/CollectionDemo/SetDemo1.java

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,82 @@
66
// https://www.youtube.com/watch?v=fWaabv-UgCs&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=537
77

88
/** Set demo 1 */
9-
109
import java.util.HashSet;
1110
import java.util.Iterator;
1211
import java.util.Set;
1312
import org.junit.jupiter.api.Test;
1413

1514
/**
16-
* Set Demo 1
15+
* Set Demo 1
1716
*
18-
* 0) "Set" is an interface, we need to implement it before using.
19-
* plz check below implemented classes
17+
* <p>0) "Set" is an interface, we need to implement it before using. plz check below implemented
18+
* classes
2019
*
21-
* 1) Collection framework:
22-
* ....
23-
* |--- Set interface : storage non-ordering, non-repeatable elements
24-
* |--- HashSet, LinkedHastSet, TreeSet
20+
* <p>1) Collection framework: .... |--- Set interface : storage non-ordering, non-repeatable
21+
* elements |--- HashSet, LinkedHastSet, TreeSet
2522
*
26-
* 2) 3 implemented classes (Set)
27-
* - HashSet : main implemented class (Set interface), thread Un-safety, can save `null` value
28-
* - LinkedHastSet : "HashSet"'s sub class. hashset with linkedlist structure. make looping/add/delete elements more efficient
29-
* - TreeSet : use "Red–black tree" in low level. can ordering input elements based on their properties
23+
* <p>2) 3 implemented classes (Set) - HashSet : main implemented class (Set interface), thread
24+
* Un-safety, can save `null` value - LinkedHastSet : "HashSet"'s sub class. hashset with linkedlist
25+
* structure. make looping/add/delete elements more efficient - TreeSet : use "Red–black tree" in
26+
* low level. can ordering input elements based on their properties
3027
*
31-
* 3) There are NO extra defined methods in Set -> all methods it (Set) has are as SAME as Collections's (methods)
28+
* <p>3) There are NO extra defined methods in Set -> all methods it (Set) has are as SAME as
29+
* Collections's (methods)
3230
*
33-
* 4) requirement :
34-
* - when add element to HashSet -> we need to Overwrite hashCode() and equals() methods
35-
* - Overwritten hashCode() and equals() methods should be "consistency" -> e.g. same elements SHOULD have SAME hash value
31+
* <p>4) requirement : - when add element to HashSet -> we need to Overwrite hashCode() and equals()
32+
* methods - Overwritten hashCode() and equals() methods should be "consistency" -> e.g. same
33+
* elements SHOULD have SAME hash value
3634
*/
37-
3835
public class SetDemo1 {
3936

40-
@Test
41-
public void test1(){
42-
/**
43-
* Set : storage non-ordering, non-duplicated (HashSet)
44-
*
45-
* 0) HashSet : array + linked list (low level structure)
46-
*
47-
* 1) non-ordering :
48-
* - non-ordering != randomness
49-
* - ordering in storage space is NOT based on input ordering, BUT on record's hash value
50-
*
51-
* 2) non-duplicated
52-
* - check duplicated or not (added elements) based on "equals()" method
53-
* - Need to overwrite "equals", "hashCode" methods if user-defined class
54-
* - can only add "one" same element into HashSet
55-
* - plz check below "set.add(new User("ann",20))" example
56-
*
57-
* 3) adding element steps (HashSet)
58-
* - step 1) when we add element a to HashSet
59-
* - step 2) get its hash value via its class' hashCode() method
60-
* - step 3) then get storage address (in storage space) via hash value above
61-
* - step 4) check if there is already element on the address
62-
* - if False : add element a OK
63-
* - if True : compare element a and b's hash value (if there is already an element b on the address) //(case 1)
64-
* - if False: add element a OK
65-
* - if True: call class' equals() method, compare every part in element a and element b //(case 2)
66-
* - if True (equals()): add element a Failed //(case 3)
67-
* - if False (equals()): add element a OK
68-
*
69-
* - (for success case 2, case 3, element a will be saved as Linked list form)
70-
* - (JDK 7 : put element a into array, point a -> original element)
71-
* - (JDK 8 : point original element -> element a)
72-
*/
73-
74-
Set set = new HashSet();
75-
set.add(456);
76-
set.add(123);
77-
set.add(123); // only storage one "123", since HashSet is non-duplicated
78-
set.add("aa");
79-
set.add("bb");
80-
set.add(new Person("tim",11));
81-
set.add(new Person("tim",11)); // NOTE : will storage 2 "Person("tim",11)" since we haven't overwritten "equals", "hashCode" methods in Person class
82-
set.add(new User("ann",20));
83-
set.add(new User("ann",20)); // NOTE : only storage 1 "User("ann",20)" if we overwrite "equals", "hashCode" methods in User class
37+
@Test
38+
public void test1() {
39+
/**
40+
* Set : storage non-ordering, non-duplicated (HashSet)
41+
*
42+
* <p>0) HashSet : array + linked list (low level structure)
43+
*
44+
* <p>1) non-ordering : - non-ordering != randomness - ordering in storage space is NOT based on
45+
* input ordering, BUT on record's hash value
46+
*
47+
* <p>2) non-duplicated - check duplicated or not (added elements) based on "equals()" method -
48+
* Need to overwrite "equals", "hashCode" methods if user-defined class - can only add "one"
49+
* same element into HashSet - plz check below "set.add(new User("ann",20))" example
50+
*
51+
* <p>3) adding element steps (HashSet) - step 1) when we add element a to HashSet - step 2) get
52+
* its hash value via its class' hashCode() method - step 3) then get storage address (in
53+
* storage space) via hash value above - step 4) check if there is already element on the
54+
* address - if False : add element a OK - if True : compare element a and b's hash value (if
55+
* there is already an element b on the address) //(case 1) - if False: add element a OK - if
56+
* True: call class' equals() method, compare every part in element a and element b //(case 2) -
57+
* if True (equals()): add element a Failed //(case 3) - if False (equals()): add element a OK
58+
*
59+
* <p>- (for success case 2, case 3, element a will be saved as Linked list form) - (JDK 7 : put
60+
* element a into array, point a -> original element) - (JDK 8 : point original element ->
61+
* element a)
62+
*/
63+
Set set = new HashSet();
64+
set.add(456);
65+
set.add(123);
66+
set.add(123); // only storage one "123", since HashSet is non-duplicated
67+
set.add("aa");
68+
set.add("bb");
69+
set.add(new Person("tim", 11));
70+
set.add(
71+
new Person(
72+
"tim",
73+
11)); // NOTE : will storage 2 "Person("tim",11)" since we haven't overwritten "equals",
74+
// "hashCode" methods in Person class
75+
set.add(new User("ann", 20));
76+
set.add(
77+
new User(
78+
"ann",
79+
20)); // NOTE : only storage 1 "User("ann",20)" if we overwrite "equals", "hashCode"
80+
// methods in User class
8481

85-
Iterator iterator = set.iterator();
86-
while (iterator.hasNext()){
87-
System.out.println(iterator.next());
88-
}
82+
Iterator iterator = set.iterator();
83+
while (iterator.hasNext()) {
84+
System.out.println(iterator.next());
8985
}
86+
}
9087
}

0 commit comments

Comments
 (0)