Skip to content

Commit f5efa43

Browse files
author
boyunkai
committed
update
1 parent f3f6632 commit f5efa43

6 files changed

Lines changed: 90 additions & 64 deletions

File tree

02nio/nio01/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
<artifactId>netty-all</artifactId>
6060
<version>4.1.51.Final</version>
6161
</dependency>
62+
<dependency>
63+
<groupId>io.netty</groupId>
64+
<artifactId>netty-all</artifactId>
65+
<version>4.1.55.Final</version>
66+
<scope>compile</scope>
67+
</dependency>
6268
</dependencies>
6369

6470

02nio/nio01/src/main/java/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class Main {
1111

1212
public static void main(String[] args) {
13-
Map<String, Class> map = new HashMap<>();
13+
Map<String, Class> map = new HashMap();
1414
map.put("1", HttpServer01.class);
1515
map.put("2", HttpServer02.class);
1616
map.put("3", HttpServer03.class);

04fx/java8/src/main/java/io/kimmking/java8/ForeachDemo.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
import java.util.List;
55

66
public class ForeachDemo {
7-
8-
private int x=1;
9-
7+
8+
private int x = 1;
9+
1010
public static void main(String[] args) {
11-
11+
1212
ForeachDemo demo = new ForeachDemo();
13-
13+
1414
demo.test();
15-
15+
1616
System.out.println(demo.x);
1717
}
18-
18+
1919
private void test() {
20-
List list = Arrays.asList(1,2);
20+
List list = Arrays.asList(1, 2);
2121
int y = 1;
2222
list.forEach(e -> {
23-
x=2;
24-
//y=2; // can't be compiled
23+
x = 2;
24+
// y = 2; // can't be compiled
2525
});
2626
}
27-
27+
2828
}

04fx/java8/src/main/java/io/kimmking/java8/LambdaDemo.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,77 @@
33
import java.io.Serializable;
44
import java.util.Arrays;
55
import java.util.Collection;
6+
import java.util.Optional;
67

7-
public class LambdaDemo<T extends Serializable&Comparable&Collection> {
8-
9-
public static void main(String args[]){
8+
public class LambdaDemo<T extends Serializable & Comparable & Collection> {
9+
10+
public static void main(String args[]) {
1011
LambdaDemo demo = new LambdaDemo();
11-
12+
1213
MathOperation op = new MathOperation<Integer>() {
1314
@Override
1415
public Integer operation(int a, int b) {
1516
return 1;
1617
}
1718
};
18-
19+
1920
MathOperation op1 = (a, b) -> 1;
20-
21+
2122
// 类型声明
2223
MathOperation addition = (int a, int b) -> a + b;
23-
24-
// 不用类型声明
24+
25+
// 不用类型声明
2526
MathOperation subtraction = (a, b) -> a - b + 1.0;
26-
27+
2728
// 大括号中的返回语句
28-
MathOperation multiplication = (int a, int b) -> {
29+
MathOperation multiplication = (int a, int b) -> {
2930
int c = 1000;
30-
return a * b + c;
31+
return a * b + c;
3132
};
32-
33+
3334
// 没有大括号及返回语句
3435
MathOperation division = (int a, int b) -> a / b;
35-
36+
3637
System.out.println("10 + 5 = " + demo.operate(10, 5, addition));
3738
System.out.println("10 - 5 = " + demo.operate(10, 5, subtraction));
3839
System.out.println("10 x 5 = " + demo.operate(10, 5, multiplication));
3940
System.out.println("10 / 5 = " + demo.operate(10, 5, division));
40-
41+
4142
//System.out.println("10 ^ 5 = " + demo.operate(10, 5, (a, b) -> new Double(Math.pow(a,b)).intValue()));
42-
43-
System.out.println("10 ^ 5 = " + demo.operate(10, 5, (a, b) -> Math.pow(a,b)));
44-
43+
44+
System.out.println("10 ^ 5 = " + demo.operate(10, 5, (a, b) -> Math.pow(a, b)));
45+
4546
// 不用括号
4647
GreetingService greetService1 = message ->
4748
System.out.println("Hello " + message);
48-
49+
4950
// 用括号
5051
GreetingService greetService2 = (message) ->
5152
System.out.println("Hello " + message);
52-
53+
5354
GreetingService greetService3 = System.out::println;
54-
55-
Arrays.asList(1,2,3).forEach( x -> System.out.println(x+3));
56-
Arrays.asList(1,2,3).forEach( LambdaDemo::println );
57-
55+
56+
Arrays.asList(1, 2, 3).forEach(x -> System.out.println(x + 3));
57+
Arrays.asList(1, 2, 3).forEach(LambdaDemo::println);
58+
5859
greetService1.sayMessage("kimmking");
5960
greetService2.sayMessage("Java");
6061
}
61-
62+
6263
private static void println(int x) {
63-
System.out.println(x+3);
64+
System.out.println(x + 3);
6465
}
65-
66+
6667
interface MathOperation<T> {
6768
T operation(int a, int b); // 返回类型+函数名+参数类型的列表
6869
}
69-
70+
7071
interface GreetingService {
7172
void sayMessage(String message);
7273
}
73-
74-
private <T> T operate(int a, int b, MathOperation<T> mathOperation){
74+
75+
private T operate(int a, int b, MathOperation<T> mathOperation) {
7576
return mathOperation.operation(a, b);
7677
}
77-
78+
7879
}

04fx/java8/src/main/java/io/kimmking/java8/StreamDemo.java

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.alibaba.fastjson.JSON;
44

55
import java.io.IOException;
6+
import java.util.ArrayList;
67
import java.util.Arrays;
78
import java.util.LinkedHashMap;
89
import java.util.List;
@@ -11,39 +12,57 @@
1112
import java.util.stream.Collectors;
1213

1314
public class StreamDemo {
14-
15+
1516
public static void main(String[] args) throws IOException {
16-
17-
List<Integer> list = Arrays.asList(4,2,3,5,1,2,2,7,6);
17+
18+
List<Integer> list = Arrays.asList(4, 2, 3, 5, 1, 2, 2, 7, 6);
1819
print(list);
19-
20+
2021
// Optional
2122
Optional<Integer> first = list.stream().findFirst();
22-
23+
2324
System.out.println(first.map(i -> i * 100).orElse(100));
24-
25-
int sum = list.stream().filter( i -> i<4).distinct().reduce(0,(a,b)->a+b);
26-
System.out.println("sum="+sum);
27-
25+
26+
int sum = list.stream().filter(i -> i < 4).distinct().reduce(0, (a, b) -> a + b);
27+
System.out.println("sum=" + sum);
28+
2829
//Map map = list.stream().collect(Collectors.toMap(a->a,a->(a+1)));
29-
Map<Integer,Integer> map = list.parallelStream().collect(Collectors.toMap(a->a,a->(a+1),(a,b)->a, LinkedHashMap::new));
30+
Map<Integer, Integer> map =
31+
list.parallelStream().collect(Collectors.toMap(a -> a, a -> (a + 1), (a, b) -> a, LinkedHashMap::new));
3032
print(map);
31-
32-
33+
34+
3335
map.forEach((k, v) -> System.out.println("key:value = " + k + ":" + v));
34-
List<Integer> list1 = map.entrySet().parallelStream().map(e -> e.getKey()+e.getValue()).collect(Collectors.toList());
36+
List<Integer> list1 =
37+
map.entrySet().parallelStream().map(e -> e.getKey() + e.getValue()).collect(Collectors.toList());
3538
print(list1);
36-
39+
3740
// parallelStream()
38-
41+
3942
// 总结:
4043
// 1. Fluent API:继续Stream
4144
// 2. 终止操作:得到结果
42-
43-
45+
46+
test();
47+
test2();
48+
}
49+
50+
static int one;
51+
52+
static void test() {
53+
List<Integer> b = new ArrayList<>();
54+
b.add(1);
55+
b.forEach((x) -> one = 2);
56+
System.out.println("test" + one);
57+
}
58+
59+
static void test2() {
60+
List<Integer> b = new ArrayList<>();
61+
b.add(1);
62+
b.forEach(x -> x = 2);
63+
System.out.println("test" + b.get(0));
4464
}
45-
46-
65+
4766
private static void print(Object obj) {
4867
System.out.println(JSON.toJSONString(obj));
4968
}

09mq/activemq-demo/src/main/java/io/kimmking/javacourse/mq/activemq/ActivemqApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public void onMessage(Message message) {
6262
producer.send(message);
6363
}
6464

65-
Thread.sleep(2000);
66-
session.close();
67-
conn.close();
65+
// Thread.sleep(2000);
66+
// session.close();
67+
// conn.close();
6868

6969

7070
} catch (Exception e) {

0 commit comments

Comments
 (0)