Skip to content

Commit 8db9667

Browse files
author
yongjie.zhang@ucarinc.com
committed
11.13
1 parent f1fa8de commit 8db9667

File tree

8 files changed

+230
-2
lines changed

8 files changed

+230
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.asher.function.annotation;
2+
3+
import java.lang.annotation.*;
4+
5+
/**
6+
* 重复注解
7+
*
8+
*/
9+
@Repeatable(MyAnnotations.class)
10+
@Target(ElementType.TYPE)
11+
@Retention(RetentionPolicy.RUNTIME)
12+
public @interface MyAnnotation {
13+
String value()default "zhangyongjie";
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.asher.function.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.TYPE)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface MyAnnotations {
11+
MyAnnotation[] value();
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.asher.function.annotation;
2+
3+
/**
4+
* @author : 张勇杰
5+
* @date : 2019/10/19 15:51
6+
* @Version : v1.0
7+
* @description
8+
**/
9+
public class TestRepeatAnnotation {
10+
public static void main(String[] args) {
11+
12+
}
13+
}

java-stream/src/com/asher/function/stream/StreamApiTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,30 @@
2121
* 3.终止操作(终端操作)
2222
**/
2323
public class StreamApiTest {
24+
25+
static class A{
26+
27+
}
28+
static class B extends A{
29+
30+
}
31+
static class C extends B{
32+
33+
}
2434
public static void main(String[] args) {
2535
test1();
2636
}
2737

38+
39+
40+
2841
public static void test1(){
42+
43+
44+
2945
//1.可以通过Collection系列集合提供的stream()
3046
List<String> list = new ArrayList<>();
47+
3148
Stream<String> stream = list.stream();
3249

3350
//2.通过Arrays中的静态方法stream获取数组流

java-stream/src/com/asher/function/stream/StreamApiTest2.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.ArrayList;
66
import java.util.Arrays;
7+
import java.util.Comparator;
78
import java.util.List;
89
import java.util.stream.Stream;
910

@@ -110,7 +111,6 @@ public static void test6(){
110111
public static void test7(){
111112
List<String> list = Arrays.asList("aaa","bbb","ccc","ddd","eee");
112113
list.stream().map(x -> x.toUpperCase()).forEach(System.out::println);
113-
114114
users.stream().map(User::getName).forEach(System.out::println);
115115
System.out.println("--------------------------------------------");
116116
users.stream().sorted((e1,e2) ->{
@@ -120,7 +120,6 @@ public static void test7(){
120120
return e1.getAge().compareTo(e2.getAge());
121121
}
122122
}).forEach(System.out::println);
123-
124123
}
125124

126125
static Stream<Character> filterChracter(String str){
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.asher.function.stream;
2+
3+
/**
4+
* @author : 张勇杰
5+
* @date : 2019/10/30 18:13
6+
* @Version : v1.0
7+
* @description
8+
**/
9+
public class Test1 implements Cloneable{
10+
public static void main(String[] args) throws CloneNotSupportedException {
11+
Test1 t = new Test1();
12+
Object clone = t.clone();
13+
System.out.println(t);
14+
System.out.println(clone);
15+
}
16+
void method1(Test<? extends Fu> test){
17+
// test.setT(new Fu1());
18+
Fu t = test.getT();
19+
}
20+
21+
void method2(Test<? super Zi> test){
22+
test.setT(new Zi1());
23+
test.getT();
24+
}
25+
}
26+
class Test<T>{
27+
T t;
28+
29+
public T getT() {
30+
return t;
31+
}
32+
33+
public void setT(T t) {
34+
this.t = t;
35+
}
36+
}
37+
class Zi1 extends Zi{}
38+
class Zi extends Fu{}
39+
class Fu extends Fu1{}
40+
class Fu1{}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.asher.function.time;
2+
3+
import java.time.*;
4+
import java.time.format.DateTimeFormatter;
5+
import java.time.temporal.TemporalAdjusters;
6+
import java.util.Set;
7+
8+
/**
9+
* @author : 张勇杰
10+
* @date : 2019/10/19 11:34
11+
* @Version : v1.0
12+
* @description
13+
**/
14+
public class LocalDateTimeTest {
15+
public static void main(String[] args) {
16+
test1();
17+
test2();
18+
// test3();
19+
test4();
20+
test5();
21+
}
22+
public static void test1(){
23+
LocalDateTime dateTime1 = LocalDateTime.now();
24+
System.out.println(dateTime1);
25+
LocalDateTime dateTime2 = LocalDateTime.of(2019,10,19,11,35,20);
26+
System.out.println(dateTime2);
27+
28+
LocalDateTime dateTime3 = dateTime2.plusYears(2);
29+
System.out.println(dateTime3);
30+
}
31+
32+
/**
33+
* Instant: 时间戳(以Unix元年:1970年1月1日00:00:00到某个时间之间的毫秒值
34+
*/
35+
public static void test2(){
36+
//获取UTC时区
37+
Instant now = Instant.now();
38+
System.out.println(now);
39+
40+
OffsetDateTime offsetDateTime = now.atOffset(ZoneOffset.ofHours(8));
41+
System.out.println(offsetDateTime);
42+
43+
Instant now1 = Instant.now();
44+
System.out.println(now1.getEpochSecond()-now.getEpochSecond());
45+
}
46+
47+
48+
/**
49+
* Duration 计算两个时间之间的间隔
50+
* period 计算两个日期之间的间隔
51+
*
52+
*/
53+
public static void test3() {
54+
Instant ins1 = Instant.now();
55+
try {
56+
Thread.sleep(1000);
57+
}catch (Exception e){
58+
59+
}
60+
61+
Instant ins2 = Instant.now();
62+
Duration duration = Duration.between(ins1,ins2);
63+
System.out.println(duration.toMillis());
64+
65+
System.out.println("----------------");
66+
LocalTime lt1 = LocalTime.now();
67+
try {
68+
Thread.sleep(1000);
69+
}catch (Exception e){
70+
71+
}
72+
LocalTime lt2 = LocalTime.now();
73+
Duration duration2 = Duration.between(lt1,lt2);
74+
System.out.println(duration2.toMillis());
75+
76+
System.out.println("----------------");
77+
78+
79+
LocalDate ld1 = LocalDate.of(2015,1,1);
80+
LocalDate ld2 = LocalDate.now();
81+
Period period = Period.between(ld1,ld2);
82+
System.out.println(period);
83+
System.out.println(period.getYears());
84+
System.out.println(period.getMonths());
85+
System.out.println(period.getDays());
86+
}
87+
88+
/**
89+
* TemporalAdjuster:时间矫正器
90+
*/
91+
public static void test4(){
92+
LocalDateTime ldt = LocalDateTime.now();
93+
System.out.println(ldt);
94+
95+
LocalDateTime ldt2 = ldt.withDayOfMonth(10);
96+
System.out.println(ldt2);
97+
98+
//本月第一天
99+
LocalDateTime with = ldt.with(TemporalAdjusters.firstDayOfMonth());
100+
System.out.println(with);
101+
102+
//下一个周五
103+
LocalDateTime with1 = ldt.with(TemporalAdjusters.next(DayOfWeek.FRIDAY));
104+
System.out.println(with1);
105+
}
106+
107+
/**
108+
* DateTimeFormatter 格式化时间日期
109+
*/
110+
public static void test5(){
111+
DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME;
112+
LocalDateTime ldt = LocalDateTime.now();
113+
114+
String format = ldt.format(dtf);
115+
System.out.println(format);
116+
117+
System.out.println("---------");
118+
DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
119+
System.out.println(ldt.format(dtf1));
120+
test6();
121+
}
122+
123+
/**
124+
* 获取时区列表
125+
*/
126+
public static void test6(){
127+
Set<String> availableZoneIds = ZoneId.getAvailableZoneIds();
128+
availableZoneIds.forEach(System.out::println);
129+
}
130+
}

java-stream/src/com/asher/function/time/SimpleDateFormatTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.text.SimpleDateFormat;
44
import java.time.LocalDate;
5+
import java.time.LocalDateTime;
56
import java.time.format.DateTimeFormatter;
67
import java.util.ArrayList;
78
import java.util.Date;
@@ -53,6 +54,7 @@ public static void main(String[] args) {
5354
ExecutorService exec = Executors.newFixedThreadPool(10);
5455
List<Future<LocalDate>> futures = new ArrayList<>();
5556
for(int i =0;i<10;i++){
57+
5658
Future<LocalDate> f = exec.submit(callable);
5759
futures.add(f);
5860
}
@@ -65,5 +67,6 @@ public static void main(String[] args) {
6567
e.printStackTrace();
6668
}
6769
});
70+
exec.shutdown();
6871
}
6972
}

0 commit comments

Comments
 (0)