Skip to content

Commit e8f5f84

Browse files
committed
delete redundant code
1 parent ac2e3d4 commit e8f5f84

File tree

5 files changed

+99
-104
lines changed

5 files changed

+99
-104
lines changed

src/main/java/com/hunantv/fw/db/C3P0.java

Lines changed: 85 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -15,92 +15,89 @@
1515
import com.mchange.v2.c3p0.ComboPooledDataSource;
1616

1717
public class C3P0 {
18-
public static final FwLogger logger = new FwLogger(C3P0.class);
19-
private static C3P0 c3p0 = null;
20-
private Map<String, DataSource> dataSources = new HashMap<String, DataSource>();
21-
public static final String DEFUAT_DB_NAME = "write";
22-
23-
private C3P0() {
24-
try {
25-
Map<String, Map<String, Object>> specialPros = initPros();
26-
for (Iterator<String> iter = specialPros.keySet().iterator(); iter.hasNext();) {
27-
String name = iter.next();
28-
printPros(name, specialPros.get(name));
29-
DataSource ds = new ComboPooledDataSource();
30-
BeanUtils.populate(ds, specialPros.get(name));
31-
this.dataSources.put(name, ds);
32-
}
33-
} catch (Exception ex) {
34-
throw new RuntimeException(ex);
35-
}
36-
}
37-
38-
private void printPros(String name, Map<String, Object> pros) {
39-
logger.debug("datasource name:" + name);
40-
for (Iterator<String> iter = pros.keySet().iterator(); iter.hasNext();) {
41-
String key = iter.next();
42-
logger.debug(key + "=" + (String) pros.get(key));
43-
}
44-
}
45-
46-
private Map<String, Map<String, Object>> initPros() {
47-
try {
48-
Properties pros = new SysConf().read("c3p0.properties");
49-
50-
Map<String, Object> sharePros = new HashMap<String, Object>();
51-
String[] names = StringUtil.split(((String) pros.get("c3p0.names")).trim(), ",");
52-
53-
Map<String, Map<String, Object>> specialPros = new HashMap<String, Map<String, Object>>();
54-
for (String name : names) {
55-
specialPros.put(name, new HashMap<String, Object>());
56-
}
57-
58-
for (Iterator iter = pros.keySet().iterator(); iter.hasNext();) {
59-
String key = (String) iter.next();
60-
if (key.startsWith("c3p0.") && !key.startsWith("c3p0.names")) {
61-
for (String specialName : specialPros.keySet()) {
62-
if (!key.startsWith("c3p0." + specialName)) {
63-
sharePros.put(key.substring(5), pros.get(key));
64-
} else {
65-
// c3p0. 这个长度是5,最后一个 1是最后还有一个 . 的长度
66-
int len = 5 + specialName.length() + 1;
67-
specialPros.get(specialName).put(key.substring(len), pros.get(key));
68-
}
69-
}
70-
}
71-
}
72-
73-
/**
74-
* 把常规属性放到特殊属性里面去
75-
*/
76-
for (Map<String, Object> ps : specialPros.values()) {
77-
for (Iterator<String> iter = sharePros.keySet().iterator(); iter.hasNext();) {
78-
String key = iter.next();
79-
ps.put(key, sharePros.get(key));
80-
}
81-
}
82-
return specialPros;
83-
} catch (Exception ex) {
84-
throw new RuntimeException(ex);
85-
}
86-
}
87-
88-
public static C3P0 instance() {
89-
if (c3p0 == null)
90-
c3p0 = new C3P0();
91-
return c3p0;
92-
}
93-
94-
public DataSource getDataSource() {
95-
return this.getDataSource(this.DEFUAT_DB_NAME);
96-
}
97-
98-
public DataSource getDataSource(String name) {
99-
return this.dataSources.get(name);
100-
}
101-
102-
public static void main(String[] args) throws Exception {
103-
ComboPooledDataSource ds = (ComboPooledDataSource) new C3P0().getDataSource();
104-
System.out.println(ds.getMaxPoolSize());
105-
}
18+
public static final FwLogger logger = new FwLogger(C3P0.class);
19+
private static C3P0 c3p0 = null;
20+
private Map<String, DataSource> dataSources = new HashMap<>();
21+
public static final String DEFUAT_DB_NAME = "write";
22+
23+
private C3P0() {
24+
try {
25+
Map<String, Map<String, Object>> specialPros = initPros();
26+
for (Iterator<String> iter = specialPros.keySet().iterator(); iter.hasNext(); ) {
27+
String name = iter.next();
28+
printPros(name, specialPros.get(name));
29+
DataSource ds = new ComboPooledDataSource();
30+
BeanUtils.populate(ds, specialPros.get(name));
31+
this.dataSources.put(name, ds);
32+
}
33+
} catch (Exception ex) {
34+
throw new RuntimeException(ex);
35+
}
36+
}
37+
38+
private void printPros(String name, Map<String, Object> pros) {
39+
logger.debug("datasource name:" + name);
40+
pros.forEach((k, v) -> logger.debug(k + "=" + v));
41+
}
42+
43+
private Map<String, Map<String, Object>> initPros() {
44+
try {
45+
Properties pros = new SysConf().read("c3p0.properties");
46+
47+
Map<String, Object> sharePros = new HashMap<>();
48+
String[] names = StringUtil.split(((String) pros.get("c3p0.names")).trim(), ",");
49+
50+
Map<String, Map<String, Object>> specialPros = new HashMap<>();
51+
for (String name : names) {
52+
specialPros.put(name, new HashMap<>());
53+
}
54+
55+
for (Iterator iter = pros.keySet().iterator(); iter.hasNext(); ) {
56+
String key = (String) iter.next();
57+
if (key.startsWith("c3p0.") && !key.startsWith("c3p0.names")) {
58+
for (String specialName : specialPros.keySet()) {
59+
if (!key.startsWith("c3p0." + specialName)) {
60+
sharePros.put(key.substring(5), pros.get(key));
61+
} else {
62+
// c3p0. 这个长度是5,最后一个 1是最后还有一个 . 的长度
63+
int len = 5 + specialName.length() + 1;
64+
specialPros.get(specialName).put(key.substring(len), pros.get(key));
65+
}
66+
}
67+
}
68+
}
69+
70+
/**
71+
* 把常规属性放到特殊属性里面去
72+
*/
73+
for (Map<String, Object> ps : specialPros.values()) {
74+
for (Iterator<String> iter = sharePros.keySet().iterator(); iter.hasNext(); ) {
75+
String key = iter.next();
76+
ps.put(key, sharePros.get(key));
77+
}
78+
}
79+
return specialPros;
80+
} catch (Exception ex) {
81+
throw new RuntimeException(ex);
82+
}
83+
}
84+
85+
public static C3P0 instance() {
86+
if (c3p0 == null)
87+
c3p0 = new C3P0();
88+
return c3p0;
89+
}
90+
91+
public DataSource getDataSource() {
92+
return this.getDataSource(this.DEFUAT_DB_NAME);
93+
}
94+
95+
public DataSource getDataSource(String name) {
96+
return this.dataSources.get(name);
97+
}
98+
99+
public static void main(String[] args) throws Exception {
100+
ComboPooledDataSource ds = (ComboPooledDataSource) new C3P0().getDataSource();
101+
System.out.println(ds.getMaxPoolSize());
102+
}
106103
}

src/main/java/com/hunantv/fw/route/Route.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import com.hunantv.fw.utils.StringUtil;
1717

1818
public class Route {
19-
public static enum HttpMethod {
20-
GET, POST, PUT, DELETE, OPTIONS, HEAD, TRACE;
19+
public enum HttpMethod {
20+
GET, POST, PUT, DELETE, OPTIONS, HEAD, TRACE
2121
}
2222

2323
Map<String, Object[]> classAndRegMapping = new HashMap<String, Object[]>() {
@@ -260,9 +260,8 @@ public ControllerAndAction buildControllerAndAction() throws HttpException {
260260

261261
public ControllerAndAction buildControllerAndAction(Object[] args) throws HttpException {
262262
Class<? extends Controller> controllerClass = this.getController();
263-
Controller controller = null;
264263
try {
265-
controller = controllerClass.newInstance();
264+
Controller controller = controllerClass.newInstance();
266265
if (args == null)
267266
return new ControllerAndAction(controller, this.action);
268267
return new ControllerAndAction(controller, this.action, args);

src/main/java/com/hunantv/fw/route/Routes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public class Routes {
1414
/**
1515
* { uri: { httpMethod: Route } }
1616
*/
17-
private Map<String, Map<String, Route>> staticRoutes = new HashMap<String, Map<String, Route>>();
17+
private Map<String, Map<String, Route>> staticRoutes = new HashMap<>();
1818

1919
/**
2020
* { Route: { httpMethod } }
2121
*/
22-
private Map<Route, Set<String>> dyRoutes = new HashMap<Route, Set<String>>();
22+
private Map<Route, Set<String>> dyRoutes = new HashMap<>();
2323

2424
public Routes() {
2525
}
@@ -38,7 +38,7 @@ public Routes addStatic(Route route) {
3838
String routeUri = route.getUriReg();
3939
Map<String, Route> tmpMap = staticRoutes.get(routeUri);
4040
if (null == tmpMap) {
41-
tmpMap = new HashMap<String, Route>();
41+
tmpMap = new HashMap<>();
4242
staticRoutes.put(routeUri, tmpMap);
4343
}
4444
tmpMap.put(route.getHttpMethod().toString(), route);

src/main/java/com/hunantv/fw/utils/SysConf.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ private String sysPath() throws Exception {
7777
String path = url.getFile();
7878
int fileStrPosition = path.indexOf("file:/");
7979
int begin = 0;
80-
int end = path.length();
8180
if (fileStrPosition >= 0)
8281
begin = fileStrPosition + 5;
83-
end = path.indexOf("WEB-INF/");
82+
int end = path.indexOf("WEB-INF/");
8483
if (end > 0) {
8584
String rf = path.substring(begin, end);
8685
webPath = rf;

src/main/java/com/hunantv/fw/view/View.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
public interface View {
1313
FwLogger logger = FwLogger.getLogger(View.class);
1414

15-
public abstract String render();
15+
String render();
1616

17-
public abstract void renderTo(Writer out) throws IOException;
17+
void renderTo(Writer out) throws IOException;
1818

19-
public abstract Object getV();
19+
Object getV();
2020

2121
/**
2222
* Determine if this view should rendered as byte's stream, <br/>
2323
* default is false,
2424
*
2525
* @return
2626
*/
27-
public default boolean isStreamView() {
27+
default boolean isStreamView() {
2828
return false;
2929
}
3030

@@ -35,7 +35,7 @@ public default boolean isStreamView() {
3535
* @param response: HttpServletResponse
3636
* @throws IOException
3737
*/
38-
public default void renderTo(HttpServletResponse response) throws IOException {
38+
default void renderTo(HttpServletResponse response) throws IOException {
3939
if (isStreamView()) {
4040
renderTo(response.getOutputStream());
4141
} else {
@@ -48,7 +48,7 @@ public default void renderTo(HttpServletResponse response) throws IOException {
4848
*
4949
* @return View's bytes
5050
*/
51-
public default byte[] getBytes() {
51+
default byte[] getBytes() {
5252
return null;
5353
}
5454

@@ -61,7 +61,7 @@ public default byte[] getBytes() {
6161
* @param out: OutputStream
6262
* @throws IOException
6363
*/
64-
public default void renderTo(OutputStream out) throws IOException {
64+
default void renderTo(OutputStream out) throws IOException {
6565
byte[] bytes = getBytes();
6666

6767
if (bytes == null) {

0 commit comments

Comments
 (0)