Skip to content

Commit

Permalink
Merge pull request #41 from luoziyihao/master
Browse files Browse the repository at this point in the history
merge code from master repository
  • Loading branch information
onlyliuxin authored Mar 1, 2017
2 parents 49050f1 + 9bbbca0 commit feeae45
Show file tree
Hide file tree
Showing 44 changed files with 1,867 additions and 1 deletion.
File renamed without changes.
1 change: 1 addition & 0 deletions group17/102228177/work2_19/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions group17/102228177/work2_26/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions group17/102228177/work2_26/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>work2_26</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions group17/102228177/work2_26/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
146 changes: 146 additions & 0 deletions group17/102228177/work2_26/src/com/coderising/array/ArrayUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.coderising.array;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class ArrayUtil {

/**
* 给定一个整形数组a , 对该数组的值进行置换
例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
* @param origin
* @return
*/
public void reverseArray(int[] origin){
for (int i = 0; i < origin.length/2; i++) {
int temp = origin[i];
origin[i] = origin[origin.length-i-1];
origin[origin.length-i-1] = temp;
}
}

public static void main(String[] args) {
ArrayUtil util = new ArrayUtil();
int[] origin = new int[]{1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
// System.out.println(Arrays.toString(util.removeZero(origin)));

int[] a1 = {3, 5, 7,8};
int[] a2 = {4, 5, 6,7};
System.out.println(Arrays.toString(util.merge(a1, a2)));
}

/**
* 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
* 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
* {1,3,4,5,6,6,5,4,7,6,7,5}
* @param oldArray
* @return
*/

public int[] removeZero(int[] oldArray){
int[] newArray = new int[oldArray.length];
int j = 0;
for (int i = 0; i < oldArray.length; i++) {
if(oldArray[i] != 0){
newArray[j] = oldArray[i];
j++;
}
}
return Arrays.copyOf(newArray, j);
}

/**
* 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
* 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
* @param array1
* @param array2
* @return
*/

public int[] merge(int[] array1, int[] array2){

//Set是不允许重复的,所以将数组的值全部放在Set对象中
Set set = new HashSet<Integer>();

for(int i = 0; i < array1.length ; i++){
set.add(array1[i]);
}

for(int i = 0; i < array2.length ; i++){
set.add(array2[i]);
}

Iterator i = set.iterator();
int[] arrays = new int[set.size()];
int num=0;
while(i.hasNext()){
int a = (Integer)i.next();
arrays[num] = a;
num = num + 1;
}

//对结果进行排序
Arrays.sort(arrays);
return arrays;
}
/**
* 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
* 注意,老数组的元素在新数组中需要保持
* 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
* [2,3,6,0,0,0]
* @param oldArray
* @param size
* @return
*/
public int[] grow(int [] oldArray, int size){
return null;
}

/**
* 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
* 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
* max = 1, 则返回空数组 []
* @param max
* @return
*/
public int[] fibonacci(int max){
return null;
}

/**
* 返回小于给定最大值max的所有素数数组
* 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
* @param max
* @return
*/
public int[] getPrimes(int max){
return null;
}

/**
* 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
* 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
* @param max
* @return
*/
public int[] getPerfectNumbers(int max){
return null;
}

/**
* 用seperator 把数组 array给连接起来
* 例如array= [3,8,9], seperator = "-"
* 则返回值为"3-8-9"
* @param array
* @param s
* @return
*/
public String join(int[] array, String seperator){
return null;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.coderising.litestruts;

/**
* javaBean 工具
* @author ren
*
*/
public class BeanUtil {
/**
* 返回set方法名
* @param filedName 属性名
* @return set方法名
*/
public static String setter(String filedName){
return "set"+filedName.substring(0, 1).toUpperCase()+filedName.substring(1);
}

/**
* 返回get方法名
* @param filedName 属性名
* @return get方法名
*/
public static String getter(String filedName){
return "get"+filedName.substring(0, 1).toUpperCase()+filedName.substring(1);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.coderising.litestruts;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
* Dom4J 解析XML文件
* @author ren
*
*/
public class Dom4jUtil {

/**
* 传入文件路径解析xml文件获取根节点
* @param path xml文件的绝对路径
* @return Element 根节点
*/
public static Element parseXml(String path){
InputStream is = null;
Map<String, String> map = new HashMap<String,String>();
try {
is = new FileInputStream(path);
//创建SAXReader读取XML
SAXReader reader = new SAXReader();
//根据saxReader的read重写方法可知,既可以通过inputStream输入流来读取,也可以通过file对象来读取
Document document = reader.read(is);
//获取根节点对象
Element rootElement = document.getRootElement();
return rootElement;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
finally{
if( is!=null ){
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}

/**
* 获取子节点的属性值并添加到map中并返回
* @param element xml文件根节点对象
* @return map 封装的属性值map对象
*/
public static Map<String, String> getAttribute(Element element){
Map<String, String> map = new HashMap<String, String>();
List<Element> elements = element.elements();
for (Element ele : elements) {
String name = ele.attributeValue("name");
String clas = ele.attributeValue("class");
map.put(name, clas);
}
return map;
}

/**
* 根据传入的Action名返回结果JSP
* @param element 根节点
* @param actionName 标签name属性的value
* @return map 封装返回结果jsp的map对象
*/
public static Map<String, String> getJspMap(Element element,String actionName){
Map<String, String> map = new HashMap<String, String>();
List<Element> actions = element.elements();
for (Element action : actions) {
if(actionName.equals(action.attributeValue("name"))){
List<Element> results = action.elements();
for (Element result : results) {
String name = result.attributeValue("name");
String text = result.getText();
map.put(name, text);
}
}
}
return map;
}

public static void main(String[] args) {
String path = Dom4jUtil.class.getResource("").getPath()+"struts.xml";
System.out.println(path);
Element element = parseXml(path);
Map<String, String> attribute = getAttribute(element);
System.out.println(getJspMap(element,"login").get("success"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.coderising.litestruts;

/**
* 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
* @author liuxin
*
*/
public class LoginAction{
private String name ;
private String password;
private String message;

public String getName() {
return name;
}

public String getPassword() {
return password;
}

public String execute(){
if("test".equals(name) && "1234".equals(password)){
this.message = "login successful";
return "success";
}
this.message = "login failed,please check your user/pwd";
return "fail";
}

public void setName(String name){
this.name = name;
}
public void setPassword(String password){
this.password = password;
}
public String getMessage(){
return this.message;
}
}
Loading

0 comments on commit feeae45

Please sign in to comment.