Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit df38cab

Browse files
committed
调整代码格式
1 parent dc430a3 commit df38cab

Some content is hidden

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

66 files changed

+3311
-3307
lines changed

‎src/main/java/cg.java‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
/**
22
* Copyright 2015-2023 yanglb.com
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
import com.yanglb.codegen.shell.CGShell;
1718

1819

1920
public class cg {
2021

21-
public static void main(String[] args) {
22-
CGShell shell = new CGShell();
23-
boolean r = shell.invoke(args);
24-
if (!r) {
25-
System.exit(1);
26-
}
27-
}
22+
public static void main(String[] args) {
23+
CGShell shell = new CGShell();
24+
boolean r = shell.invoke(args);
25+
if (!r) {
26+
System.exit(1);
27+
}
28+
}
2829
}
Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2015-2023 yanglb.com
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,84 +19,84 @@
1919
import com.yanglb.codegen.utils.ObjectUtil;
2020
import com.yanglb.codegen.utils.Resources;
2121
import com.yanglb.codegen.utils.StringUtil;
22+
2223
import java.lang.reflect.Field;
2324
import java.util.Map;
2425

2526

2627
public class BeanMapConverter<T> {
27-
28-
/**
29-
* 将Map转换为 cls类的对象
30-
* @param cls 将要转换为的类
31-
* @param map 保存数据的Map
32-
* @return 转换结果
33-
* @throws CodeGenException
34-
*/
35-
public T convert(Class<T> cls, Map<String, String> map) throws CodeGenException {
36-
T result = null;
37-
try {
38-
result = cls.newInstance();
39-
for(String key:map.keySet()) {
40-
Field field = ObjectUtil.getDeepField(result.getClass(), key);
41-
field.setAccessible(true);
42-
43-
String mapValue = map.get(key);
44-
Object value = null;
45-
46-
// 类型转换
47-
Class<?> type = field.getType();
48-
if(boolean.class.equals(type)) {
49-
value = false;
50-
if(!StringUtil.isNullOrEmpty(mapValue)) {
51-
value = this.toBoolean(mapValue);
52-
}
53-
} else if (Boolean.class.equals(type)) {
54-
value = null;
55-
if(!StringUtil.isNullOrEmpty(mapValue)) {
56-
value = this.toBoolean(mapValue);
57-
}
58-
} else if (int.class.equals(type)) {
59-
// 直接转换,出错时向外抛异常
60-
try{
61-
value = Integer.parseInt(mapValue);
62-
}catch(NumberFormatException e) {
63-
throw new CodeGenException(String.format(Resources.getString("E_001"), key, e.getMessage()));
64-
}
65-
} else if ( Integer.class.equals(type)) {
66-
// 可以为Null的整型
67-
if(StringUtil.isNullOrEmpty(mapValue)) {
68-
value = null;
69-
} else {
70-
try{
71-
value = Integer.parseInt(mapValue);
72-
}catch(NumberFormatException e) {
73-
throw new CodeGenException(String.format(Resources.getString("E_001"), key, e.getMessage()));
74-
}
75-
}
76-
} else {
77-
value = mapValue;
78-
}
79-
field.set(result, value);
80-
}
81-
} catch (NoSuchFieldException e) {
82-
throw new CodeGenException(String.format(Resources.getString("E_002"), e.getMessage()));
83-
} catch (SecurityException e) {
84-
throw new CodeGenException(e.getMessage());
85-
} catch (Exception e) {
86-
throw new CodeGenException(e.getMessage());
87-
}
88-
return result;
89-
}
90-
91-
private boolean toBoolean(String v) {
92-
boolean value = false;
93-
v = v.toLowerCase();
94-
if("y".equals(v)
95-
|| "√".equals(v)
96-
|| "yes".equals(v)
97-
|| "true".equals(v)){
98-
value = true;
99-
}
100-
return value;
101-
}
28+
29+
/**
30+
* 将Map转换为 cls类的对象
31+
* @param cls 将要转换为的类
32+
* @param map 保存数据的Map
33+
* @return 转换结果
34+
*/
35+
public T convert(Class<T> cls, Map<String, String> map) throws CodeGenException {
36+
T result = null;
37+
try {
38+
result = cls.newInstance();
39+
for (String key : map.keySet()) {
40+
Field field = ObjectUtil.getDeepField(result.getClass(), key);
41+
field.setAccessible(true);
42+
43+
String mapValue = map.get(key);
44+
Object value = null;
45+
46+
// 类型转换
47+
Class<?> type = field.getType();
48+
if (boolean.class.equals(type)) {
49+
value = false;
50+
if (!StringUtil.isNullOrEmpty(mapValue)) {
51+
value = this.toBoolean(mapValue);
52+
}
53+
} else if (Boolean.class.equals(type)) {
54+
value = null;
55+
if (!StringUtil.isNullOrEmpty(mapValue)) {
56+
value = this.toBoolean(mapValue);
57+
}
58+
} else if (int.class.equals(type)) {
59+
// 直接转换,出错时向外抛异常
60+
try {
61+
value = Integer.parseInt(mapValue);
62+
} catch (NumberFormatException e) {
63+
throw new CodeGenException(String.format(Resources.getString("E_001"), key, e.getMessage()));
64+
}
65+
} else if (Integer.class.equals(type)) {
66+
// 可以为Null的整型
67+
if (StringUtil.isNullOrEmpty(mapValue)) {
68+
value = null;
69+
} else {
70+
try {
71+
value = Integer.parseInt(mapValue);
72+
} catch (NumberFormatException e) {
73+
throw new CodeGenException(String.format(Resources.getString("E_001"), key, e.getMessage()));
74+
}
75+
}
76+
} else {
77+
value = mapValue;
78+
}
79+
field.set(result, value);
80+
}
81+
} catch (NoSuchFieldException e) {
82+
throw new CodeGenException(String.format(Resources.getString("E_002"), e.getMessage()));
83+
} catch (SecurityException e) {
84+
throw new CodeGenException(e.getMessage());
85+
} catch (Exception e) {
86+
throw new CodeGenException(e.getMessage());
87+
}
88+
return result;
89+
}
90+
91+
private boolean toBoolean(String v) {
92+
boolean value = false;
93+
v = v.toLowerCase();
94+
if ("y".equals(v)
95+
|| "√".equals(v)
96+
|| "yes".equals(v)
97+
|| "true".equals(v)) {
98+
value = true;
99+
}
100+
return value;
101+
}
102102
}
Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2015-2023 yanglb.com
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,31 +17,32 @@
1717

1818
import com.yanglb.codegen.exceptions.CodeGenException;
1919
import com.yanglb.codegen.model.TableModel;
20+
2021
import java.util.ArrayList;
2122
import java.util.List;
2223
import java.util.Map;
2324

2425

2526
public class TableModelConverter<T> {
2627

27-
/**
28-
* 将TableModel对象转换为指定的model对象
29-
* @param cls Model类
30-
* @param model 数据模型
31-
* @return cls Bean的列表
32-
* @throws CodeGenException 转换出错时抛出异常
33-
*/
34-
public List<T> convert(Class<T> cls, TableModel model) throws CodeGenException {
35-
List<T> result = new ArrayList<T>();
36-
List<Map<String, String>> modelList = model.toList();
37-
38-
BeanMapConverter<T> converter = new BeanMapConverter<T>();
39-
for(Map<String, String> itm : modelList) {
40-
T res = converter.convert(cls, itm);
41-
42-
// 添加到结果集中
43-
result.add(res);
44-
}
45-
return result;
46-
}
28+
/**
29+
* 将TableModel对象转换为指定的model对象
30+
* @param cls Model类
31+
* @param model 数据模型
32+
* @return cls Bean的列表
33+
* @throws CodeGenException 转换出错时抛出异常
34+
*/
35+
public List<T> convert(Class<T> cls, TableModel model) throws CodeGenException {
36+
List<T> result = new ArrayList<T>();
37+
List<Map<String, String>> modelList = model.toList();
38+
39+
BeanMapConverter<T> converter = new BeanMapConverter<T>();
40+
for(Map<String, String> itm : modelList) {
41+
T res = converter.convert(cls, itm);
42+
43+
// 添加到结果集中
44+
result.add(res);
45+
}
46+
return result;
47+
}
4748
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2015-2023 yanglb.com
3-
*
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,31 +20,31 @@
2020
import com.yanglb.codegen.utils.Resources;
2121

2222
public class GenFactory<T> {
23-
private GenFactory() {
24-
}
23+
private GenFactory() {
24+
}
2525

26-
/**
27-
* 根据配置文件中配置的名字创建
28-
* @param <T> 创建接口类型
29-
* @return T的接口实例
30-
* @throws CodeGenException 错误信息
31-
*/
32-
public static <T> T createByName(String className) throws CodeGenException {
33-
T result = null;
34-
try {
35-
GenFactory<T> factory = new GenFactory<T>();
36-
result = factory.create(className);
37-
} catch (Exception e) {
38-
throw new CodeGenException(String.format(Resources.getString("E_011"), className, e.getMessage()));
39-
}
40-
return result;
41-
}
26+
/**
27+
* 根据配置文件中配置的名字创建
28+
* @param <T> 创建接口类型
29+
* @return T的接口实例
30+
* @throws CodeGenException 错误信息
31+
*/
32+
public static <T> T createByName(String className) throws CodeGenException {
33+
T result = null;
34+
try {
35+
GenFactory<T> factory = new GenFactory<T>();
36+
result = factory.create(className);
37+
} catch (Exception e) {
38+
throw new CodeGenException(String.format(Resources.getString("E_011"), className, e.getMessage()));
39+
}
40+
return result;
41+
}
4242

43-
private T create(String implName)
44-
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
45-
if (implName.startsWith(".")) implName = "com.yanglb.codegen" + implName;
43+
private T create(String implName)
44+
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
45+
if (implName.startsWith(".")) implName = "com.yanglb.codegen" + implName;
4646

47-
Object instance = Class.forName(implName).newInstance();
48-
return ObjectUtil.cast(instance);
49-
}
47+
Object instance = Class.forName(implName).newInstance();
48+
return ObjectUtil.cast(instance);
49+
}
5050
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /