Skip to content

Commit d3ba3e5

Browse files
committed
增加类型
1 parent c6cc206 commit d3ba3e5

21 files changed

+685
-101
lines changed

src/main/java/seven/anno/ExcelAnno.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package seven.anno;
22

3+
import seven.callBack.ConvertInterface;
4+
import seven.callBack.imp.DefaultConvert;
5+
6+
import javax.swing.text.DateFormatter;
37
import java.lang.annotation.ElementType;
48
import java.lang.annotation.Retention;
59
import java.lang.annotation.RetentionPolicy;
@@ -20,14 +24,24 @@
2024
// ___`. | .'___
2125
// (______|______)
2226
//=======================================================
27+
2328
/**
2429
* @author Seven
2530
*/
2631
@Target(ElementType.FIELD)
2732
@Retention(RetentionPolicy.RUNTIME)
2833
public @interface ExcelAnno {
29-
String Value()default "Null";
30-
boolean Pass() default false;
31-
String Required() default "Null";
32-
short Align() default 0x2;
33-
}
34+
35+
String Value() default "Null";
36+
37+
boolean Pass() default false;
38+
39+
String Required() default "Null";
40+
41+
short Align() default 0x2;
42+
43+
@Deprecated
44+
Class<? extends ConvertInterface> Convert() default DefaultConvert.class;
45+
46+
String DateTimeFormatter() default "yyyy-MM-dd hh:mm:ss";
47+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package seven.callBack;
2+
3+
//=======================================================
4+
// .----.
5+
// _.'__ `.
6+
// .--(^)(^^)---/!\
7+
// .' @ /!!!\
8+
// : , !!!!
9+
// `-..__.-' _.-\!!!/
10+
// `;_: `"'
11+
// .'"""""`.
12+
// /, ya ,\\
13+
// //狗神保佑\\
14+
// `-._______.-'
15+
// ___`. | .'___
16+
// (______|______)
17+
//=======================================================
18+
19+
/**
20+
* @author Seven
21+
* FileName: FiledConvert.java
22+
* Created by Seven on 2019/12/2
23+
**/
24+
@FunctionalInterface
25+
public interface ConvertInterface<T> {
26+
T convert(Object o);
27+
}
28+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package seven.callBack.imp;
2+
3+
//=======================================================
4+
// .----.
5+
// _.'__ `.
6+
// .--(^)(^^)---/!\
7+
// .' @ /!!!\
8+
// : , !!!!
9+
// `-..__.-' _.-\!!!/
10+
// `;_: `"'
11+
// .'"""""`.
12+
// /, ya ,\\
13+
// //狗神保佑\\
14+
// `-._______.-'
15+
// ___`. | .'___
16+
// (______|______)
17+
//=======================================================
18+
19+
import seven.callBack.ConvertInterface;
20+
21+
/**
22+
* @author Seven
23+
* FileName: DefaultConvert.java
24+
* Created by Seven on 2019/12/2
25+
**/
26+
public class DefaultConvert implements ConvertInterface<Object> {
27+
@Override
28+
public Object convert(Object o) {
29+
return o;
30+
}
31+
}

src/main/java/seven/config/Config.java

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
5+
import seven.callBack.ConvertInterface;
56

67
import java.util.Arrays;
8+
import java.util.HashMap;
9+
import java.util.Map;
710
import java.util.Objects;
811

912
public class Config {
10-
private static final Logger logger= LoggerFactory.getLogger(Config.class);
13+
private static final Logger logger = LoggerFactory.getLogger(Config.class);
1114

1215
private Integer titleRow = 0;
1316
private Integer contentRowStart = 1;
@@ -19,25 +22,28 @@ public class Config {
1922
private String[] require = null;
2023
private Integer startSheet = 0;
2124
private Integer endSheet = null;
22-
private Integer sheetIndex=-1;
25+
private Integer sheetIndex = -1;
2326
private String sheetName = null;
27+
private Map<String, Class<? extends ConvertInterface>> convertMap = new HashMap<>();
28+
private Map<String, ConvertInterface> convertMapImpl = new HashMap<>();
2429

2530
public Config() {
2631
}
2732

28-
private boolean args(Object... params){
33+
private boolean args(Object... params) {
2934
return Arrays.stream(params).anyMatch(Objects::isNull);
3035
}
3136

32-
public void check ()throws RuntimeException{
33-
if(args(titleRow,contentRowStart)){
34-
logger.error("config[titleRow,contentRowStart] is null, the config {}",this);
37+
public void check() throws RuntimeException {
38+
if (args(titleRow, contentRowStart)) {
39+
logger.error("config[titleRow,contentRowStart] is null, the config {}", this);
3540
throw new RuntimeException("onfig[titleRow,contentRowStart] is null");
36-
}else {
37-
logger.info("config[titleRow,contentRowStart] is null, the config {}",this);
41+
} else {
42+
logger.info("config[titleRow,contentRowStart] is null, the config {}", this);
3843
}
3944

4045
}
46+
4147
@Deprecated
4248
public String[] getRequire() {
4349
return require;
@@ -79,6 +85,23 @@ public Config setErrorLog(Boolean errorLog) {
7985
return this;
8086
}
8187

88+
@Deprecated
89+
public Config withConvert(String name, Class<? extends ConvertInterface> clazz) {
90+
this.convertMap.put(name, clazz);
91+
return this;
92+
}
93+
94+
/**
95+
* @param name
96+
* @param convert
97+
* @return
98+
*/
99+
@Deprecated
100+
public Config withConvert(String name, ConvertInterface convert) {
101+
this.convertMapImpl.put(name, convert);
102+
return this;
103+
}
104+
82105
public Integer getSheetIndex() {
83106
return sheetIndex;
84107
}
@@ -138,6 +161,14 @@ public Integer getContentRowEnd() {
138161
return contentRowEnd;
139162
}
140163

164+
public Map<String, Class<? extends ConvertInterface>> getConvertMap() {
165+
return convertMap;
166+
}
167+
168+
public Map<String, ConvertInterface> getConvertMapImpl() {
169+
return convertMapImpl;
170+
}
171+
141172
/**
142173
* 内容结束行号
143174
*/
@@ -175,17 +206,8 @@ public Config endSheet(Integer endSheet) {
175206

176207
@Override
177208
public String toString() {
178-
return "Config{" +
179-
"titleRow=" + titleRow +
180-
", contentRowStart=" + contentRowStart +
181-
", contentRowEnd=" + contentRowEnd +
182-
", isLoopSheet=" + isLoopSheet +
183-
", errorLog=" + errorLog +
184-
", vocSize=" + vocSize +
185-
", require=" + Arrays.toString(require) +
186-
", startSheet=" + startSheet +
187-
", endSheet=" + endSheet +
188-
'}';
209+
return "Config{" + "titleRow=" + titleRow + ", contentRowStart=" + contentRowStart + ", contentRowEnd=" + contentRowEnd + ", isLoopSheet=" + isLoopSheet + ", errorLog=" + errorLog + ", vocSize=" + vocSize + ", require=" + Arrays
210+
.toString(require) + ", startSheet=" + startSheet + ", endSheet=" + endSheet + '}';
189211
}
190212

191213

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package seven.handler;
2+
3+
//=======================================================
4+
// .----.
5+
// _.'__ `.
6+
// .--(^)(^^)---/!\
7+
// .' @ /!!!\
8+
// : , !!!!
9+
// `-..__.-' _.-\!!!/
10+
// `;_: `"'
11+
// .'"""""`.
12+
// /, ya ,\\
13+
// //狗神保佑\\
14+
// `-._______.-'
15+
// ___`. | .'___
16+
// (______|______)
17+
//=======================================================
18+
19+
import seven.handler.implInput.*;
20+
21+
import java.time.LocalDate;
22+
import java.time.LocalDateTime;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
26+
/**
27+
* @author Seven
28+
* FileName: HandlerFactory.java
29+
* Created by Seven on 2019/12/2
30+
**/
31+
@SuppressWarnings("all")
32+
public class HandlerFactory {
33+
private static final Map<Class, InPutHandler> handler = new HashMap<>();
34+
static {
35+
reg();
36+
}
37+
38+
private static void reg() {
39+
handler.put(Integer.class, new IntegerHandler());
40+
handler.put(Double.class, new DoubleHandler());
41+
handler.put(Long.class, new LongHandler());
42+
handler.put(LocalDateTime.class, new LocalDateTimeHandler());
43+
handler.put(LocalDate.class, new LocalDateHandler());
44+
}
45+
46+
public static InPutHandler getInPutHandler(Class clazz) {
47+
return handler.getOrDefault(clazz,it->it);
48+
}
49+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package seven.handler;
2+
3+
public interface InPutHandler<T> {
4+
default T Handler(String source) {
5+
if (source != null && !"".equals(source)) {
6+
return handlerConvert(source);
7+
}
8+
return null;
9+
}
10+
11+
T handlerConvert(String source);
12+
13+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package seven.handler;
2+
3+
//=======================================================
4+
// .----.
5+
// _.'__ `.
6+
// .--(^)(^^)---/!\
7+
// .' @ /!!!\
8+
// : , !!!!
9+
// `-..__.-' _.-\!!!/
10+
// `;_: `"'
11+
// .'"""""`.
12+
// /, ya ,\\
13+
// //狗神保佑\\
14+
// `-._______.-'
15+
// ___`. | .'___
16+
// (______|______)
17+
//=======================================================
18+
19+
import javax.swing.plaf.IconUIResource;
20+
21+
/**
22+
* @author Seven
23+
* FileName: OutPutHandler.java
24+
* Created by Seven on 2019/12/2
25+
**/
26+
public interface OutPutHandler<T,R> {
27+
28+
default R Handler(T source) {
29+
if(source!=null){
30+
return handlerConvert(source);
31+
}
32+
return null;
33+
34+
}
35+
36+
R handlerConvert(T source);
37+
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package seven.handler.implInput;
2+
3+
//=======================================================
4+
// .----.
5+
// _.'__ `.
6+
// .--(^)(^^)---/!\
7+
// .' @ /!!!\
8+
// : , !!!!
9+
// `-..__.-' _.-\!!!/
10+
// `;_: `"'
11+
// .'"""""`.
12+
// /, ya ,\\
13+
// //狗神保佑\\
14+
// `-._______.-'
15+
// ___`. | .'___
16+
// (______|______)
17+
//=======================================================
18+
19+
import seven.handler.InPutHandler;
20+
21+
/**
22+
* @author Seven
23+
* FileName: DoubleHandler.java
24+
* Created by Seven on 2019/12/2
25+
**/
26+
public class DoubleHandler implements InPutHandler<Double> {
27+
@Override
28+
public Double handlerConvert(String source) {
29+
return Double.parseDouble(source);
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package seven.handler.implInput;
2+
3+
//=======================================================
4+
// .----.
5+
// _.'__ `.
6+
// .--(^)(^^)---/!\
7+
// .' @ /!!!\
8+
// : , !!!!
9+
// `-..__.-' _.-\!!!/
10+
// `;_: `"'
11+
// .'"""""`.
12+
// /, ya ,\\
13+
// //狗神保佑\\
14+
// `-._______.-'
15+
// ___`. | .'___
16+
// (______|______)
17+
//=======================================================
18+
19+
import seven.handler.InPutHandler;
20+
21+
/**
22+
* @author Seven
23+
* FileName: IntagerHandler.java
24+
* Created by Seven on 2019/12/2
25+
**/
26+
public class IntegerHandler implements InPutHandler<Integer> {
27+
@Override
28+
public Integer handlerConvert(String source) {
29+
return Integer.parseInt(source);
30+
}
31+
}

0 commit comments

Comments
 (0)