Skip to content

Commit 8cdcf8e

Browse files
authored
Merge pull request onlyliuxin#22 from Ren650119726/master
重新提交
2 parents 8b46df6 + 6bfc756 commit 8cdcf8e

File tree

21 files changed

+506
-0
lines changed

21 files changed

+506
-0
lines changed
File renamed without changes.

group17/102228177/work2_19/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
File renamed without changes.

group17/102228177/work2_26/.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>

group17/102228177/work2_26/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>work2_26</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.7
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.7
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package com.coderising.array;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.Iterator;
6+
import java.util.Set;
7+
8+
public class ArrayUtil {
9+
10+
/**
11+
* 给定一个整形数组a , 对该数组的值进行置换
12+
例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
13+
如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
14+
* @param origin
15+
* @return
16+
*/
17+
public void reverseArray(int[] origin){
18+
for (int i = 0; i < origin.length/2; i++) {
19+
int temp = origin[i];
20+
origin[i] = origin[origin.length-i-1];
21+
origin[origin.length-i-1] = temp;
22+
}
23+
}
24+
25+
public static void main(String[] args) {
26+
ArrayUtil util = new ArrayUtil();
27+
int[] origin = new int[]{1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
28+
// System.out.println(Arrays.toString(util.removeZero(origin)));
29+
30+
int[] a1 = {3, 5, 7,8};
31+
int[] a2 = {4, 5, 6,7};
32+
System.out.println(Arrays.toString(util.merge(a1, a2)));
33+
}
34+
35+
/**
36+
* 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
37+
* 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
38+
* {1,3,4,5,6,6,5,4,7,6,7,5}
39+
* @param oldArray
40+
* @return
41+
*/
42+
43+
public int[] removeZero(int[] oldArray){
44+
int[] newArray = new int[oldArray.length];
45+
int j = 0;
46+
for (int i = 0; i < oldArray.length; i++) {
47+
if(oldArray[i] != 0){
48+
newArray[j] = oldArray[i];
49+
j++;
50+
}
51+
}
52+
return Arrays.copyOf(newArray, j);
53+
}
54+
55+
/**
56+
* 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
57+
* 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
58+
* @param array1
59+
* @param array2
60+
* @return
61+
*/
62+
63+
public int[] merge(int[] array1, int[] array2){
64+
65+
//Set是不允许重复的,所以将数组的值全部放在Set对象中
66+
Set set = new HashSet<Integer>();
67+
68+
for(int i = 0; i < array1.length ; i++){
69+
set.add(array1[i]);
70+
}
71+
72+
for(int i = 0; i < array2.length ; i++){
73+
set.add(array2[i]);
74+
}
75+
76+
Iterator i = set.iterator();
77+
int[] arrays = new int[set.size()];
78+
int num=0;
79+
while(i.hasNext()){
80+
int a = (Integer)i.next();
81+
arrays[num] = a;
82+
num = num + 1;
83+
}
84+
85+
//对结果进行排序
86+
Arrays.sort(arrays);
87+
return arrays;
88+
}
89+
/**
90+
* 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
91+
* 注意,老数组的元素在新数组中需要保持
92+
* 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
93+
* [2,3,6,0,0,0]
94+
* @param oldArray
95+
* @param size
96+
* @return
97+
*/
98+
public int[] grow(int [] oldArray, int size){
99+
return null;
100+
}
101+
102+
/**
103+
* 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
104+
* 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
105+
* max = 1, 则返回空数组 []
106+
* @param max
107+
* @return
108+
*/
109+
public int[] fibonacci(int max){
110+
return null;
111+
}
112+
113+
/**
114+
* 返回小于给定最大值max的所有素数数组
115+
* 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
116+
* @param max
117+
* @return
118+
*/
119+
public int[] getPrimes(int max){
120+
return null;
121+
}
122+
123+
/**
124+
* 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
125+
* 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
126+
* @param max
127+
* @return
128+
*/
129+
public int[] getPerfectNumbers(int max){
130+
return null;
131+
}
132+
133+
/**
134+
* 用seperator 把数组 array给连接起来
135+
* 例如array= [3,8,9], seperator = "-"
136+
* 则返回值为"3-8-9"
137+
* @param array
138+
* @param s
139+
* @return
140+
*/
141+
public String join(int[] array, String seperator){
142+
return null;
143+
}
144+
145+
146+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.coderising.litestruts;
2+
3+
/**
4+
* javaBean 工具
5+
* @author ren
6+
*
7+
*/
8+
public class BeanUtil {
9+
/**
10+
* 返回set方法名
11+
* @param filedName 属性名
12+
* @return set方法名
13+
*/
14+
public static String setter(String filedName){
15+
return "set"+filedName.substring(0, 1).toUpperCase()+filedName.substring(1);
16+
}
17+
18+
/**
19+
* 返回get方法名
20+
* @param filedName 属性名
21+
* @return get方法名
22+
*/
23+
public static String getter(String filedName){
24+
return "get"+filedName.substring(0, 1).toUpperCase()+filedName.substring(1);
25+
}
26+
27+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.coderising.litestruts;
2+
3+
import java.io.FileInputStream;
4+
import java.io.FileNotFoundException;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
import org.dom4j.Document;
12+
import org.dom4j.Element;
13+
import org.dom4j.io.SAXReader;
14+
15+
/**
16+
* Dom4J 解析XML文件
17+
* @author ren
18+
*
19+
*/
20+
public class Dom4jUtil {
21+
22+
/**
23+
* 传入文件路径解析xml文件获取根节点
24+
* @param path xml文件的绝对路径
25+
* @return Element 根节点
26+
*/
27+
public static Element parseXml(String path){
28+
InputStream is = null;
29+
Map<String, String> map = new HashMap<String,String>();
30+
try {
31+
is = new FileInputStream(path);
32+
//创建SAXReader读取XML
33+
SAXReader reader = new SAXReader();
34+
//根据saxReader的read重写方法可知,既可以通过inputStream输入流来读取,也可以通过file对象来读取
35+
Document document = reader.read(is);
36+
//获取根节点对象
37+
Element rootElement = document.getRootElement();
38+
return rootElement;
39+
} catch (FileNotFoundException e) {
40+
e.printStackTrace();
41+
} catch (Exception e) {
42+
e.printStackTrace();
43+
}
44+
finally{
45+
if( is!=null ){
46+
try {
47+
is.close();
48+
} catch (IOException e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
}
53+
return null;
54+
}
55+
56+
/**
57+
* 获取子节点的属性值并添加到map中并返回
58+
* @param element xml文件根节点对象
59+
* @return map 封装的属性值map对象
60+
*/
61+
public static Map<String, String> getAttribute(Element element){
62+
Map<String, String> map = new HashMap<String, String>();
63+
List<Element> elements = element.elements();
64+
for (Element ele : elements) {
65+
String name = ele.attributeValue("name");
66+
String clas = ele.attributeValue("class");
67+
map.put(name, clas);
68+
}
69+
return map;
70+
}
71+
72+
/**
73+
* 根据传入的Action名返回结果JSP
74+
* @param element 根节点
75+
* @param actionName 标签name属性的value
76+
* @return map 封装返回结果jsp的map对象
77+
*/
78+
public static Map<String, String> getJspMap(Element element,String actionName){
79+
Map<String, String> map = new HashMap<String, String>();
80+
List<Element> actions = element.elements();
81+
for (Element action : actions) {
82+
if(actionName.equals(action.attributeValue("name"))){
83+
List<Element> results = action.elements();
84+
for (Element result : results) {
85+
String name = result.attributeValue("name");
86+
String text = result.getText();
87+
map.put(name, text);
88+
}
89+
}
90+
}
91+
return map;
92+
}
93+
94+
public static void main(String[] args) {
95+
String path = Dom4jUtil.class.getResource("").getPath()+"struts.xml";
96+
System.out.println(path);
97+
Element element = parseXml(path);
98+
Map<String, String> attribute = getAttribute(element);
99+
System.out.println(getJspMap(element,"login").get("success"));
100+
}
101+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.coderising.litestruts;
2+
3+
/**
4+
* 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
5+
* @author liuxin
6+
*
7+
*/
8+
public class LoginAction{
9+
private String name ;
10+
private String password;
11+
private String message;
12+
13+
public String getName() {
14+
return name;
15+
}
16+
17+
public String getPassword() {
18+
return password;
19+
}
20+
21+
public String execute(){
22+
if("test".equals(name) && "1234".equals(password)){
23+
this.message = "login successful";
24+
return "success";
25+
}
26+
this.message = "login failed,please check your user/pwd";
27+
return "fail";
28+
}
29+
30+
public void setName(String name){
31+
this.name = name;
32+
}
33+
public void setPassword(String password){
34+
this.password = password;
35+
}
36+
public String getMessage(){
37+
return this.message;
38+
}
39+
}

0 commit comments

Comments
 (0)