Skip to content

Commit db3bb0f

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
Collection (#170)
* generic examle * update collection * update checkstyle * change to jdk 14 * fixed build error * udpate formatter version * Formatted with Google Java Formatter Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 9094d95 commit db3bb0f

32 files changed

+835
-126
lines changed

.github/workflows/checkstyle.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ jobs:
88
steps:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-python@v2
11-
- name: Set up JDK 16
11+
- name: Set up JDK 12
1212
uses: actions/setup-java@v1
1313
with:
14-
java-version: 16
15-
- run: wget https://github.com/google/google-java-format/releases/download/v1.11.0/google-java-format-1.11.0-all-deps.jar -O formatter.jar
16-
- run: java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -jar formatter.jar --replace --set-exit-if-changed $(find . -type f -name "*.java" | grep ".*/src/.*java")
14+
java-version: 12
15+
- run: wget https://github.com/google/google-java-format/releases/download/google-java-format-1.9/google-java-format-1.9-all-deps.jar -O formatter.jar
16+
# - run: java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -jar formatter.jar --replace --set-exit-if-changed $(find . -type f -name "*.java" | grep ".*/src/.*java")
17+
- run: java -jar formatter.jar --replace --set-exit-if-changed $(find . -type f -name "*.java" | grep ".*/src/.*java")
1718
- name: Commit Format changes
1819
if: failure()
1920
run: |

.github/workflows/maven.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v2
15-
- name: Set up JDK 16
15+
- name: Set up JDK 14
1616
uses: actions/setup-java@v1
1717
with:
18-
java-version: 16
18+
java-version: 14
1919
- name: Build with Maven
2020
run: mvn clean test

pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<artifactId>untitled</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010
<properties>
11-
<maven.compiler.source>16</maven.compiler.source>
12-
<maven.compiler.target>16</maven.compiler.target>
11+
<maven.compiler.source>14</maven.compiler.source>
12+
<maven.compiler.target>14</maven.compiler.target>
1313
</properties>
1414
<dependencies>
1515
<dependency>
@@ -30,8 +30,8 @@
3030
<groupId>org.apache.maven.plugins</groupId>
3131
<artifactId>maven-compiler-plugin</artifactId>
3232
<configuration>
33-
<source>16</source>
34-
<target>16</target>
33+
<source>14</source>
34+
<target>14</target>
3535
</configuration>
3636
</plugin>
3737
</plugins>

src/main/java/com/examplehub/basics/ArrayListExample.java

-105
This file was deleted.

src/main/java/com/examplehub/basics/HashMapExample.java

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.generic;
2+
3+
public class GenericClass {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.generic;
2+
3+
public class GenericExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.map;
2+
3+
public class EnumMapExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.map;
2+
3+
public class HashMapExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.map;
2+
3+
public class PropertiesExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.map;
2+
3+
public class TreeMapExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.queue;
2+
3+
public class DequeExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.queue;
2+
3+
public class PriorityQueueExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.queue;
2+
3+
public class QueueExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.queue;
2+
3+
public class StackExample {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.examplehub.basics.set;
2+
3+
4+
public class ArrayListExample {}

src/main/java/com/examplehub/basics/HashSetExample.java src/main/java/com/examplehub/basics/set/HashSetExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.examplehub.basics;
1+
package com.examplehub.basics.set;
22

33
import java.util.HashSet;
44

src/main/java/com/examplehub/basics/LinkedListExample.java src/main/java/com/examplehub/basics/set/LinkedListExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.examplehub.basics;
1+
package com.examplehub.basics.set;
22

33
import java.util.LinkedList;
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.set;
2+
3+
public class TreeSetExample {}

src/test/java/com/examplehub/basics/HashMapExampleTest.java

+57-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ void testPut() {
1717

1818
assertNull(hashMap.put("bio", "Github"));
1919
assertEquals("Github", hashMap.put("bio", "I love coding"));
20+
21+
hashMap.put("username", "admin_username");
22+
assertEquals("admin_username", hashMap.get("username"));
2023
}
2124

2225
@Test
@@ -61,6 +64,8 @@ void testGet() {
6164
assertNull(hashMap.get("bio"));
6265

6366
assertEquals("jack", hashMap.getOrDefault("user", "jack"));
67+
68+
assertNull(hashMap.get("url"));
6469
}
6570

6671
@Test
@@ -112,10 +117,16 @@ void testKeySet() {
112117
hashMap.put("password", "abc123");
113118
assertEquals("[password, username]", hashMap.keySet().toString());
114119

115-
// password->abc123
116-
// username->admin
120+
String[][] keyValues =
121+
new String[][] {
122+
{"password", "abc123"},
123+
{"username", "admin"}
124+
};
125+
int index = 0;
117126
for (String key : hashMap.keySet()) {
118-
System.out.println(key + "->" + hashMap.get(key));
127+
assertEquals(keyValues[index][0], key);
128+
assertEquals(keyValues[index][1], hashMap.get(key));
129+
index++;
119130
}
120131
}
121132

@@ -141,10 +152,50 @@ void testEntry() {
141152
HashMap<String, String> hashMap = new HashMap<>();
142153
hashMap.put("username", "admin");
143154
hashMap.put("password", "abc123");
144-
// password->abc123
145-
// username->admin
155+
String[][] keyValues =
156+
new String[][] {
157+
{"password", "abc123"},
158+
{"username", "admin"}
159+
};
160+
int index = 0;
146161
for (Map.Entry<String, String> entry : hashMap.entrySet()) {
147-
System.out.println(entry.getKey() + "->" + entry.getValue());
162+
assertEquals(keyValues[index][0], entry.getKey());
163+
assertEquals(keyValues[index][1], entry.getValue());
164+
index++;
165+
}
166+
}
167+
168+
@Test
169+
void testStoreObj() {
170+
class Student {
171+
private String name;
172+
private int age;
173+
174+
public Student(String name, int age) {
175+
this.name = name;
176+
this.age = age;
177+
}
178+
179+
public String getName() {
180+
return name;
181+
}
182+
183+
public void setName(String name) {
184+
this.name = name;
185+
}
186+
187+
public int getAge() {
188+
return age;
189+
}
190+
191+
public void setAge(int age) {
192+
this.age = age;
193+
}
148194
}
195+
Student student = new Student("Jack", 25);
196+
HashMap<String, Student> hashMap = new HashMap<>();
197+
hashMap.put("jack", student);
198+
assertEquals("Jack", hashMap.get("jack").getName());
199+
assertEquals(25, hashMap.get("jack").getAge());
149200
}
150201
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.examplehub.basics.generic;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class GenericClassTest {
8+
@Test
9+
void testWriteGenericClass() {
10+
class MyBean<T> {
11+
T value;
12+
13+
public T getValue() {
14+
return value;
15+
}
16+
17+
public void setValue(T value) {
18+
this.value = value;
19+
}
20+
}
21+
MyBean<Integer> bean1 = new MyBean<>();
22+
bean1.setValue(123);
23+
assertEquals(123, bean1.getValue());
24+
}
25+
}

0 commit comments

Comments
 (0)