diff --git a/group15/1500_369516660/.gitignore b/group15/1500_369516660/.gitignore deleted file mode 100644 index 5e56e040ec..0000000000 --- a/group15/1500_369516660/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin diff --git a/group15/1500_369516660/src/com/basic/array/ArrayList.java b/group15/1500_369516660/src/com/basic/array/ArrayList.java deleted file mode 100644 index 45708e38e5..0000000000 --- a/group15/1500_369516660/src/com/basic/array/ArrayList.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.basic.array; - -public class ArrayList { - -} diff --git a/group15/1500_369516660/src/com/basic/array/BinaryTreeNode.java b/group15/1500_369516660/src/com/basic/array/BinaryTreeNode.java deleted file mode 100644 index 4454e41e76..0000000000 --- a/group15/1500_369516660/src/com/basic/array/BinaryTreeNode.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.basic.array; - -public class BinaryTreeNode { - -} diff --git a/group15/1500_369516660/src/com/basic/array/Iterator.java b/group15/1500_369516660/src/com/basic/array/Iterator.java deleted file mode 100644 index 931cd71ed9..0000000000 --- a/group15/1500_369516660/src/com/basic/array/Iterator.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.basic.array; - -public class Iterator { - -} diff --git a/group15/1500_369516660/src/com/basic/array/LinkedList.java b/group15/1500_369516660/src/com/basic/array/LinkedList.java deleted file mode 100644 index 46f9116431..0000000000 --- a/group15/1500_369516660/src/com/basic/array/LinkedList.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.basic.array; - -public class LinkedList { - -} diff --git a/group15/1500_369516660/src/com/basic/array/List.java b/group15/1500_369516660/src/com/basic/array/List.java deleted file mode 100644 index 53f33bfe03..0000000000 --- a/group15/1500_369516660/src/com/basic/array/List.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.basic.array; - -public class List { - -} diff --git a/group15/1500_369516660/src/com/basic/array/Queue.java b/group15/1500_369516660/src/com/basic/array/Queue.java deleted file mode 100644 index 2e2c0eaee5..0000000000 --- a/group15/1500_369516660/src/com/basic/array/Queue.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.basic.array; - -public class Queue { - -} diff --git a/group15/1500_369516660/src/com/basic/array/Stack.java b/group15/1500_369516660/src/com/basic/array/Stack.java deleted file mode 100644 index 280f09defe..0000000000 --- a/group15/1500_369516660/src/com/basic/array/Stack.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.basic.array; - -public class Stack { - -} diff --git a/group15/1500_369516660/src/com/basic/struts/LoginAction.java b/group15/1500_369516660/src/com/basic/struts/LoginAction.java deleted file mode 100644 index d2ca3948f1..0000000000 --- a/group15/1500_369516660/src/com/basic/struts/LoginAction.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.basic.struts; -/** - * 登录的业务类 - * @author Jodie - * - */ -public class LoginAction { - - private String name; - private String password; - private String message; - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getPassword() { - return password; - } - public void setPassword(String password) { - this.password = password; - } - public String getMessage() { - return message; - } - public void setMessage(String message) { - this.message = message; - } - - public String execute(){ - if("test".equals(name)&&"1234".equals(password)){ - this.message = "login successful"; - return "success"; - } - this.message = "login fail,please check your name or password"; - return "fail"; - } - -} diff --git a/group15/1500_369516660/src/com/basic/struts/LoginOutAction.java b/group15/1500_369516660/src/com/basic/struts/LoginOutAction.java deleted file mode 100644 index d26773970b..0000000000 --- a/group15/1500_369516660/src/com/basic/struts/LoginOutAction.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.basic.struts; -/** - * 退出的业务类 - * @author Jodie - * - */ -public class LoginOutAction { - - private String name; - private String password; - private String message; - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getPassword() { - return password; - } - public void setPassword(String password) { - this.password = password; - } - public String getMessage() { - return message; - } - public void setMessage(String message) { - this.message = message; - } - /*public String execute(){ - if("test".equals(name)&&"1234".equals(password)){ - this.message = "loginOut successful"; - return "success"; - } - this.message = "loginOut fail,please check your name or password"; - return "fail"; - }*/ - -} diff --git a/group15/1500_369516660/src/com/basic/struts/Struts.java b/group15/1500_369516660/src/com/basic/struts/Struts.java deleted file mode 100644 index a7db2274a1..0000000000 --- a/group15/1500_369516660/src/com/basic/struts/Struts.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.basic.struts; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.Map.Entry; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class Struts { - - public static View runAction(String actionName,Map parameters){ - /* - * 0. 读取配置文件struts.xml - * 1. 根据actionName找到相对应的class, 例如LoginAction,通过反射实例化(创建对象), - * 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 ("name"="test","password"="1234"),那就应该调用 setName和setPassword方法 - * 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" - * 3. 通过反射找到对象的所有getter方法(例如 getMessage), - * 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,放到View对象的parameters - * 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,放到View对象的jsp字段中。 - */ - DocumentBuilderFactory domfac=DocumentBuilderFactory.newInstance();//得到 DOM 解析器的工厂实例 - try { - DocumentBuilder domBuilder=domfac.newDocumentBuilder();//从 DOM 工厂获得 DOM 解析器 - InputStream is= new FileInputStream(new File("../struts.xml")); - Document doc = domBuilder.parse(is); - Element root = doc.getDocumentElement();//获取根节点 - NodeList childNodes = root.getChildNodes();//获取子节点 - if(childNodes!=null){ - for(int i=0;i - Node childNode = childNodes.item(i); - if(childNode.getNodeType()==Node.ELEMENT_NODE){//判断是否是元素节点 - String name = childNode.getAttributes().getNamedItem("name").getNodeValue();//获取节点的属性值(action的属性name的值) - if(actionName.equals(name)){ - Class class1 = Class.forName(childNode.getAttributes().getNamedItem("class").getNodeValue());//得到action的一个class对象 - Object object = class1.newInstance();//构造一个action实例 - for(Entry entry : parameters.entrySet()){ - //得到每个参数的setter方法 - Method method = class1.getMethod(new StringBuffer("set").append(entry.getKey().substring(0,1).toUpperCase()).append(entry.getKey().substring(1)).toString(), entry.getKey().getClass()); - //调用action中的每个参数的setter方法来给action属性赋值 - method.invoke(object,entry.getValue()); - } - //得到处理action请求的函数入口 - Method method2 = class1.getMethod("execute"); - - } - /*for(Node node = childNode.getFirstChild();node!=null;node=node.getNextSibling()){ - if(node.getNodeType()==Node.ELEMENT_NODE){ - if(node.getNodeName().equals("name")){ - String name2 = node.getNodeValue(); - String name3 = node.getFirstChild().getNodeValue(); - } - if(node.getNodeName().equals("price")){ - String price = node.getFirstChild().getNodeValue(); - } - } - }*/ - } - } - } - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - -} diff --git a/group15/1500_369516660/src/com/basic/struts/StrutsTest.java b/group15/1500_369516660/src/com/basic/struts/StrutsTest.java deleted file mode 100644 index 25ed70d5fb..0000000000 --- a/group15/1500_369516660/src/com/basic/struts/StrutsTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.basic.struts; - -public class StrutsTest { - -} diff --git a/group15/1501_2535894075/2017code/src/arraylist.java b/group15/1501_2535894075/2017code/src/arraylist.java deleted file mode 100644 index 01e3be56e7..0000000000 --- a/group15/1501_2535894075/2017code/src/arraylist.java +++ /dev/null @@ -1,252 +0,0 @@ -package firstweek; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -public class arraylist implements List { - ArrayList q=new ArrayList(); - - private static final int InitialValue=10; - - private static final Object[] Empty_Elementdata={}; - - private Object[] elementData = new Object[100]; - - private int size = 0; - - public boolean add(Object o){ - if(elementData==Empty_Elementdata){ - //设置为初始化容量为10的数组 - elementData[0]=o; - } - if(size==elementData.length){ - //copy数组并增大50% - int oldLength=elementData.length; - int newLength=oldLength+(oldLength>>1); - if(newLength-oldLength>0){ - elementData=Arrays.copyOf(elementData, newLength); - } - } - elementData[size++]=o; - return true; - - } - public void add(int index, Object o){ - if(elementData==Empty_Elementdata){ - elementData[0]=o; - System.out.print("创建了一个新的只有该元素的数组"); - return ; - } - if(size==elementData.length){ - int oldLength=elementData.length; - int newLength=oldLength+(oldLength>>1); - if(newLength-oldLength>0){ - System.arraycopy(elementData, index, elementData,index+1 ,size-index); - } - } - elementData[index]=o; - size++; - } - - public Object get(int index){ - rangecheck(index); - return elementData[index]; - } - - public Object remove(int index){ - rangecheck(index); - Object oldValue=elementData(index); - int numMove=size-index-1; - if(numMove>0){ - System.arraycopy(elementData, index+1, elementData, index, numMove); - } - elementData[--size]=null; - return true; - } - public boolean removeObject(Object o){ - if(o==null){ - for(int index=0;index elementData(int index) { - // TODO Auto-generated method stub - return null; - } - public int size(){ - return size; - } - @Override - public boolean isEmpty() { - // TODO Auto-generated method stub - return size==0; - } - @Override - public boolean contains(Object o) { - // TODO Auto-generated method stub - return 0>=indexOf(o); - } - @Override - public Iterator iterator() { - // TODO Auto-generated method stub - //不会 - return null; - } - @Override - public Object[] toArray() { - // TODO Auto-generated method stub - return Arrays.copyOf(elementData,size); - } - @Override - public Object[] toArray(Object[] a) { - - // TODO Auto-generated method stub - return null; - } - @Override - public boolean remove(Object o) { - // TODO Auto-generated method stub - if(o==null){ - for(int i=0;isize||index<0){ - System.out.println("查询超出范围。"); - return null; - } - elementData[index]=element; - return null; - } - @Override - public int indexOf(Object o) { - // TODO Auto-generated method stub - if(o==null){ - for(int i=0;i= this.size) - throw new IndexOutOfBoundsException(outOfBoundsMsg(index)); - } - private String outOfBoundsMsg(int index) { - return "Index: "+index+", Size: "+this.size; - } - private void fastremove(int index){ - int numMoved=size-index-1; - if(numMoved>0){ - System.arraycopy(elementData, index+1, elementData, index, numMoved); - } - elementData[--size]=null; - } - -} diff --git a/group15/1501_2535894075/2017code/src/com/coderising/array/ArrayUtil.java b/group15/1501_2535894075/2017code/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..8d5a83d85d --- /dev/null +++ b/group15/1501_2535894075/2017code/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,190 @@ +package com.coderising.array; + +public class ArrayUtil { + + /** + * 缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 + 渚嬪锛 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[] o){ + + int length=o.length; + int half=length/2; + if(length==0||length==1){ + return; + } + for(int i=0;i parameters) { + + try{ + File f=new File("src\\com\\coderising\\litestruts\\struts.xml");//鎵惧埌xml鏂囦欢 + DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();//寰楀埌dom瑙f瀽鍣ㄥ伐鍘傚疄渚 + DocumentBuilder builder =factory.newDocumentBuilder();//浠庡伐鍘備腑寰楀埌DOM瑙f瀽鍣 + Document doc=builder.parse(f);//瑙f瀽鏂囦欢寰楀埌docunment + Element root=doc.getDocumentElement();//寰楀埌xml鏂囨。鐨勬牴鑺傜偣 + NodeList books=root.getChildNodes();//寰楀埌姣忎竴涓妭鐐 + if(books!=null){//濡傛灉涓嶄负绌鸿妭鐐 + for(int i=0;i 鍒 + String name=book.getAttributes().getNamedItem("name").getNodeValue();//鑾峰彇閲岀殑 灞炴у + String classname=book.getAttributes().getNamedItem("class").getNodeValue(); + if(actionName.equals(name)){//濡傛灉浼犺繘鏉ョ殑鍊肩瓑浜 灞炴ame鐨勫 + Class localclass=Class.forName(classname);//鏍规嵁class灞炴х殑鍊煎垱寤篶lass + Object object =localclass.newInstance();//鍒涘缓class瀹炰緥 + for(Entry entry :parameters.entrySet()){//寰幆閬嶅巻浼犺繘鏉ョ殑鍙傛暟 + String methodname=new StringBuffer("set").append(entry.getKey().substring(0,1).toUpperCase()).append(entry.getKey().substring(1)).toString();//鏍规嵁鍙傛暟鏉ョ敓鎴愮浉搴旂殑set鍑芥暟 + Method method=localclass.getMethod(methodname,entry.getKey().getClass()); + method.invoke(object, entry.getValue());//鎵ц鍑芥暟 + } + Method methods=localclass.getMethod("execute"); + String returnvalue=(String)methods.invoke(object); + Map map=new HashMap(); + String namepara=(String) getter(object,"name"); + String passwordpara=(String)getter(object,"password"); + String message=(String)getter(object,"message"); + map.put("name",namepara); + map.put("password", passwordpara); + map.put("message",message); + View view= new View(); + view.setParameters(map); + String jsp = null; + if(returnvalue.equals(" ")){ + + } + NodeList nl = doc.getElementsByTagName("result"); + for(int w=0;w 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛 + 鏀惧埌View瀵硅薄鐨刯sp瀛楁涓 + + */ + + return null; + } + public static Object getter(Object object,String toGet){ + Method target=null; + Object result=null; + try{ + target=object.getClass().getMethod("get"+upperFirst(toGet), null); + result=target.invoke(object); + return result; + }catch(Exception e){ + e.printStackTrace(); + } + return result; + } + public static String upperFirst(String toUpper){ + return toUpper.substring(0,1).toUpperCase()+toUpper.substring(1); + } +} diff --git a/group15/1501_2535894075/2017code/src/com/coderising/litestruts/StrutsTest.java b/group15/1501_2535894075/2017code/src/com/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..b8c81faf3c --- /dev/null +++ b/group15/1501_2535894075/2017code/src/com/coderising/litestruts/StrutsTest.java @@ -0,0 +1,43 @@ +package com.coderising.litestruts; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + + + + + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() { + + String actionName = "login"; + + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //瀵嗙爜鍜岄璁剧殑涓嶄竴鑷 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group15/1500_369516660/src/com/basic/struts/View.java b/group15/1501_2535894075/2017code/src/com/coderising/litestruts/View.java similarity index 63% rename from group15/1500_369516660/src/com/basic/struts/View.java rename to group15/1501_2535894075/2017code/src/com/coderising/litestruts/View.java index b6424115af..07df2a5dab 100644 --- a/group15/1500_369516660/src/com/basic/struts/View.java +++ b/group15/1501_2535894075/2017code/src/com/coderising/litestruts/View.java @@ -1,23 +1,23 @@ -package com.basic.struts; +package com.coderising.litestruts; import java.util.Map; public class View { - private String jsp; private Map parameters; + public String getJsp() { return jsp; } - public void setJsp(String jsp) { + public View setJsp(String jsp) { this.jsp = jsp; + return this; } public Map getParameters() { return parameters; } - public void setParameters(Map parameters) { + public View setParameters(Map parameters) { this.parameters = parameters; + return this; } - - } diff --git a/group15/1501_2535894075/2017code/src/com/coderising/litestruts/struts.xml b/group15/1501_2535894075/2017code/src/com/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..d60b234c2b --- /dev/null +++ b/group15/1501_2535894075/2017code/src/com/coderising/litestruts/struts.xml @@ -0,0 +1,21 @@ + + + + + + + /jsp/homepage.jsp + + /jsp/showLogin.jsp + + + + + + /jsp/welcome.jsp + + /jsp/error.jsp + + + + \ No newline at end of file diff --git a/group15/1501_2535894075/2017code/src/com/coding/basic/ArrayList.java b/group15/1501_2535894075/2017code/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..1f185736f9 --- /dev/null +++ b/group15/1501_2535894075/2017code/src/com/coding/basic/ArrayList.java @@ -0,0 +1,32 @@ +package com.coding.basic; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void add(Object o){ + + } + public void add(int index, Object o){ + + } + + public Object get(int index){ + return null; + } + + public Object remove(int index){ + return null; + } + + public int size(){ + return -1; + } + + public Iterator iterator(){ + return null; + } + +} diff --git a/group15/1501_2535894075/2017code/src/com/coding/basic/BinaryTreeNode.java b/group15/1501_2535894075/2017code/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..d7ac820192 --- /dev/null +++ b/group15/1501_2535894075/2017code/src/com/coding/basic/BinaryTreeNode.java @@ -0,0 +1,32 @@ +package com.coding.basic; + +public class BinaryTreeNode { + + private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public BinaryTreeNode getLeft() { + return left; + } + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + public BinaryTreeNode getRight() { + return right; + } + public void setRight(BinaryTreeNode right) { + this.right = right; + } + + public BinaryTreeNode insert(Object o){ + return null; + } + +} diff --git a/group15/1514_616019420/Iterator.java b/group15/1501_2535894075/2017code/src/com/coding/basic/Iterator.java similarity index 100% rename from group15/1514_616019420/Iterator.java rename to group15/1501_2535894075/2017code/src/com/coding/basic/Iterator.java diff --git a/group15/1501_2535894075/2017code/src/com/coding/basic/LinkedList.java b/group15/1501_2535894075/2017code/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..e2c4e5e795 --- /dev/null +++ b/group15/1501_2535894075/2017code/src/com/coding/basic/LinkedList.java @@ -0,0 +1,46 @@ +package com.coding.basic; + +public class LinkedList implements List { + + private Node head; + + public void add(Object o){ + + } + public void add(int index , Object o){ + + } + public Object get(int index){ + return null; + } + public Object remove(int index){ + return null; + } + + public int size(){ + return -1; + } + + public void addFirst(Object o){ + + } + public void addLast(Object o){ + + } + public Object removeFirst(){ + return null; + } + public Object removeLast(){ + return null; + } + public Iterator iterator(){ + return null; + } + + + private static class Node{ + Object data; + Node next; + + } +} diff --git a/group15/1514_616019420/List.java b/group15/1501_2535894075/2017code/src/com/coding/basic/List.java similarity index 100% rename from group15/1514_616019420/List.java rename to group15/1501_2535894075/2017code/src/com/coding/basic/List.java diff --git a/group15/1501_2535894075/2017code/src/com/coding/basic/Queue.java b/group15/1501_2535894075/2017code/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..36e516e266 --- /dev/null +++ b/group15/1501_2535894075/2017code/src/com/coding/basic/Queue.java @@ -0,0 +1,19 @@ +package com.coding.basic; + +public class Queue { + + public void enQueue(Object o){ + } + + public Object deQueue(){ + return null; + } + + public boolean isEmpty(){ + return false; + } + + public int size(){ + return -1; + } +} diff --git a/group15/1501_2535894075/2017code/src/com/coding/basic/Stack.java b/group15/1501_2535894075/2017code/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..a5a04de76d --- /dev/null +++ b/group15/1501_2535894075/2017code/src/com/coding/basic/Stack.java @@ -0,0 +1,22 @@ +package com.coding.basic; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + } + + public Object pop(){ + return null; + } + + public Object peek(){ + return null; + } + public boolean isEmpty(){ + return false; + } + public int size(){ + return -1; + } +} diff --git a/group15/1501_2535894075/2017code/src/linkedlist.java b/group15/1501_2535894075/2017code/src/linkedlist.java deleted file mode 100644 index 04a99762e5..0000000000 --- a/group15/1501_2535894075/2017code/src/linkedlist.java +++ /dev/null @@ -1,194 +0,0 @@ -package firstweek; - - -import java.util.NoSuchElementException; - -public class linkedlist { - private int size=0; - - private node first; - - private node next; - - private node last; - - public linkedlist(){ - - } - - private void linkFirst(E e){ - final node f=first; - final node newnode=new node(null,e,f); - first=newnode; - if(f==null){ - last=f; - }else{ - f.pre=newnode; - } - size++; - } - - void linkLast(E e){ - final node l=last; - final node newnode=new node(l,e,null); - last=newnode; - if(last==null){ - last=l; - }else{ - l.next=newnode; - } - } - - void linkbefore(E e,node nodes ){ - final node pre=nodes.pre; - final node newnode=new node<>(pre,e,nodes); - nodes.pre=newnode; - if(pre==null){ - first=newnode; - }else{ - pre.next=newnode; - } - size++; - } - - private E unlinkFirst(node f){ - //删除第一个非空节点 确定f为第一个节点并非空 - final E item=f.item; - final node next=f.next; - f.item=null; - f.next=null;//这样是为了gc来回收 - first=next; - if(next==null){ - last=null; - }else{ - next.pre=null; - } - size--; - return item; - } - private E unlinkLast(node l){ - //删除最后一个非空节点 确定l为最后节点且非空 - final E item=l.item; - final node pre=l.pre; - l.item=null; - l.pre=null; - last=pre; - if(pre==null){ - first=null; - }else{ - pre.next=null; - } - size--; - return item; - } - - E unlinekd(node e){ - final node pre=e.pre; - final node next=e.next; - if(size==0){ - System.out.println("链表为空 无需删除"); - return e.item; - } - if(e==last){ - if(size==1){ - last=null; - first=null; - size--; - return e.item; - } - last=pre; - pre.next=null; - size--; - return e.item; - } - if(e==first){ - if(size==1){ - first=null; - last=null; - size--; - return e.item; - } - size--; - first=next; - next.pre=null; - return e.item; - } - pre.next=next; - next.pre=pre; - size--; - return e.item; - } - - public E getFirst(){ - final node f=first; - if(f==null){ - throw new NoSuchElementException(); - } - return f.item; - } - - public E getLast(){ - final node l=last; - if(l==null){ - throw new NoSuchElementException(); - } - return l.item; - } - public E removeFirst(){ - final node f=first; - if(f==null){ - throw new NoSuchElementException(); - } - return unlinkFirst(f); - } - public E removeLast(){ - final node l=last; - if(l==null){ - throw new NoSuchElementException(); - } - return unlinkLast(l); - } - public void addLast(E e){ - linkLast(e); - } - public void addFirst(E e){ - linkFirst(e); - } - public int size(){ - return size; - } - public boolean add(E e){ - linkLast(e); - return true; - } - public int indexof(Object o){ - int index=0; - if(o==null){ - for(node x=first;x!=null;x=x.next){ - if(x.item==null){ - return index; - } - index++; - } - }else{ - for(node x=first;x!=null;x=x.next){ - if(o.equals(x.item)){ - return index; - } - index++; - } - } - return -1; - } -} - -class node{ - E item; - node pre; - node next; - node(node pre,E item,node next){ - this.pre=pre; - this.next=next; - this.item=item; - } -} diff --git a/group15/1501_2535894075/2017code/src/queue.java b/group15/1501_2535894075/2017code/src/queue.java deleted file mode 100644 index 8a9646a2ea..0000000000 --- a/group15/1501_2535894075/2017code/src/queue.java +++ /dev/null @@ -1,115 +0,0 @@ -package firstweek; -import java.util.AbstractList; -import java.util.Iterator; -import java.util.List; - -public class queue extends AbstractList implements List ,java.io.Serializable { - - private static final long serialVersionUID = 6203363761107460505L; - - // 指向队头 - private transient Entry front; - - private transient int size ; - // 指向队尾 - private transient Entry rear; - - public Iterator singleListIterator() { - return new QueueIterator(); - } - - public queue() { - this.front = this.rear = null; - } - - @Override - public boolean add(E e) { - Entry newData = new Entry(e, null); - if (this.rear == null) { - this.rear = newData; - this.front = this.rear; - } else { - Entry preElement = this.front; - while (preElement.next != null) { - preElement = preElement.next; - } - preElement.next = newData; - } - size ++; - return true; - } - - /** - * 队尾加入元素 - * @param e - * @return - */ - public boolean append(E e) { - return add(e); - } - - /** - * 取队头数据 - */ - @Override - public E get(int index) { - return this.front.element; - } - - public E getFrist() { - return get(0); - } - - /** - * 出队列 - * @return - */ - public E delete() { - E result = null; - Entry entry = this.front; - if (entry != null) { - result = entry.element; - this.front = entry.next; - entry = null; - } - size --; - return result; - } - - /** - * 队长度 - */ - @Override - public int size() { - return size; - } - - private static class Entry { - E element; - Entry next; - public Entry(E element, Entry next) { - this.element = element; - this.next = next; - } - } - - private class QueueIterator implements Iterator { - private Entry itFront = front; - @Override - public boolean hasNext() { - return itFront != null; - } - - @Override - public E next() { - E result = itFront.element ; - itFront = itFront.next; - return result; - } - - @Override - public void remove() { - throw new UnsupportedOperationException("can not remove"); - } - } -} \ No newline at end of file diff --git a/group15/1501_2535894075/2017code/src/stack.java b/group15/1501_2535894075/2017code/src/stack.java deleted file mode 100644 index 64cf55168b..0000000000 --- a/group15/1501_2535894075/2017code/src/stack.java +++ /dev/null @@ -1,71 +0,0 @@ -package firstweek; - -import java.util.Arrays; - -public class stack { - //Define capacity constant:CAPACITY - private static final int CAPACITY = 1024; - //Define capacity - private static int capacity; - //Define the top position of stack - //top = -1 meaning that the stack empty - private static int top = -1; - //Basic Object class array - Object[] array; - //Initialize the capacity of stack - public stack() { - this.capacity = CAPACITY; - array = new Object[capacity]; - } - - //Get the size of stack - public int getSize(){ - if(isEmpty()){ - return 0; - }else{ - return top + 1; - } - } - - //Get whether stack is empty - public boolean isEmpty(){ - return (top < 0); - } - - //Get the top element of stack - public Object top() { - - if(isEmpty()){ - System.out.println("Stack is empty"); - } - return array[top]; - - } - - //Push element to stack - public void push(Object element) throws Exception{ - if(getSize()== CAPACITY){ - throw new Exception("Stack is full"); - } - array[++ top] = element; - } - - //Pop element from stack - public Object pop() { - if(isEmpty()){ - System.out.println("Stack is empty"); - } - return array[top --]; - } - - - public String getAllElements() { - String[] arr = new String[top + 1]; - if(!isEmpty()){ - for(int i = 0;i < getSize();i ++){ - arr[i] = (String)array[i]; - } - } - return Arrays.toString(arr); - } -} diff --git a/group15/1502_1617273078/src/com/coderising/array/ArrayUtil.java b/group15/1502_1617273078/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..de36e61726 --- /dev/null +++ b/group15/1502_1617273078/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,283 @@ +package com.coderising.array; + +public class ArrayUtil { + + /** + * 缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 + * 渚嬪锛 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) { + int[] a = new int[origin.length]; + for (int i = 0; i < origin.length; i++) { + a[i] = origin[origin.length - 1 - i]; + } + for (int i = 0; i < a.length; i++) { + System.out.print(a[i]); + + } + + } + + /** + * 鐜板湪鏈夊涓嬬殑涓涓暟缁勶細 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 count = 0; + int index = 0; + //int[] brige = new int[oldArray.length]; + for (int i = 0; i < oldArray.length; i++) { + if (oldArray[i] != 0) { + + count++; + } + } + int[] result = new int[count]; + for (int i = 0; i < oldArray.length; i++) { + if (oldArray[i] != 0) { + result[index++] = oldArray[i]; + } + + + } + return result; + } + + /** + * 缁欏畾涓や釜宸茬粡鎺掑簭濂界殑鏁村舰鏁扮粍锛 a1鍜宎2 , 鍒涘缓涓涓柊鐨勬暟缁刟3, 浣垮緱a3 鍖呭惈a1鍜宎2 鐨勬墍鏈夊厓绱狅紝 骞朵笖浠嶇劧鏄湁搴忕殑 + * 渚嬪 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) { + int alength = array1.length; + int blength = array2.length; + int[] newint = new int[alength + blength]; + for (int i = 0; i < alength; i++) { + newint[i] = array1[i]; + } + int index = alength; + //鏈夌浉鍚岄」涓簍rue锛屾病鏈変负false + boolean flag = false; + for (int c = 0; c < blength; c++) { + for (int j = 0; j < alength; j++) { + if (array1[j] == array2[c]) { + + flag = true; + break; + } + + } + if (flag) { + + flag = false; + } else { + newint[index] = array2[c]; + index++; + } + + } + // 鍘婚浂 + newint = removeZero(newint); + //鎺掑簭 + + quickSort(newint); + return newint; + } + + /** + * 鎶婁竴涓凡缁忓瓨婊℃暟鎹殑鏁扮粍 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) { + int[] newarry = new int[oldArray.length + size]; + for (int i = 0; i < oldArray.length; i++) { + newarry[i] = oldArray[i]; + } + return newarry; + } + + /** + * 鏂愭尝閭e鏁板垪涓猴細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) { + int count = 0; + for (int i = 0; ; i++) { + if (createfibonacci(i + 1) < max) { + count++; + } else { + break; + + } + } + int[] arry = new int[count]; + for (int a = 0; a < count; a++) { + arry[a] = createfibonacci(a + 1); + } + return arry; + } + + /** + * 杩斿洖灏忎簬缁欏畾鏈澶у糾ax鐨勬墍鏈夌礌鏁版暟缁 + * 渚嬪max = 23, 杩斿洖鐨勬暟缁勪负[2,3,5,7,11,13,17,19] + * + * @param max + * @return + */ + public int[] getPrimes(int max) { + int count = 0; + for (int i = 0; i < max; i++) { + if (isprime(i)) { + count++; + } + } + int[] arry = new int[count]; + int sign = 0; + for (int i = 0; i < max; i++) { + if (isprime(i)) { + arry[sign] = i; + sign++; + } + } + return arry; + } + + /** + * 鎵璋撯滃畬鏁扳濓紝 鏄寚杩欎釜鏁版伆濂界瓑浜庡畠鐨勫洜瀛愪箣鍜岋紝渚嬪6=1+2+3 + * 缁欏畾涓涓渶澶у糾ax锛 杩斿洖涓涓暟缁勶紝 鏁扮粍涓槸灏忎簬max 鐨勬墍鏈夊畬鏁 + * + * @param max + * @return + */ + public int[] getPerfectNumbers(int max) { + int count = 0; + for (int i = 0; i < max; i++) { + if (isperfectnmber(i)) { + count++; + } + } + int[] arry = new int[count]; + int sign = 0; + for (int i = 0; i < max; i++) { + if (isperfectnmber(i)) { + arry[sign] = i; + sign++; + } + } + return arry; + + } + + /** + * 鐢╯eperator 鎶婃暟缁 array缁欒繛鎺ヨ捣鏉 + * 渚嬪array= [3,8,9], seperator = "-" + * 鍒欒繑鍥炲间负"3-8-9" + * + * @param array + * @param + * @return + */ + public String join(int[] array, String seperator) { + String stringBuilder=new String(String.valueOf(array[0])); + for (int i = 1; i = pivot) --high; + arr[low] = arr[high]; //浜ゆ崲姣旀灑杞村皬鐨勮褰曞埌宸︾ + while (low < high && arr[low] <= pivot) ++low; + arr[high] = arr[low]; //浜ゆ崲姣旀灑杞村皬鐨勮褰曞埌鍙崇 + } + //鎵弿瀹屾垚锛屾灑杞村埌浣 + arr[low] = pivot; + //杩斿洖鐨勬槸鏋㈣酱鐨勪綅缃 + return low; + } + + //鐢熸垚鏂愭尝閭e鏁板垪 + public static int createfibonacci(int n) { + if (n <= 2) { + return 1; + } else { + return createfibonacci(n - 1) + createfibonacci(n - 2); + } + } + + //鍒ゆ柇鏄惁鏄礌鏁 + public static boolean isprime(int a) { + boolean flag = true; + if (a < 2) { + return false; + } else { + for (int i = 2; i <= Math.sqrt(a); i++) { + if (a % i == 0) { + flag = false; + break; + } + } + } + return flag; + } + + //鍒ゆ柇鏄惁鏄畬鏁 + public static boolean isperfectnmber(int a) { + boolean flag = true; + int temp = 0;// 瀹氫箟鍥犲瓙涔嬪拰鍙橀噺 + + for (int n = 1; n < a / 2 + 1; n++) { + if (a % n == 0) { + temp += n;// 鑳借鏁撮櫎鐨勯櫎鏁板垯琚姞鍒皌emp涓 + } + } + if (temp == a) {// 濡傛灉鍥犲瓙涔嬪拰涓庡師鏁扮浉绛夌殑璇濓紝璇存槑鏄畬鏁 + //System.out.print(a + " ");// 杈撳嚭瀹屾暟 + flag = true; + } else { + flag = false; + } + return flag; + } + +} diff --git a/group15/1502_1617273078/src/com/coderising/array/ArrayUtilTest.java b/group15/1502_1617273078/src/com/coderising/array/ArrayUtilTest.java new file mode 100644 index 0000000000..17f810bc0f --- /dev/null +++ b/group15/1502_1617273078/src/com/coderising/array/ArrayUtilTest.java @@ -0,0 +1,163 @@ +package com.coderising.array; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** +* ArrayUtil Tester. +* +* @author +* @since
二月 27, 2017
+* @version 1.0 +*/ +public class ArrayUtilTest { + +@Before +public void before() throws Exception { + ArrayUtil arrayUtil = new ArrayUtil(); + int[] a = new int[10]; + a[0] = 1; + a[1] = 2; + a[2] = 3; + a[3] = 4; + a[4] = 5; + a[5] = 6; +} + +@After +public void after() throws Exception { +} + +/** +* +* Method: reverseArray(int[] origin) +* +*/ +@Test +public void testReverseArray() throws Exception { +//TODO: Test goes here... + int[] a = new int[10]; + a[0] = 1; + a[1] = 2; + a[2] = 3; + a[3] = 4; + a[4] = 5; + a[5] = 6; + ArrayUtil arrayUtil = new ArrayUtil(); + for (int i = 0; i parameters) throws DocumentException { + + /* + + 0. 璇诲彇閰嶇疆鏂囦欢struts.xml + + 1. 鏍规嵁actionName鎵惧埌鐩稿搴旂殑class 锛 渚嬪LoginAction, 閫氳繃鍙嶅皠瀹炰緥鍖栵紙鍒涘缓瀵硅薄锛 + 鎹畃arameters涓殑鏁版嵁锛岃皟鐢ㄥ璞$殑setter鏂规硶锛 渚嬪parameters涓殑鏁版嵁鏄 + ("name"="test" , "password"="1234") , + 閭e氨搴旇璋冪敤 setName鍜宻etPassword鏂规硶 + + 2. 閫氳繃鍙嶅皠璋冪敤瀵硅薄鐨別xectue 鏂规硶锛 骞惰幏寰楄繑鍥炲硷紝渚嬪"success" + + 3. 閫氳繃鍙嶅皠鎵惧埌瀵硅薄鐨勬墍鏈塯etter鏂规硶锛堜緥濡 getMessage锛, + 閫氳繃鍙嶅皠鏉ヨ皟鐢紝 鎶婂煎拰灞炴у舰鎴愪竴涓狧ashMap , 渚嬪 {"message": "鐧诲綍鎴愬姛"} , + 鏀惧埌View瀵硅薄鐨刾arameters + + 4. 鏍规嵁struts.xml涓殑 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛 + 鏀惧埌View瀵硅薄鐨刯sp瀛楁涓 + + */ + HashMap Parameters = new HashMap<>(); + View view = new View(); + SAXReader reader = new SAXReader(); + Document document = reader.read(new File("./src/com/coderising/litestruts/struts.xml")); + Element root = document.getRootElement(); + Element thiselement = null; + List list = root.elements(); + String classpath = null; + for (Element element : list) { + //System.out.println(element.attribute("name").getValue()); + if (element.attribute("name").getValue().equals(actionName)) { + thiselement = element; + classpath = element.attribute("class").getValue(); + break; + } + } + Class ojbect; + + try { + ojbect=Class.forName(classpath); + Object acionclass = ojbect.newInstance(); + for (String string : parameters.keySet()) { + Method method = ojbect.getMethod("set"+upperCase(string),String.class); + method.invoke(acionclass,parameters.get(string)); + } + Method execute = ojbect.getMethod("execute"); + String result= (String) execute.invoke(acionclass); + //鍒ゆ柇杩斿洖鐨刯sp + List elementresult = thiselement.elements(); + for (Element element:elementresult){ + if (element.attribute("name").getValue().equals(result)) { + view.setJsp(element.getStringValue()); + break; + } + } + // 鑾峰緱getter鏂规硶,骞惰缃甈arameters + Method[] methods = ojbect.getDeclaredMethods(); + + for (Method method : methods) { + if (method.getName().substring(0, 3).equals("get")) { + String attribute= (String) method.invoke(acionclass); + Parameters.put(method.getName().substring(3).toLowerCase(), attribute); + } + } + view.setParameters(Parameters); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + + + return view; + } + //棣栧瓧姣嶅ぇ鍐 + public static String upperCase(String str) { + char[] ch = str.toCharArray(); + if (ch[0] >= 'a' && ch[0] <= 'z') { + ch[0] = (char) (ch[0] - 32); + } + return new String(ch); + } + +} diff --git a/group15/1502_1617273078/src/com/coderising/litestruts/StrutsTest.java b/group15/1502_1617273078/src/com/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..05b7a00aa8 --- /dev/null +++ b/group15/1502_1617273078/src/com/coderising/litestruts/StrutsTest.java @@ -0,0 +1,44 @@ +package com.coderising.litestruts; + +import java.util.HashMap; +import java.util.Map; + +import org.dom4j.DocumentException; +import org.junit.Assert; +import org.junit.Test; + + + + + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() throws DocumentException { + + String actionName = "login"; + + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() throws DocumentException { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //瀵嗙爜鍜岄璁剧殑涓嶄竴鑷 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group15/1502_1617273078/src/com/coderising/litestruts/View.java b/group15/1502_1617273078/src/com/coderising/litestruts/View.java new file mode 100644 index 0000000000..07df2a5dab --- /dev/null +++ b/group15/1502_1617273078/src/com/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coderising.litestruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group15/1502_1617273078/src/com/coderising/litestruts/struts.xml b/group15/1502_1617273078/src/com/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..07f80b6476 --- /dev/null +++ b/group15/1502_1617273078/src/com/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file diff --git a/group15/1506_1084478979/1506_1084478979/.classpath b/group15/1506_1084478979/1506_1084478979/.classpath index fceb4801b5..373dce4005 100644 --- a/group15/1506_1084478979/1506_1084478979/.classpath +++ b/group15/1506_1084478979/1506_1084478979/.classpath @@ -2,5 +2,6 @@ + diff --git a/group15/1506_1084478979/1506_1084478979/.settings/org.eclipse.core.resources.prefs b/group15/1506_1084478979/1506_1084478979/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..ac8e1d1ea4 --- /dev/null +++ b/group15/1506_1084478979/1506_1084478979/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/banshee/WorkTwo=GBK +encoding//src/banshee/WorkTwo/ArrayUtil.java=UTF-8 +encoding/=UTF-8 diff --git a/group15/1506_1084478979/1506_1084478979/RemoteSystemsTempFiles/.project b/group15/1506_1084478979/1506_1084478979/RemoteSystemsTempFiles/.project new file mode 100644 index 0000000000..5447a64fa9 --- /dev/null +++ b/group15/1506_1084478979/1506_1084478979/RemoteSystemsTempFiles/.project @@ -0,0 +1,12 @@ + + + RemoteSystemsTempFiles + + + + + + + org.eclipse.rse.ui.remoteSystemsTempNature + + diff --git a/group15/1506_1084478979/1506_1084478979/src/RemoteSystemsTempFiles/.project b/group15/1506_1084478979/1506_1084478979/src/RemoteSystemsTempFiles/.project new file mode 100644 index 0000000000..5447a64fa9 --- /dev/null +++ b/group15/1506_1084478979/1506_1084478979/src/RemoteSystemsTempFiles/.project @@ -0,0 +1,12 @@ + + + RemoteSystemsTempFiles + + + + + + + org.eclipse.rse.ui.remoteSystemsTempNature + + diff --git a/group15/1506_1084478979/1506_1084478979/src/banshee/ArrayList.java b/group15/1506_1084478979/1506_1084478979/src/banshee/ArrayList.java index d3afe067a7..5cc79a3457 100644 --- a/group15/1506_1084478979/1506_1084478979/src/banshee/ArrayList.java +++ b/group15/1506_1084478979/1506_1084478979/src/banshee/ArrayList.java @@ -40,16 +40,16 @@ public int size(){ return -1; } - public Iterator iterator(){ - //TODO - //不会。。。 - return null; - } +// public Iterator iterator(){ +// //TODO +// //锟斤拷锟结。锟斤拷锟斤拷 +// return null; +// } private void rangeCheck( int index) { if (index >= size || index < 0){ - throw new IndexOutOfBoundsException("指定的index超过界限"); + throw new IndexOutOfBoundsException("指锟斤拷锟斤拷index锟斤拷锟斤拷锟斤拷锟斤拷"); } } @@ -57,7 +57,7 @@ private void rangeCheck( int index) { public void ensureCapacity(int minCapacity) { int oldCapacity = elementData.length; if (minCapacity > oldCapacity) { - //计算新的容量大小,为当前容量的1.5倍 + //锟斤拷锟斤拷锟铰碉拷锟斤拷锟斤拷锟斤拷小锟斤拷为锟斤拷前锟斤拷锟斤拷锟斤拷1.5锟斤拷 int newCapacity = (oldCapacity * 3) / 2 + 1; if (newCapacity < minCapacity) newCapacity = minCapacity; diff --git a/group15/1506_1084478979/1506_1084478979/src/banshee/LinkedList.java b/group15/1506_1084478979/1506_1084478979/src/banshee/LinkedList.java index f5fe5b5a31..9462e7fbae 100644 --- a/group15/1506_1084478979/1506_1084478979/src/banshee/LinkedList.java +++ b/group15/1506_1084478979/1506_1084478979/src/banshee/LinkedList.java @@ -2,7 +2,8 @@ import java.util.NoSuchElementException; -public class LinkedList implements List { + +public class LinkedList { private Node head; private Node last; @@ -74,11 +75,11 @@ public Object removeLast(){ size--; return e; } - public Iterator iterator(){ - //TODO - //不会... - return null; - } +// public Iterator iterator(){ +// //TODO +// //锟斤拷锟斤拷... +// return null; +// } private static class Node{ @@ -119,7 +120,7 @@ private void linkBrfore(Object element , Node spNode ){ private void rangeCheck(int index) { if (index > size || index < 0) { - throw new IndexOutOfBoundsException("指定的index超过界限"); + throw new IndexOutOfBoundsException("指锟斤拷锟斤拷index锟斤拷锟斤拷锟斤拷锟斤拷"); } } diff --git a/group15/1506_1084478979/1506_1084478979/src/banshee/RemoteSystemsTempFiles/.project b/group15/1506_1084478979/1506_1084478979/src/banshee/RemoteSystemsTempFiles/.project new file mode 100644 index 0000000000..5447a64fa9 --- /dev/null +++ b/group15/1506_1084478979/1506_1084478979/src/banshee/RemoteSystemsTempFiles/.project @@ -0,0 +1,12 @@ + + + RemoteSystemsTempFiles + + + + + + + org.eclipse.rse.ui.remoteSystemsTempNature + + diff --git a/group15/1506_1084478979/1506_1084478979/src/banshee/WorkTwo/ArrayUtil.java b/group15/1506_1084478979/1506_1084478979/src/banshee/WorkTwo/ArrayUtil.java new file mode 100644 index 0000000000..3bac4a642c --- /dev/null +++ b/group15/1506_1084478979/1506_1084478979/src/banshee/WorkTwo/ArrayUtil.java @@ -0,0 +1,165 @@ +package banshee.WorkTwo; + +import java.util.Arrays; +import java.util.ArrayList; + + +public class ArrayUtil { + + /** + * 缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 + 渚嬪锛 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){ + int j = origin.length - 1; + int temp; + for(int i = 0; i < origin.length /2; i++,j--){ + temp = origin[j]; + origin[j] = origin[i]; + origin[i] = temp; + } + + } + + /** + * 鐜板湪鏈夊涓嬬殑涓涓暟缁勶細 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[] newArr = new int[oldArray.length]; + int j = 0; + for (int i = 0; i < newArr.length; i++) { + if (oldArray[i] != 0){ + newArr[j] = oldArray[i]; + j++; + } + } + + return Arrays.copyOfRange(newArr, 0, j) ; + } + + /** + * 缁欏畾涓や釜宸茬粡鎺掑簭濂界殑鏁村舰鏁扮粍锛 a1鍜宎2 , 鍒涘缓涓涓柊鐨勬暟缁刟3, 浣垮緱a3 鍖呭惈a1鍜宎2 鐨勬墍鏈夊厓绱狅紝 骞朵笖浠嶇劧鏄湁搴忕殑 + * 渚嬪 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){ + + int i = 0,j = 0, k = 0; + int[] array3 = new int[array1.length + array2.length]; + + while (i < array1.length && j < array2.length) { + if (array1[i] < array2[j]) { + array3[k++] = array1[i++]; + } else if (array1[i] > array2[j]) { + array3[k++] = array2[j++]; + }else { + array3[k++] = array1[i++]; + j++; + } + } + while (i < array1.length) { + array3[k++] = array1[i++]; + } + while (j < array2.length) { + array3[k++] = array2[j++]; + } + return Arrays.copyOf(array3, k); + } + /** + * 鎶婁竴涓凡缁忓瓨婊℃暟鎹殑鏁扮粍 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){ + int newCapacity = oldArray.length + size; + int[] newArr = Arrays.copyOf(oldArray, newCapacity); + return newArr; + } + + /** + * 鏂愭尝閭e鏁板垪涓猴細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){ + ArrayList list = new ArrayList(); + if (max == 1) { + return new int[0]; + }else{ + list.add(1); + list.add(1); + int temp = 0, a = 1,b = 1; + while (a + b < max) { + list.add(a + b); + temp = a; + a = b; + b = temp + b; + } + } + int[] arr = new int[list.size()]; + for (int i = 0; i < list.size(); i++) { + + arr[i] = (Integer) list.get(i); + + } + return arr; + } + + /** + * 杩斿洖灏忎簬缁欏畾鏈澶у糾ax鐨勬墍鏈夌礌鏁版暟缁 + * 渚嬪max = 23, 杩斿洖鐨勬暟缁勪负[2,3,5,7,11,13,17,19] + * @param max + * @return + */ + public int[] getPrimes(int max){ + return null; + } + + /** + * 鎵璋撯滃畬鏁扳濓紝 鏄寚杩欎釜鏁版伆濂界瓑浜庡畠鐨勫洜瀛愪箣鍜岋紝渚嬪6=1+2+3 + * 缁欏畾涓涓渶澶у糾ax锛 杩斿洖涓涓暟缁勶紝 鏁扮粍涓槸灏忎簬max 鐨勬墍鏈夊畬鏁 + * @param max + * @return + */ + public int[] getPerfectNumbers(int max){ + return null; + } + + /** + * 鐢╯eperator 鎶婃暟缁 array缁欒繛鎺ヨ捣鏉 + * 渚嬪array= [3,8,9], seperator = "-" + * 鍒欒繑鍥炲间负"3-8-9" + * @param array + * @param s + * @return + */ + public String join(int[] array, String seperator){ + StringBuilder sb = new StringBuilder(); + for (int element : array) { + sb.append(element).append(seperator); + } + sb.setLength(sb.length() - 1); + return sb.toString(); + } + + + + +} diff --git a/group15/1506_1084478979/1506_1084478979/src/banshee/WorkTwo/ArrayUtilTest.java b/group15/1506_1084478979/1506_1084478979/src/banshee/WorkTwo/ArrayUtilTest.java new file mode 100644 index 0000000000..4b0c7cd328 --- /dev/null +++ b/group15/1506_1084478979/1506_1084478979/src/banshee/WorkTwo/ArrayUtilTest.java @@ -0,0 +1,72 @@ +package banshee.WorkTwo; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ArrayUtilTest { + + private ArrayUtil util; + + @Before + public void setUp() throws Exception { + util = new ArrayUtil(); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testReverseArray() throws Exception { + int[] origin1 = {7, 9 , 30, 3}; + int[] origin2 = {7, 9, 30, 3, 4}; + util.reverseArray(origin1); + util.reverseArray(origin2); + assertArrayEquals(new int[]{3, 30, 9,7}, origin1); + assertArrayEquals(new int[]{4,3, 30 , 9,7}, origin2); + } + + @Test + public void testRemoveZero() throws Exception { + int oldArr[] = {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5}; + assertArrayEquals(new int[]{1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 5}, util.removeZero(oldArr)); + } + + @Test + public void testMerge() throws Exception{ + int[] arr1 = new int[]{3, 5, 7, 8}; + int[] arr2 = new int[]{4, 5, 6, 7}; + assertArrayEquals(new int[]{3, 4, 5, 6, 7, 8}, util.merge(arr1, arr2)); + } + + @Test + public void testGrow() throws Exception{ + int[] old = new int[]{2, 3, 6}; + assertArrayEquals(util.grow(old, 3), new int[]{2, 3, 6, 0, 0, 0}); + } + + @Test + public void testFibonacci() throws Exception { + assertArrayEquals(new int[]{1, 1, 2, 3, 5, 8, 13}, util.fibonacci(15)); + } + + @Test + public void testGetPrimes() { + fail("Not yet implemented"); + } + + @Test + public void testGetPerfectNumbers() { + fail("Not yet implemented"); + } + + @Test + public void testJoin() throws Exception { + int[] arr = new int[]{3, 8, 9}; + assertEquals("3-8-9", util.join(arr, "-")); + } + +} diff --git a/group15/1510_739253131/src/com/bruce/homework0305/array/ArrayUtil.java b/group15/1510_739253131/src/com/bruce/homework0305/array/ArrayUtil.java new file mode 100644 index 0000000000..85276ce4da --- /dev/null +++ b/group15/1510_739253131/src/com/bruce/homework0305/array/ArrayUtil.java @@ -0,0 +1,232 @@ +package com.bruce.homework0305.array; + +import com.bruce.homework0226.LinkedListV00; + +import java.util.*; + +public class ArrayUtil { + + /** + * 缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 + 渚嬪锛 a = [7, 9 , 30, 3] , 缃崲鍚庝负 [3, 30, 9,7] + 濡傛灉 a = [7, 9, 30, 3, 4] , 缃崲鍚庝负 [4,3, 30 , 9,7] + * @param origin + * @return + */ + public int[] reverseArray(int[] origin){ + if(origin != null && origin.length > 0) { + int temp; + for (int i = 0; i < origin.length / 2; i++) { + temp = origin[i]; + origin[i] = origin[origin.length-1 - i]; + origin[origin.length-1 - i] = temp; + } + } + return origin; + } + + /** + * 鐜板湪鏈夊涓嬬殑涓涓暟缁勶細 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[] result = null; + if(oldArray != null && oldArray.length >= 0){ + int index = 0; + LinkedList linkedList = new LinkedList(); + for(int i = 0;i list = new LinkedList<>(); + getElementFromArray(array1,list); + getElementFromArray(array2,list); + Collections.sort(list); + int[] result = new int[list.size()]; + for(int n = 0;n Integer.MAX_VALUE) { + return result;//鎶涘嚭寮傚父 + } else if (max == 1) { + result = new int[0]; + } else { + ArrayList list = new ArrayList(); + list.add(1); + list.add(1); + for (int i = 2;i max){ + break; + } + list.add(i,(list.get(i-2)+list.get(i-1))); + } + result = new int[list.size()]; + for (int j=0;j Integer.MAX_VALUE) { + return result;//鎶涘嚭寮傚父 + } else if(max == 1){ + result = new int[0]; + }else { + ArrayList list = new ArrayList<>(); + for (int i=2 ; i<=max ; i++) { + if(isPrimes(i)){ + list.add(i); + } + } + result = new int[list.size()]; + for(int m = 0 ; m Integer.MAX_VALUE){ + return result; + } else { + LinkedList list = new LinkedList<>(); + for(int i = 1 ; i < max ; i++){ + if (isPerfectNumber(i)) { + list.add(i); + } + } + result = new int[list.size()]; + for (int i = 0 ; i < list.size() ; i++) { + result[i] = list.get(i); + } + } + return result; + } + + //鍒ゆ柇涓涓暟鏄惁鏄畬鏁帮紝true锛氭槸瀹屾暟锛沠alse锛氫笉鏄畬鏁般 + public boolean isPerfectNumber(int value){ + int sum = 0; + for(int i = 1 ; i < value ; i++){ + if(value % i == 0){ + sum += i; + } + } + return sum == value; + } + + /** + * 鐢╯eperator 鎶婃暟缁 array缁欒繛鎺ヨ捣鏉 + * 渚嬪array= [3,8,9], seperator = "-" + * 鍒欒繑鍥炲间负"3-8-9" + * @param array + * @param s + * @return + */ + public String join(int[] array, String seperator){ + StringBuffer sb = new StringBuffer(); + if (array != null && array.length >= 1) { + for (int i = 0 ; i < array.length ; i++) { + sb.append(array[i]); + if (i < array.length-1) { + sb.append(seperator); + } + } + } + return sb.toString(); + } + + +} diff --git a/group15/1510_739253131/src/com/bruce/homework0305/array/JuintArrayUtil.java b/group15/1510_739253131/src/com/bruce/homework0305/array/JuintArrayUtil.java new file mode 100644 index 0000000000..eb5487e76d --- /dev/null +++ b/group15/1510_739253131/src/com/bruce/homework0305/array/JuintArrayUtil.java @@ -0,0 +1,84 @@ +package com.bruce.homework0305.array; + +import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by Bruce.Jiao on 2017/3/2. + */ +public class JuintArrayUtil extends TestCase { + + @Test + public void testReverse(){ + ArrayUtil au = new ArrayUtil(); + int[] demo0 = {}; + int[] demo1 = {6}; + int[] demo = {7, 9, 30, 3, 4, 6}; + int[] nullArray = au.reverseArray(null); + int[] reverseArray0 = au.reverseArray(demo0); + int[] reverseArray1 = au.reverseArray(demo1); + int[] reverseArray = au.reverseArray(demo); + System.out.println(Arrays.toString(nullArray)); + System.out.println(Arrays.toString(reverseArray0)); + System.out.println(Arrays.toString(reverseArray1)); + System.out.println(Arrays.toString(reverseArray)); + } + + @Test + public void testRemoveZero(){ + ArrayUtil au = new ArrayUtil(); + int[] one = {0}; + int[] many = {1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}; + System.out.println(Arrays.toString(au.removeZero(one))); + System.out.println(Arrays.toString(au.removeZero(many))); + System.out.println(Arrays.toString(au.removeZero(null))); + System.out.println(Arrays.toString(au.removeZero(new int[0]))); + } + + @Test + public void testMerge(){ + ArrayUtil au = new ArrayUtil(); + int[] arr1 = {3,4,5,6,7,8,9}; + int[] arr2 = {1,3,5,6,7,9,10,12,13}; + int[] arr3 = null; + int[] arr4 = new int[0]; + System.out.println(Arrays.toString(au.merge(arr1,arr2))); + System.out.println(Arrays.toString(au.merge(arr1,arr3))); + System.out.println(Arrays.toString(au.merge(arr2,arr4))); + } + + @Test + public void testGrow(){ + ArrayUtil au = new ArrayUtil(); + int[] arr = {3,4,5,6,7,8,9}; + System.out.println(Arrays.toString(au.grow(arr,5))); + } + + @Test + public void testFibonacci(){ + ArrayUtil au = new ArrayUtil(); + System.out.println(Arrays.toString(au.fibonacci(15))); + } + + @Test + public void testPrimes(){ + ArrayUtil au = new ArrayUtil(); + System.out.println(Arrays.toString(au.getPrimes(23))); + } + + @Test + public void testPerfectNumbers(){ + ArrayUtil au = new ArrayUtil(); + System.out.println(Arrays.toString(au.getPerfectNumbers(23))); + } + + @Test + public void testJoin(){ + ArrayUtil au = new ArrayUtil(); + int[] array = {1,6,8,8,8,8,8,8,8,8,8,}; + System.out.println(au.join(array,"-")); + } +} diff --git a/group15/1510_739253131/src/com/bruce/homework0305/mystruts/LoginAction.java b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/LoginAction.java new file mode 100644 index 0000000000..4b509b2102 --- /dev/null +++ b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/LoginAction.java @@ -0,0 +1,39 @@ +package com.bruce.homework0305.mystruts; + +/** + * 杩欐槸涓涓敤鏉ュ睍绀虹櫥褰曠殑涓氬姟绫伙紝 鍏朵腑鐨勭敤鎴峰悕鍜屽瘑鐮侀兘鏄‖缂栫爜鐨勩 + * @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; + } +} diff --git a/group15/1510_739253131/src/com/bruce/homework0305/mystruts/Struts.java b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/Struts.java new file mode 100644 index 0000000000..ab54fd0625 --- /dev/null +++ b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/Struts.java @@ -0,0 +1,81 @@ +package com.bruce.homework0305.mystruts; + +import com.sun.deploy.util.StringUtils; +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; +import org.junit.Test; + +import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.*; + + +public class Struts { + + public static View runAction(String actionName, Map parameters) throws DocumentException, + ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException { + + /* + 0. 璇诲彇閰嶇疆鏂囦欢struts.xml + 1. 鏍规嵁actionName鎵惧埌鐩稿搴旂殑class 锛 渚嬪LoginAction, 閫氳繃鍙嶅皠瀹炰緥鍖栵紙鍒涘缓瀵硅薄锛 + 鎹畃arameters涓殑鏁版嵁锛岃皟鐢ㄥ璞$殑setter鏂规硶锛 渚嬪parameters涓殑鏁版嵁鏄 + ("name"="test" , "password"="1234") , + 閭e氨搴旇璋冪敤 setName鍜宻etPassword鏂规硶 + 2. 閫氳繃鍙嶅皠璋冪敤瀵硅薄鐨別xectue 鏂规硶锛 骞惰幏寰楄繑鍥炲硷紝渚嬪"success" + 3. 閫氳繃鍙嶅皠鎵惧埌瀵硅薄鐨勬墍鏈塯etter鏂规硶锛堜緥濡 getMessage锛, + 閫氳繃鍙嶅皠鏉ヨ皟鐢紝 鎶婂煎拰灞炴у舰鎴愪竴涓狧ashMap , 渚嬪 {"message": "鐧诲綍鎴愬姛"} , + 鏀惧埌View瀵硅薄鐨刾arameters + 4. 鏍规嵁struts.xml涓殑 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛 + 鏀惧埌View瀵硅薄鐨刯sp瀛楁涓 + */ + SAXReader reader = new SAXReader(); + Document document = reader.read(new File("src/com/bruce/homework0305/mystruts/struts.xml")); + Element root = document.getRootElement(); + Iterator actions = root.elementIterator("action"); + HashMap map = new HashMap<>(); + View view = new View(); + while(actions.hasNext()){ + Element next = actions.next(); + List attributes = next.attributes(); + Attribute action_name = next.attribute("name"); + if(actionName.equals(action_name.getValue())){ + //鎵惧埌name="login"鐨刟ction,鎷垮埌鍏禼lass璺緞 + Attribute aClass = next.attribute("class"); + //閫氳繃鍙嶅皠鎷垮埌LoginAction绫 + Class clazz = Class.forName(aClass.getValue()); + LoginAction login = (LoginAction) clazz.newInstance(); + //浠巔arameters涓嬁鍒版墍鏈夌殑key锛岄氳繃杩欎簺key鎷垮埌瀵瑰簲鐨勫硷紝骞朵笖浼犲叆LoginAction瀵瑰簲鐨剆etter鏂规硶 + Set keys = parameters.keySet();parameters.entrySet(); + for(String key : keys){ + //棣栧瓧姣嶅ぇ鍐欙紝鎷垮埌setter鏂规硶,骞跺皢parameters涓搴旇key鐨剉alue鎷垮嚭鏉ワ紝鍙嶅皠浼犲叆鐩稿簲鏂规硶 + String setter = "set"+ key.substring(0,1).toUpperCase()+key.substring(1,key.length()); + Method method = clazz.getMethod(setter,String.class); + method.invoke(login,parameters.get(key)); + } + //鍙嶅皠鎷垮埌execute鏂规硶锛屽苟鎷垮埌鎵ц缁撴灉 + Method execute = clazz.getMethod("execute"); + String result = (String) execute.invoke(login); + //鍙嶅皠鎷垮埌getMessage鏂规硶,缁撴灉浠ap鏍煎紡淇濆瓨锛屽苟淇濆瓨鍦╲iew瀵硅薄涓 + Method getMessage = clazz.getMethod("getMessage"); + String message = (String)getMessage.invoke(login); + map.put("message",message); + view.setParameters(map); + //鏍规嵁execute鏂规硶鐨勬墽琛岀粨鏋滐紝鎵惧埌鐩稿叧result鐨刯sp璺緞锛屽皢璇ヨ矾寰勪繚瀛樺湪view瀵硅薄涓 + Iterator results = next.elementIterator("result"); + while(results.hasNext()){ + Element element = results.next(); + if(result.equals(element.attribute("name").getValue())){ + view.setJsp(element.getText()); + break; + } + } + } + } + return view; + } +} diff --git a/group15/1510_739253131/src/com/bruce/homework0305/mystruts/StrutsTest.java b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/StrutsTest.java new file mode 100644 index 0000000000..e54809e4b6 --- /dev/null +++ b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/StrutsTest.java @@ -0,0 +1,61 @@ +package com.bruce.homework0305.mystruts; + +import org.dom4j.DocumentException; +import org.junit.Assert; +import org.junit.Test; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() { + try { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + View view = Struts.runAction(actionName,params); + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } catch (DocumentException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + @Test + public void testLoginActionFailed() { + try { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //瀵嗙爜鍜岄璁剧殑涓嶄竴鑷 + View view = Struts.runAction(actionName,params); + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } catch (DocumentException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } +} diff --git a/group15/1510_739253131/src/com/bruce/homework0305/mystruts/View.java b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/View.java new file mode 100644 index 0000000000..47abd77a37 --- /dev/null +++ b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/View.java @@ -0,0 +1,23 @@ +package com.bruce.homework0305.mystruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group15/1510_739253131/src/com/bruce/homework0305/mystruts/struts.xml b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/struts.xml new file mode 100644 index 0000000000..41c7be3d2f --- /dev/null +++ b/group15/1510_739253131/src/com/bruce/homework0305/mystruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file diff --git a/group15/1511_714512544/.idea/workspace.xml b/group15/1511_714512544/.idea/workspace.xml index e9a1aea025..cb4932867a 100644 --- a/group15/1511_714512544/.idea/workspace.xml +++ b/group15/1511_714512544/.idea/workspace.xml @@ -1,9 +1,7 @@ - - - + @@ -76,7 +93,7 @@ - + @@ -89,8 +106,9 @@ - + + @@ -116,6 +134,10 @@ @@ -130,11 +152,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - + - - + + + + - - + + + + + + + + + + + + + - - + - - + - - + - @@ -770,7 +823,28 @@ - + + + + + + + + + + + + + + + + + + + + + + 1487829266287 @@ -828,77 +902,149 @@ - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + + + + + + + + - - - - - + - - - - - - + + + + + + + + + + + + - - @@ -933,12 +1079,14 @@ - + + @@ -947,29 +1095,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -1012,13 +1137,6 @@ - - - - - - - @@ -1061,6 +1179,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1068,143 +1251,231 @@ - + - - + + - + - - - + + - + - - + + - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + - + - - + + - - - - - - - - - - - - + + - + - - - + + - + - - + + + - + - - - + + - + - - - - - - + + - - - + + + + + + + + + - + - - - + + + + + + - + - - - + + + + + + - - + + + + + + + + + + + + + + + + + + diff --git a/group15/1511_714512544/1511_714512544.iml b/group15/1511_714512544/1511_714512544.iml index 3ab15b1867..1868349e70 100644 --- a/group15/1511_714512544/1511_714512544.iml +++ b/group15/1511_714512544/1511_714512544.iml @@ -10,7 +10,16 @@ - + + + + + + + + + + diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coderising/array/ArrayUtil.class b/group15/1511_714512544/out/production/1511_714512544/com/coderising/array/ArrayUtil.class new file mode 100644 index 0000000000..e84a8b4b40 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coderising/array/ArrayUtil.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coderising/array/ArrayUtilTest.class b/group15/1511_714512544/out/production/1511_714512544/com/coderising/array/ArrayUtilTest.class new file mode 100644 index 0000000000..f7b0cd1b22 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coderising/array/ArrayUtilTest.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/LoginAction.class b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/LoginAction.class new file mode 100644 index 0000000000..d781f45ce9 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/LoginAction.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/Struts.class b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/Struts.class new file mode 100644 index 0000000000..02b3ad4da2 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/Struts.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/StrutsTest.class b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/StrutsTest.class new file mode 100644 index 0000000000..ab32147b2a Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/StrutsTest.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/View.class b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/View.class new file mode 100644 index 0000000000..e7a5112144 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/View.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/struts.xml b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..07f80b6476 --- /dev/null +++ b/group15/1511_714512544/out/production/1511_714512544/com/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList$1.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList$1.class new file mode 100644 index 0000000000..c4306e1489 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList$1.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList$ListIterator.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList$ListIterator.class new file mode 100644 index 0000000000..1d423f2cc8 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList$ListIterator.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList.class new file mode 100644 index 0000000000..b3a53ec4c1 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/ArrayList.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/BinarySearchTree.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/BinarySearchTree.class new file mode 100644 index 0000000000..5998f97032 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/BinarySearchTree.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/BinarySearchTreeNode.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/BinarySearchTreeNode.class new file mode 100644 index 0000000000..2fbda2a306 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/BinarySearchTreeNode.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Iterator.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Iterator.class new file mode 100644 index 0000000000..16c3f1aded Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Iterator.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$1.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$1.class new file mode 100644 index 0000000000..648241c965 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$1.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$ListIterator.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$ListIterator.class new file mode 100644 index 0000000000..4097ca6433 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$ListIterator.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$Node.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$Node.class new file mode 100644 index 0000000000..466c28ba4f Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList$Node.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList.class new file mode 100644 index 0000000000..7ac1a0fa80 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/LinkedList.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/List.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/List.class new file mode 100644 index 0000000000..82055051ce Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/List.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Queue.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Queue.class new file mode 100644 index 0000000000..60e7cea803 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Queue.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Stack.class b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Stack.class new file mode 100644 index 0000000000..c309e6c5e7 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/com/coding/basic/Stack.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/ArrayListTest.class b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/ArrayListTest.class new file mode 100644 index 0000000000..435d12baf4 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/ArrayListTest.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/BinarySearchTreeTest.class b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/BinarySearchTreeTest.class new file mode 100644 index 0000000000..167f83c32c Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/BinarySearchTreeTest.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/LinkedListTest.class b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/LinkedListTest.class new file mode 100644 index 0000000000..2b2fb7b768 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/LinkedListTest.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/QueueTest.class b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/QueueTest.class new file mode 100644 index 0000000000..fcd2281a17 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/QueueTest.class differ diff --git a/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/StackTest.class b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/StackTest.class new file mode 100644 index 0000000000..1b08c84113 Binary files /dev/null and b/group15/1511_714512544/out/production/1511_714512544/test/com/coding/basic/StackTest.class differ diff --git a/group15/1511_714512544/src/com/coderising/array/ArrayUtil.java b/group15/1511_714512544/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..cd48c18e32 --- /dev/null +++ b/group15/1511_714512544/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,183 @@ +package com.coderising.array; + +import java.util.Arrays; + +public class ArrayUtil { + + /** + * 缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 + 渚嬪锛 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){ + int len = origin.length; + int temp = 0; + for (int i = 0; i < len/2; i++) { + temp = origin[i]; + origin[i] = origin[len -1 -i]; + origin[len -1 -i] = temp; + } + } + + /** + * 鐜板湪鏈夊涓嬬殑涓涓暟缁勶細 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[] temp = new int[oldArray.length]; + int index = 0; + for (int i : oldArray) { + if(i != 0){ + temp[index++] = i; + } + } + if(index == 0){ + return new int[]{}; + } + return Arrays.copyOf(temp, index); + } + + /** + * 缁欏畾涓や釜宸茬粡鎺掑簭濂界殑鏁村舰鏁扮粍锛 a1鍜宎2 , 鍒涘缓涓涓柊鐨勬暟缁刟3, 浣垮緱a3 鍖呭惈a1鍜宎2 鐨勬墍鏈夊厓绱狅紝 骞朵笖浠嶇劧鏄湁搴忕殑 + * 渚嬪 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){ + int[] array3 = new int[array1.length+array2.length]; + for (int i = 0; i < array1.length; i++) { + array3[i] = array1[i]; + } + int index = array1.length; + for (int i = 0; i < array2.length; i++) { + boolean flag = true; //a2鍏冪礌涓嶅湪a3涓 + for (int j = 0; j < index; j++) { + if(array3[j] == array2[i]){ + flag = false; + } + } + if(flag){ //a2鍏冪礌涓嶅湪a3涓 + array3[index++] = array2[i]; + } + } + int[] temp = Arrays.copyOf(array3, index); + Arrays.sort(temp); + return temp; + } + /** + * 鎶婁竴涓凡缁忓瓨婊℃暟鎹殑鏁扮粍 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 Arrays.copyOf(oldArray, oldArray.length+size); + } + + /** + * 鏂愭尝閭e鏁板垪涓猴細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){ + if(max == 1) return new int[]{}; //max=1锛岃繑鍥炵┖鏁扮粍 + int[] arr = new int[max+1]; + arr[0] = 1; + arr[1] = 1; + + int sum = 2; + for (int i = 2; i < arr.length; i++) { + arr[i] = arr[i-1] + arr[i-2]; + if(arr[i] >= max){ + break; + } + sum ++; + } + return Arrays.copyOf(arr, sum); + } + + /** + * 杩斿洖灏忎簬缁欏畾鏈澶у糾ax鐨勬墍鏈夌礌鏁版暟缁 + * 渚嬪max = 23, 杩斿洖鐨勬暟缁勪负[2,3,5,7,11,13,17,19] + * @param max + * @return + */ + public int[] getPrimes(int max){ + if(max<=2) return new int[]{}; + + int[] temp = new int[max]; + int index = 0; + for (int i = 2; i < max; i++) { + boolean flag = true; + for (int j = 2; j <= Math.sqrt(i); j++) { + if(i % j == 0){ + flag = false; + } + } + if(flag){temp[index++] = i;} + } + return Arrays.copyOf(temp, index); + } + + /** + * 鎵璋撯滃畬鏁扳濓紝 鏄寚杩欎釜鏁版伆濂界瓑浜庡畠鐨勫洜瀛愪箣鍜岋紝渚嬪6=1+2+3 + * 缁欏畾涓涓渶澶у糾ax锛 杩斿洖涓涓暟缁勶紝 鏁扮粍涓槸灏忎簬max 鐨勬墍鏈夊畬鏁 + * @param max + * @return + */ + public int[] getPerfectNumbers(int max){ + if(max <= 2) return new int[]{}; + + int[] temp = new int[max]; + int index = 0; + for (int i = 2; i < max; i++) { + int sum = 0; + for (int j = 1; j <= Math.sqrt(i); j++) { + if(j == 1) { + sum += 1; + }else{ + if(i % j == 0){ + sum += j + i/j; + } + } + } + if(sum == i) temp[index++] = i; + } + return Arrays.copyOf(temp, index); + } + + /** + * 鐢╯eperator 鎶婃暟缁 array缁欒繛鎺ヨ捣鏉 + * 渚嬪array= [3,8,9], seperator = "-" + * 鍒欒繑鍥炲间负"3-8-9" + * @param array + * @param seperator + * @return + */ + public String join(int[] array, String seperator){ + if(array.length == 0){ + return ""; + } + StringBuilder sb = new StringBuilder(); + for (int i : array) { + sb.append(i).append(seperator); + } + String temp = sb.toString(); + return temp.substring(0,temp.length()-1); + } + + +} \ No newline at end of file diff --git a/group15/1511_714512544/src/com/coderising/array/ArrayUtilTest.java b/group15/1511_714512544/src/com/coderising/array/ArrayUtilTest.java new file mode 100644 index 0000000000..939c5c7ac6 --- /dev/null +++ b/group15/1511_714512544/src/com/coderising/array/ArrayUtilTest.java @@ -0,0 +1,76 @@ +package com.coderising.array; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.*; + +/** + * ArrayList娴嬭瘯 + */ +public class ArrayUtilTest { + private ArrayUtil util = null; + + @Before + public void setUp() throws Exception { + util = new ArrayUtil(); + } + + @After + public void tearDown() throws Exception { + util = null; + } + + @Test + public void reverseArray() throws Exception { + int[] arr = new int[]{7, 9, 30, 3, 4}; + util.reverseArray(arr); + assertArrayEquals(new int[]{4,3, 30 , 9,7}, arr); + } + + @Test + public void removeZero() throws Exception { + int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}; + int[] newArr = util.removeZero(oldArr); + assertArrayEquals(new int[]{1,3,4,5,6,6,5,4,7,6,7,5}, newArr); + } + + @Test + public void merge() throws Exception { + int[] a1 = {3, 5, 7,8}; + int[] a2 = {4, 5, 6,7}; + assertArrayEquals(new int[]{3,4,5,6,7,8}, util.merge(a1, a2)); + } + + @Test + public void grow() throws Exception { + int[] oldArray = {2,3,6}; + int[] newArr = util.grow(oldArray, 3); + assertArrayEquals(new int[]{2,3,6,0,0,0}, newArr); + } + + @Test + public void fibonacci() throws Exception { + assertArrayEquals(new int[]{1,1,2,3,5,8,13}, util.fibonacci(15) ); + } + + @Test + public void getPrimes() throws Exception { + assertArrayEquals(new int[]{2,3,5,7,11,13,17,19}, util.getPrimes(23)); + } + + @Test + public void getPerfectNumbers() throws Exception { + assertArrayEquals(new int[]{6} , util.getPerfectNumbers(7)); + } + + @Test + public void join() throws Exception { + int[] array= {3,8,9}; + assertEquals("3-8-9" ,util.join(array, "-")); + } + +} \ No newline at end of file diff --git a/group15/1511_714512544/src/com/coderising/litestruts/LoginAction.java b/group15/1511_714512544/src/com/coderising/litestruts/LoginAction.java new file mode 100644 index 0000000000..dcdbe226ed --- /dev/null +++ b/group15/1511_714512544/src/com/coderising/litestruts/LoginAction.java @@ -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; + } +} diff --git a/group15/1511_714512544/src/com/coderising/litestruts/Struts.java b/group15/1511_714512544/src/com/coderising/litestruts/Struts.java new file mode 100644 index 0000000000..8822339c00 --- /dev/null +++ b/group15/1511_714512544/src/com/coderising/litestruts/Struts.java @@ -0,0 +1,113 @@ +package com.coderising.litestruts; + +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import java.io.File; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class Struts { + + public static View runAction(String actionName, Map parameters) { + /* + 0. 璇诲彇閰嶇疆鏂囦欢struts.xml + + 1. 鏍规嵁actionName鎵惧埌鐩稿搴旂殑class 锛 渚嬪LoginAction, 閫氳繃鍙嶅皠瀹炰緥鍖栵紙鍒涘缓瀵硅薄锛 + 鏍规嵁parameters涓殑鏁版嵁锛岃皟鐢ㄥ璞$殑setter鏂规硶锛 渚嬪parameters涓殑鏁版嵁鏄 + ("name"="test" , "password"="1234") , + 閭e氨搴旇璋冪敤 setName鍜宻etPassword鏂规硶 + + 2. 閫氳繃鍙嶅皠璋冪敤瀵硅薄鐨別xectue 鏂规硶锛 骞惰幏寰楄繑鍥炲硷紝渚嬪"success" + + 3. 閫氳繃鍙嶅皠鎵惧埌瀵硅薄鐨勬墍鏈塯etter鏂规硶锛堜緥濡 getMessage锛, + 閫氳繃鍙嶅皠鏉ヨ皟鐢紝 鎶婂煎拰灞炴у舰鎴愪竴涓狧ashMap , 渚嬪 {"message": "鐧诲綍鎴愬姛"} , + 鏀惧埌View瀵硅薄鐨刾arameters + + 4. 鏍规嵁struts.xml涓殑 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛 + 鏀惧埌View瀵硅薄鐨刯sp瀛楁涓 + */ + + try { + //0璇诲彇閰嶇疆鏂囦欢struts.xml + SAXReader reader = new SAXReader(); + Document doc = reader.read(new File("src/com/coderising/litestruts/struts.xml")); + Element root = doc.getRootElement(); //鏍瑰厓绱 + Map action = new HashMap<>(); + Map loginResult = new HashMap<>(); + Map logoutResult = new HashMap<>(); + java.util.Iterator iterator = root.elementIterator("action"); + while(iterator.hasNext()){ + Element actionNode = (Element) iterator.next(); + String key = actionNode.attributeValue("name"); + String value = actionNode.attributeValue("class"); + action.put(key,value); + java.util.Iterator it = actionNode.elementIterator("result"); + while(it.hasNext()){ + Element resultNode = (Element) it.next(); + String k = resultNode.attributeValue("name"); + String v = resultNode.getText(); + if(key.equals("login")){ + loginResult.put(k,v); + }else { + logoutResult.put(k,v); + } + } + } + + //1 + String className = action.get(actionName); //鑾峰彇绫诲悕 + Object o = Class.forName(className).newInstance(); //鍒涘缓瀵硅薄 + if(o instanceof LoginAction){ + LoginAction loginAction = (LoginAction) o; + Set> set = parameters.entrySet(); + for (Map.Entry en : set) { + if(en.getKey().equals("name")){ + loginAction.setName(en.getValue()); + }else if(en.getKey().equals("password")){ + loginAction.setPassword(en.getValue()); + } + } + + //2 + Class clazz = (Class) loginAction.getClass(); + Method m = clazz.getDeclaredMethod("execute",null); + m.setAccessible(true); + String message = (String) m.invoke(loginAction,null); + + //3 + View view = new View(); + Map params = new HashMap(); + Method[] ms = clazz.getDeclaredMethods(); + for (Method method : ms) { + method.setAccessible(true); + if(method.getName().equals("getName")){ + String value = (String) method.invoke(loginAction,null); + params.put("name",value); + }else if(method.getName().equals("getPassword")){ + String value = (String) method.invoke(loginAction,null); + params.put("password",value); + }else if(method.getName().equals("getMessage")){ + String value = (String) method.invoke(loginAction,null); + params.put("message",value); + } + } + view.setParameters(params); + + //4 + String jsp = loginResult.get(message); + view.setJsp(jsp); + + return view; + }else { + return null; + } + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + } + +} diff --git a/group15/1511_714512544/src/com/coderising/litestruts/StrutsTest.java b/group15/1511_714512544/src/com/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..d28d29c0e2 --- /dev/null +++ b/group15/1511_714512544/src/com/coderising/litestruts/StrutsTest.java @@ -0,0 +1,38 @@ +package com.coderising.litestruts; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() { + String actionName = "login"; + + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //瀵嗙爜鍜岄璁剧殑涓嶄竴鑷 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group15/1511_714512544/src/com/coderising/litestruts/View.java b/group15/1511_714512544/src/com/coderising/litestruts/View.java new file mode 100644 index 0000000000..07df2a5dab --- /dev/null +++ b/group15/1511_714512544/src/com/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coderising.litestruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group15/1511_714512544/src/com/coderising/litestruts/struts.xml b/group15/1511_714512544/src/com/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..07f80b6476 --- /dev/null +++ b/group15/1511_714512544/src/com/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file diff --git a/group15/1511_714512544/src/com/coding/basic/BinarySearchTree.java b/group15/1511_714512544/src/com/coding/basic/BinarySearchTree.java index 936960abab..7f30ecd124 100644 --- a/group15/1511_714512544/src/com/coding/basic/BinarySearchTree.java +++ b/group15/1511_714512544/src/com/coding/basic/BinarySearchTree.java @@ -1,5 +1,7 @@ package com.coding.basic; +import edu.princeton.cs.algs4.BinarySearch; + import java.util.Stack; /** @@ -43,15 +45,19 @@ public BinarySearchTreeNode insert(T data){ if(current.getLeft() != null){ current = current.getLeft(); }else { - current.setLeft(new BinarySearchTreeNode(data)); - return current.getLeft(); + BinarySearchTreeNode child = new BinarySearchTreeNode(data); + current.setLeft(child); + child.setParent(current); + return child; } }else {//褰撳墠鑺傜偣鏁版嵁澶т簬root if(current.getRight() != null){ current = current.getRight(); }else { - current.setRight(new BinarySearchTreeNode(data)); - return current.getRight(); + BinarySearchTreeNode child = new BinarySearchTreeNode(data); + current.setRight(child ); + child.setParent(current); + return child; } } } @@ -230,9 +236,83 @@ public void postOrderWithoutRecursion(){ } } - //鎸夊眰閬嶅巻锛屾瘡灞備粠宸﹀埌鍙宠緭鍑 - /*public void TraversalByLayer(){ + //鍒犻櫎鏌愪釜鑺傜偣n + public void delete(BinarySearchTreeNode n){ + BinarySearchTreeNode p = n.getParent(); //鑺傜偣鐨勭埗鑺傜偣 + BinarySearchTreeNode child; //鑺傜偣鐨勫瓙鑺傜偣 + + //璇ヨ妭鐐规病鏈変换浣曞瓙鑺傜偣銆// 鍙跺瓙缁撶偣锛岀洿鎺ュ垹闄ゅ嵆鍙傝鑰冭檻寰呭垹闄ょ粨鐐规槸root鐨勬儏鍐点 + if(n.getLeft()==null && n.getRight()==null){ + //璇ヨ妭鐐规槸鏍硅妭鐐 + if(n == root){ + root = null; + return ; + } + //闈炴牴鑺傜偣 + if(n == p.getLeft()){ + p.setLeft(null); + }else if(n == p.getRight()){ + p.setRight(null); + } + } + + // 鍐呴儴缁撶偣锛屾妸瀹冪殑鍚庣户鐨勫兼嫹杩涙潵锛岀劧鍚庨掑綊鍒犻櫎瀹冪殑鍚庣户銆 + else if(n.getLeft()!=null && n.getRight()!=null){ + BinarySearchTreeNode next = successor(n); //鎵惧埌n鐨勪腑搴忓悗缁ц妭鐐 + n.setData(next.getData()); + delete(next); //涓簭鍚庣户鑺傜偣 + } + + //鍙湁涓涓瀛愮殑缁撶偣锛屾妸瀹冪殑瀛╁瓙浜ょ粰瀹冪殑鐖剁粨鐐瑰嵆鍙 + else { + if(n.getLeft() != null){ //寰楀埌瀛愯妭鐐 + child = n.getLeft(); + }else { + child = n.getRight(); + } + + if(n == root){ // n鏄牴鑺傜偣鐨勬儏鍐 + child.setParent(null); + root = child; + return; + } + //闈炴牴鑺傜偣 + if(n == p.getLeft()){ + p.setLeft(child); + child.setParent(p); + }else{ + p.setRight(child); + child.setParent(p); + } + + } + } + + //鎵惧埌n鐨勪腑搴忓悗缁ц妭鐐 + public BinarySearchTreeNode successor(BinarySearchTreeNode n){ + if( n == null) return null; + if( n.getRight() == null ) return null; + return findMin(n.getRight()); + } + + //鏌ユ壘n鏍戠殑鏈灏忓 + public BinarySearchTreeNode findMin(BinarySearchTreeNode n){ + BinarySearchTreeNode current = n; + while(current.getLeft() != null){ + current = current.getLeft(); + } + return current; + } + + //鏌ユ壘n鏍戠殑鏈澶у + public BinarySearchTreeNode findMax(BinarySearchTreeNode n){ + BinarySearchTreeNode current = n; + while(current.getRight() != null){ + current = current.getRight(); + } + return current; + } + + - }*/ - } diff --git a/group15/1511_714512544/src/com/coding/basic/BinarySearchTreeNode.java b/group15/1511_714512544/src/com/coding/basic/BinarySearchTreeNode.java index b4e94ff7b6..323a040832 100644 --- a/group15/1511_714512544/src/com/coding/basic/BinarySearchTreeNode.java +++ b/group15/1511_714512544/src/com/coding/basic/BinarySearchTreeNode.java @@ -5,6 +5,7 @@ */ public class BinarySearchTreeNode{ private T data; + private BinarySearchTreeNode parent; //鐖惰妭鐐 private BinarySearchTreeNode left; private BinarySearchTreeNode right; private int state; //閫掑綊鐘舵(闈為掑綊閬嶅巻琛ㄧず涓涓妭鐐硅繍琛屽埌鐨勭姸鎬) @@ -13,6 +14,7 @@ public BinarySearchTreeNode(T data) { this.data = data; this.left = null; this.right = null; + this.parent = null; } public T getData() { @@ -46,4 +48,11 @@ public int getState() { public void setState(int state) { this.state = state; } + public BinarySearchTreeNode getParent() { + return parent; + } + + public void setParent(BinarySearchTreeNode parent) { + this.parent = parent; + } } diff --git "a/group15/1511_714512544/\346\226\207\347\253\240\345\234\260\345\235\200.md" "b/group15/1511_714512544/\346\226\207\347\253\240\345\234\260\345\235\200.md" index f6f4c26b37..3a34a9a3fb 100644 --- "a/group15/1511_714512544/\346\226\207\347\253\240\345\234\260\345\235\200.md" +++ "b/group15/1511_714512544/\346\226\207\347\253\240\345\234\260\345\235\200.md" @@ -1 +1,3 @@ (1)浠嬬粛CPU锛屽唴瀛橈紝纭洏锛屾寚浠や互鍙婁粬浠箣闂寸殑鍏崇郴鐨勬枃绔犲湴鍧锛歨ttp://www.jianshu.com/p/f86ca5072c5d + +(2)绋嬪簭鐨勬満鍣ㄥ強琛ㄧず锛 http://www.jianshu.com/p/1eed6fe682cd diff --git a/group15/1500_369516660/.classpath b/group15/1514_616019420/.classpath similarity index 74% rename from group15/1500_369516660/.classpath rename to group15/1514_616019420/.classpath index fb5011632c..3e0fb272a8 100644 --- a/group15/1500_369516660/.classpath +++ b/group15/1514_616019420/.classpath @@ -2,5 +2,6 @@ + diff --git a/group15/1514_616019420/.gitignore b/group15/1514_616019420/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group15/1514_616019420/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group15/1514_616019420/.project b/group15/1514_616019420/.project new file mode 100644 index 0000000000..fab8d7f04c --- /dev/null +++ b/group15/1514_616019420/.project @@ -0,0 +1,17 @@ + + + 2017Learning + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group15/1514_616019420/src/com/coderising/array/ArrayUtil.java b/group15/1514_616019420/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..d636e46186 --- /dev/null +++ b/group15/1514_616019420/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,205 @@ +package com.coderising.array; + +import java.lang.reflect.Array; +import java.util.*; +import com.coding.basic.ArrayList; + +public class ArrayUtil { + + /** + * 缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 渚嬪锛 a = [7, 9 , 30, 3] , 缃崲鍚庝负 [3, 30, 9,7] 濡傛灉 a = + * [7, 9, 30, 3, 4] , 缃崲鍚庝负 [4,3, 30 , 9,7] + * + * @param origin + * @return + */ + public int[] reverseArray(int[] origin) { + + if (origin != null && origin.length > 0) { + int size = origin.length; + int[] intarray = new int[size]; + for (int i = 0; i < size; i++) { + intarray[i] = origin[size - 1 - i]; + } + origin = intarray; + + } else if (origin != null && origin.length == 0) { + + } else { + throw new NullPointerException(); + } + return origin; + } + + /** + * 鐜板湪鏈夊涓嬬殑涓涓暟缁勶細 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) { + + if (oldArray != null) { + int[] intarry = new int[oldArray.length]; + int x = 0; + int y = 0; + for (int i = 0; i < oldArray.length; i++) { + if (oldArray[i] != 0) { + intarry[y] = oldArray[i]; + y++; + } else { + x++; + } + } + int[] newarray = new int[y]; + System.arraycopy(intarry, 0, newarray, 0, y); + return newarray; + } else { + throw new NullPointerException(); + } + } + + /** + * 缁欏畾涓や釜宸茬粡鎺掑簭濂界殑鏁村舰鏁扮粍锛 a1鍜宎2 , 鍒涘缓涓涓柊鐨勬暟缁刟3, 浣垮緱a3 鍖呭惈a1鍜宎2 鐨勬墍鏈夊厓绱狅紝 骞朵笖浠嶇劧鏄湁搴忕殑 渚嬪 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) { + int count = array2.length; + array2 = grow(array2, array1.length); + System.arraycopy(array1, 0, array2, count, array1.length); + Arrays.sort(array2); + int[] array3 = new int[array2.length]; + array3[0] = array2[0]; + int x = 0; + for (int i = 1; i < array2.length; i++) { + if (array2[i] != array3[x]) { + array3[x + 1] = array2[i]; + x++; + } + } + + int[] array4 = new int[x + 1]; + System.arraycopy(array3, 0, array4, 0, x + 1); + return array4; + } + + /** + * 鎶婁竴涓凡缁忓瓨婊℃暟鎹殑鏁扮粍 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) { + int[] newArray = new int[oldArray.length + size]; + System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); + return newArray; + } + + /** + * 鏂愭尝閭e鏁板垪涓猴細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[] array, int max) { + int[] array0 = new int[array.length]; + int x = 0; + int y = 0; + for (int i = 0; i < array.length; i++) { + if (array[i] < max) { + array0[y] = array[i]; + y++; + } else { + x++; + } + } + int[] array1 = new int[y]; + return Arrays.copyOf(array0, y); + } + + /** + * 杩斿洖灏忎簬缁欏畾鏈澶у糾ax鐨勬墍鏈夌礌鏁版暟缁 渚嬪max = 23, 杩斿洖鐨勬暟缁勪负[2,3,5,7,11,13,17,19] + * + * @param max + * @return + */ + public int[] getPrimes(int max) { + + + if(max<=2) + {return new int[]{}; + + } + int[] temp = new int[max]; + int index = 0; + for (int i = 2; i < max; i++) { + boolean flag = true; + for (int j = 2; j <= Math.sqrt(i); j++) { + if(i % j == 0){ + flag = false; + } + } + if(flag){temp[index++] = i;} + } + return Arrays.copyOf(temp, index); + } + + /** + * 鎵璋撯滃畬鏁扳濓紝 鏄寚杩欎釜鏁版伆濂界瓑浜庡畠鐨勫洜瀛愪箣鍜岋紝渚嬪6=1+2+3 缁欏畾涓涓渶澶у糾ax锛 杩斿洖涓涓暟缁勶紝 鏁扮粍涓槸灏忎簬max 鐨勬墍鏈夊畬鏁 + * + * @param max + * @return + */ + public int[] getPerfectNumbers(int max) { + + if(max <= 2) return new int[]{}; + + int[] array = new int[max]; + int index = 0; + for (int i = 2; i < max; i++) { + int x = 0; + for (int j = 1; j <= Math.sqrt(i); j++) { + if(j == 1) { + x += 1; + }else{ + if(i % j == 0){ + x += j + i/j; + } + } + } + if(x == i) array[index++] = i; + } + return Arrays.copyOf(array, index); + } + + /** + * 鐢╯eperator 鎶婃暟缁 array缁欒繛鎺ヨ捣鏉 渚嬪array= [3,8,9], seperator = "-" 鍒欒繑鍥炲间负"3-8-9" + * + * @param array + * @param s + * @return + */ + public String join(int[] array, String seperator) { + if(array.length == 0){ + return ""; + } + StringBuilder sb = new StringBuilder(); + for (int i : array) { + sb.append(i).append(seperator); + } + String temp = sb.toString(); + return temp.substring(0,temp.length()-1); + } + +} diff --git a/group15/1514_616019420/src/com/coderising/array/ArrayUtilTest.java b/group15/1514_616019420/src/com/coderising/array/ArrayUtilTest.java new file mode 100644 index 0000000000..0f244f272a --- /dev/null +++ b/group15/1514_616019420/src/com/coderising/array/ArrayUtilTest.java @@ -0,0 +1,110 @@ +package com.coderising.array; + +import static org.junit.Assert.*; + +import java.util.Arrays; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ArrayUtilTest { + + private ArrayUtil u; + int[] array; + + @Before + public void setUp() throws Exception { + + u = new ArrayUtil(); + + array = new int[100]; + + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void testReverseArray() { + fail("Not yet implemented"); + for (int i = 0; i < 100; i++) { + array[i] = i; + + } + array = u.reverseArray(array); + System.out.println("testReverseArray:" + Arrays.toString(array)); + + } + + @Test + public void testRemoveZero() { + fail("Not yet implemented"); + for (int i = 0; i < 100; i++) { + if (i < 50) { + array[i] = 0; + } else { + array[i] = i; + } + } + array = u.removeZero(array); + System.out.println("testRemoveZero:" + Arrays.toString(array)); + } + + @Test + public void testMerge() { + //fail("Not yet implemented"); + int[] intarray={0,1,2,3,4,5,6,7}; + int[] intarray0={10,11,12,13,14,15,16,17,0,3}; + int[] intarray1=u.merge(intarray, intarray0); + System.out.println("testMerge:" + Arrays.toString(intarray1)); + + } + + @Test + public void testGrow() { + //fail("Not yet implemented"); + int[] intarray={0,1,2,3,4,5,6,7}; + int[] intarray0={10,11,12,13,14,15,16,17,0,3}; + int[] intarray1=u.grow(intarray, 10); + System.out.println("testGrow:" + Arrays.toString(intarray1)); + + } + + @Test + public void testFibonacci() { + //fail("Not yet implemented"); + int[] intarray={0,1,2,3,4,5,6,7}; + int[] intarray0={10,11,12,13,14,15,16,17,0,3}; + int[] intarray1=u.fibonacci(intarray0, 17); + System.out.println("testFibonacci:" + Arrays.toString(intarray1)); + } + + @Test + public void testGetPrimes() { + //fail("Not yet implemented");int[] intarray={0,1,2,3,4,5,6,7}; + int[] intarray0={10,11,12,13,14,15,16,17,0,3}; + int[] intarray1=u.getPrimes(10); + System.out.println("testGetPrimes:" + Arrays.toString(intarray1)); + + } + + @Test + public void testGetPerfectNumbers() { + // fail("Not yet implemented"); + int[] intarray0={10,11,12,13,14,15,16,17,0,3}; + int[] intarray1=u.getPerfectNumbers(10); + System.out.println("testGetPerfectNumbers:" + Arrays.toString(intarray1)); + } + + @Test + public void testJoin() { + // fail("Not yet implemented"); + int[] intarray0={10,11,12,13,14,15,16,17,0,3}; + String str=u.join(intarray0, "++"); + System.out.println("testJoin:" + str); + } + +} diff --git a/group15/1514_616019420/src/com/coderising/litestruts/LoginAction.java b/group15/1514_616019420/src/com/coderising/litestruts/LoginAction.java new file mode 100644 index 0000000000..dcdbe226ed --- /dev/null +++ b/group15/1514_616019420/src/com/coderising/litestruts/LoginAction.java @@ -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; + } +} diff --git a/group15/1514_616019420/src/com/coderising/litestruts/Struts.java b/group15/1514_616019420/src/com/coderising/litestruts/Struts.java new file mode 100644 index 0000000000..9081b94e78 --- /dev/null +++ b/group15/1514_616019420/src/com/coderising/litestruts/Struts.java @@ -0,0 +1,113 @@ +package com.coderising.litestruts; + +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import java.io.File; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class Struts { + + public static View runAction(String actionName, Map parameters) { + /* + 0. 璇诲彇閰嶇疆鏂囦欢struts.xml + + 1. 鏍规嵁actionName鎵惧埌鐩稿搴旂殑class 锛 渚嬪LoginAction, 閫氳繃鍙嶅皠瀹炰緥鍖栵紙鍒涘缓瀵硅薄锛 + 鏍规嵁parameters涓殑鏁版嵁锛岃皟鐢ㄥ璞$殑setter鏂规硶锛 渚嬪parameters涓殑鏁版嵁鏄 + ("name"="test" , "password"="1234") , + 閭e氨搴旇璋冪敤 setName鍜宻etPassword鏂规硶 + + 2. 閫氳繃鍙嶅皠璋冪敤瀵硅薄鐨別xectue 鏂规硶锛 骞惰幏寰楄繑鍥炲硷紝渚嬪"success" + + 3. 閫氳繃鍙嶅皠鎵惧埌瀵硅薄鐨勬墍鏈塯etter鏂规硶锛堜緥濡 getMessage锛, + 閫氳繃鍙嶅皠鏉ヨ皟鐢紝 鎶婂煎拰灞炴у舰鎴愪竴涓狧ashMap , 渚嬪 {"message": "鐧诲綍鎴愬姛"} , + 鏀惧埌View瀵硅薄鐨刾arameters + + 4. 鏍规嵁struts.xml涓殑 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛 + 鏀惧埌View瀵硅薄鐨刯sp瀛楁涓 + */ + + try { + //0璇诲彇閰嶇疆鏂囦欢struts.xml + SAXReader saxReader = new SAXReader(); + Document document = saxReader.read(new File("src/com/coderising/litestruts/struts.xml")); + Element rootElement = document.getRootElement(); //鏍瑰厓绱 + Map actionMap = new HashMap<>(); + Map loginResult = new HashMap<>(); + Map logoutResult = new HashMap<>(); + java.util.Iterator iterator = rootElement.elementIterator("action"); + while(iterator.hasNext()){ + Element actionNode = (Element) iterator.next(); + String key = actionNode.attributeValue("name"); + String value = actionNode.attributeValue("class"); + action.put(key,value); + java.util.Iterator it = actionNode.elementIterator("result"); + while(it.hasNext()){ + Element resultNode = (Element) it.next(); + String k = resultNode.attributeValue("name"); + String v = resultNode.getText(); + if(key.equals("login")){ + loginResult.put(k,v); + }else { + logoutResult.put(k,v); + } + } + } + + //1 + String className = actionMap.get(actionName); //鑾峰彇绫诲悕 + Object o = Class.forName(className).newInstance(); //鍒涘缓瀵硅薄 + if(o instanceof LoginAction){ + LoginAction loginAction = (LoginAction) o; + Set> set = parameters.entrySet(); + for (Map.Entry en : set) { + if(en.getKey().equals("name")){ + loginAction.setName(en.getValue()); + }else if(en.getKey().equals("password")){ + loginAction.setPassword(en.getValue()); + } + } + + //2 + Class clazz = (Class) loginAction.getClass(); + Method m = clazz.getDeclaredMethod("execute",null); + m.setAccessible(true); + String message = (String) m.invoke(loginAction,null); + + //3 + View view = new View(); + Map params = new HashMap(); + Method[] ms = clazz.getDeclaredMethods(); + for (Method method : ms) { + method.setAccessible(true); + if(method.getName().equals("getName")){ + String value = (String) method.invoke(loginAction,null); + params.put("name",value); + }else if(method.getName().equals("getPassword")){ + String value = (String) method.invoke(loginAction,null); + params.put("password",value); + }else if(method.getName().equals("getMessage")){ + String value = (String) method.invoke(loginAction,null); + params.put("message",value); + } + } + view.setParameters(params); + + //4 + String jsp = loginResult.get(message); + view.setJsp(jsp); + + return view; + }else { + return null; + } + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + } + +} diff --git a/group15/1514_616019420/src/com/coderising/litestruts/StrutsTest.java b/group15/1514_616019420/src/com/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..b8c81faf3c --- /dev/null +++ b/group15/1514_616019420/src/com/coderising/litestruts/StrutsTest.java @@ -0,0 +1,43 @@ +package com.coderising.litestruts; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + + + + + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() { + + String actionName = "login"; + + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //瀵嗙爜鍜岄璁剧殑涓嶄竴鑷 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group15/1514_616019420/src/com/coderising/litestruts/View.java b/group15/1514_616019420/src/com/coderising/litestruts/View.java new file mode 100644 index 0000000000..07df2a5dab --- /dev/null +++ b/group15/1514_616019420/src/com/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coderising.litestruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group15/1500_369516660/src/com/basic/struts/struts.xml b/group15/1514_616019420/src/com/coderising/litestruts/struts.xml similarity index 100% rename from group15/1500_369516660/src/com/basic/struts/struts.xml rename to group15/1514_616019420/src/com/coderising/litestruts/struts.xml diff --git a/group15/1514_616019420/ArrayList.java b/group15/1514_616019420/src/com/coding/basic/ArrayList.java similarity index 100% rename from group15/1514_616019420/ArrayList.java rename to group15/1514_616019420/src/com/coding/basic/ArrayList.java diff --git a/group15/1514_616019420/BinaryTreeNode.java b/group15/1514_616019420/src/com/coding/basic/BinaryTreeNode.java similarity index 100% rename from group15/1514_616019420/BinaryTreeNode.java rename to group15/1514_616019420/src/com/coding/basic/BinaryTreeNode.java diff --git a/group15/1514_616019420/src/com/coding/basic/Iterator.java b/group15/1514_616019420/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..06ef6311b2 --- /dev/null +++ b/group15/1514_616019420/src/com/coding/basic/Iterator.java @@ -0,0 +1,7 @@ +package com.coding.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group15/1514_616019420/LinkedList.java b/group15/1514_616019420/src/com/coding/basic/LinkedList.java similarity index 100% rename from group15/1514_616019420/LinkedList.java rename to group15/1514_616019420/src/com/coding/basic/LinkedList.java diff --git a/group15/1514_616019420/src/com/coding/basic/List.java b/group15/1514_616019420/src/com/coding/basic/List.java new file mode 100644 index 0000000000..10d13b5832 --- /dev/null +++ b/group15/1514_616019420/src/com/coding/basic/List.java @@ -0,0 +1,9 @@ +package com.coding.basic; + +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} diff --git a/group15/1514_616019420/Queue.java b/group15/1514_616019420/src/com/coding/basic/Queue.java similarity index 100% rename from group15/1514_616019420/Queue.java rename to group15/1514_616019420/src/com/coding/basic/Queue.java diff --git a/group15/1514_616019420/Stack.java b/group15/1514_616019420/src/com/coding/basic/Stack.java similarity index 100% rename from group15/1514_616019420/Stack.java rename to group15/1514_616019420/src/com/coding/basic/Stack.java diff --git a/group15/1514_616019420/src/com/coding/basic/readme.txt b/group15/1514_616019420/src/com/coding/basic/readme.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/group15/1515_337959725/.classpath b/group15/1515_337959725/.classpath index d171cd4c12..6a4228528e 100644 --- a/group15/1515_337959725/.classpath +++ b/group15/1515_337959725/.classpath @@ -1,6 +1,7 @@ - + + diff --git a/group15/1515_337959725/.project b/group15/1515_337959725/.project index 8c7c8dd0f7..6730933705 100644 --- a/group15/1515_337959725/.project +++ b/group15/1515_337959725/.project @@ -1,6 +1,6 @@ - BasicTest + coding0305 diff --git a/group15/1515_337959725/.settings/org.eclipse.jdt.core.prefs b/group15/1515_337959725/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..060c5ee3d2 --- /dev/null +++ b/group15/1515_337959725/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +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.5 diff --git a/group15/1500_369516660/src/com/basic/array/practice/ArrayUtil.java b/group15/1515_337959725/src/com/coderising/array/ArrayUtil.java similarity index 52% rename from group15/1500_369516660/src/com/basic/array/practice/ArrayUtil.java rename to group15/1515_337959725/src/com/coderising/array/ArrayUtil.java index 69caaf2f94..3273e77f7b 100644 --- a/group15/1500_369516660/src/com/basic/array/practice/ArrayUtil.java +++ b/group15/1515_337959725/src/com/coderising/array/ArrayUtil.java @@ -1,95 +1,184 @@ -package com.basic.array.practice; - -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){ - - } - - /** - * 现在有如下的一个数组: 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){ - return null; - } - - /** - * 给定两个已经排序好的整形数组, 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){ - return null; - } - /** - * 把一个已经存满数据的数组 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; - } - -} +package com.coderising.array; + +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){ + int a; + int length=origin.length; + for(int i=0;iarray2[j]){ + array3[k]=array1[j]; + j++; + k++; + } + } + return array3; + } + /** + * 把一个已经存满数据的数组 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){ + int[] newArray =new int[oldArray.length+size]; + int i; + for(i=0;i parameters) { + + /* + + 0. 读取配置文件struts.xml + + 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) + 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 + ("name"="test" , "password"="1234") , + 那就应该调用 setName和setPassword方法 + + 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" + + 3. 通过反射找到对象的所有getter方法(例如 getMessage), + 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , + 放到View对象的parameters + + 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, + 放到View对象的jsp字段中。 + + */ + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + View view = null; + try { + DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); + File f = new File("E:/gitProject/coding2017/group15/1515_337959725/src/com/coderising/litestruts/struts.xml"); + Document document = documentBuilder.parse(f); + NodeList actionList = document.getElementsByTagName("action"); + Node node = null; + String className=""; + for(int i=0;i params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //密码和预设的不一致 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} + diff --git a/group15/1515_337959725/src/com/coderising/litestruts/View.java b/group15/1515_337959725/src/com/coderising/litestruts/View.java new file mode 100644 index 0000000000..07df2a5dab --- /dev/null +++ b/group15/1515_337959725/src/com/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coderising.litestruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group15/1515_337959725/src/com/coderising/litestruts/struts.xml b/group15/1515_337959725/src/com/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..6f23f0a83d --- /dev/null +++ b/group15/1515_337959725/src/com/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file diff --git a/group15/1517_279137987/src/com/coderising/array/ArrayUtil.java b/group15/1517_279137987/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..443184b555 --- /dev/null +++ b/group15/1517_279137987/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,226 @@ +package com.coderising.array; + +import java.util.Arrays; + +import my.collection.linear.MyArrayList; + +public class ArrayUtil { + + /** + * 1缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 + 渚嬪锛 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){ + int temp; + int len = origin.length; + for(int i=0; i array2[j]){ + retTmp[k++] = array2[j++]; + }else{ + j++; + sameCount++; + } + } + //insert remainder array + while(i < array1.length){ + retTmp[k++] = array1[i++]; + } + while(j < array2.length){ + retTmp[k++] = array2[j++]; + } + int[] ret = new int[retTmp.length - sameCount]; + if(sameCount > 0){ + System.arraycopy(retTmp, 0, ret, 0, retTmp.length - sameCount); + } + return ret; + } + + /** + * 4鎶婁竴涓凡缁忓瓨婊℃暟鎹殑鏁扮粍 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){ + int[] newArray = new int[oldArray.length + size]; + for(int i=0; i0; i--){ + //get divide numbers + MyArrayList divideNumArrayList = new MyArrayList(10); + for(int j=1; j parameters) { + View view = new View(); + /* + * 0. 璇诲彇閰嶇疆鏂囦欢struts.xml + * */ + SAXReader reader = new SAXReader(); + try { + Document document = reader.read(new File("src/com/coderising/litestruts/struts.xml")); + Element root = document.getRootElement(); + Iterator iter = root.elementIterator(); + while(iter.hasNext()){ + Element secondNode = (Element) iter.next(); + String nameStr = secondNode.attributeValue("name"); + String classStr = secondNode.attributeValue("class"); + + /* + * 1. 鏍规嵁actionName鎵惧埌鐩稿搴旂殑class 锛 渚嬪LoginAction, 閫氳繃鍙嶅皠瀹炰緥鍖栵紙鍒涘缓瀵硅薄锛 + 鎹畃arameters涓殑鏁版嵁锛岃皟鐢ㄥ璞$殑setter鏂规硶锛 渚嬪parameters涓殑鏁版嵁鏄 + ("name"="test" , "password"="1234") , + 閭e氨搴旇璋冪敤 setName鍜宻etPassword鏂规硶 + */ + if(nameStr.equals(actionName)){ + Class cls = Class.forName(classStr); + Object obj = cls.newInstance(); + Method mtd1 = cls.getDeclaredMethod("setName", String.class); + mtd1.invoke(obj, parameters.get("name")); + + Method mtd2 = cls.getDeclaredMethod("setPassword", new Class[]{String.class}); + mtd2.invoke(obj, parameters.get("password")); + + /* + * 2. 閫氳繃鍙嶅皠璋冪敤瀵硅薄鐨別xectue 鏂规硶锛 骞惰幏寰楄繑鍥炲硷紝渚嬪"success" + * */ + Method execute = cls.getDeclaredMethod("execute"); + String runStatus = (String) execute.invoke(obj); + + /* + * 3. 閫氳繃鍙嶅皠鎵惧埌瀵硅薄鐨勬墍鏈塯etter鏂规硶锛堜緥濡 getMessage锛, + 閫氳繃鍙嶅皠鏉ヨ皟鐢紝 鎶婂煎拰灞炴у舰鎴愪竴涓狧ashMap , 渚嬪 {"message": "鐧诲綍鎴愬姛"} , + 鏀惧埌View瀵硅薄鐨刾arameters + */ + Method mtd3 = cls.getDeclaredMethod("getMessage"); + String getMes = (String) mtd3.invoke(obj); + Map params = new HashMap(); + params.put("message",getMes); + + /* + * 4. 鏍规嵁struts.xml涓殑 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛 + 鏀惧埌View瀵硅薄鐨刯sp瀛楁涓 + */ + Iterator iterSecond = secondNode.elementIterator(); + while(iterSecond.hasNext()){ + Element thirdNode = (Element) iterSecond.next(); + String resultNameStr = thirdNode.attributeValue("name"); + String pageStr = thirdNode.getText(); + + if(runStatus.equals(resultNameStr)){ + view.setJsp(pageStr); + view.setParameters(params); + break; + } + } + } + } + } catch (DocumentException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return view; + } +} diff --git a/group15/1517_279137987/src/com/coderising/litestruts/StrutsTest.java b/group15/1517_279137987/src/com/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..9f20bbfd59 --- /dev/null +++ b/group15/1517_279137987/src/com/coderising/litestruts/StrutsTest.java @@ -0,0 +1,39 @@ +package com.coderising.litestruts; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() { + + String actionName = "login"; + + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //瀵嗙爜鍜岄璁剧殑涓嶄竴鑷 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group15/1517_279137987/src/com/coderising/litestruts/View.java b/group15/1517_279137987/src/com/coderising/litestruts/View.java new file mode 100644 index 0000000000..07df2a5dab --- /dev/null +++ b/group15/1517_279137987/src/com/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coderising.litestruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group15/1517_279137987/src/com/coderising/litestruts/struts.xml b/group15/1517_279137987/src/com/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..ea46090bc9 --- /dev/null +++ b/group15/1517_279137987/src/com/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file diff --git a/group15/1517_279137987/my/collection/linear/MyArrayList.java b/group15/1517_279137987/src/my/collection/linear/MyArrayList.java similarity index 77% rename from group15/1517_279137987/my/collection/linear/MyArrayList.java rename to group15/1517_279137987/src/my/collection/linear/MyArrayList.java index 380c552539..d84b583dcb 100644 --- a/group15/1517_279137987/my/collection/linear/MyArrayList.java +++ b/group15/1517_279137987/src/my/collection/linear/MyArrayList.java @@ -70,4 +70,35 @@ public String toString(){ System.arraycopy(elementData, 0, largerElement, 0, elementData.length); elementData = largerElement; }*/ + + public MyIterator myIterator(){ + return new MyArrayListIterator(this); + } + + private class MyArrayListIterator implements MyIterator{ + @SuppressWarnings("unused") + MyArrayList list = null; + int pos = 0; + + private MyArrayListIterator(MyArrayList list){ + this.list = list; + } + + public boolean hasNext() { + if(++pos > size){ + return false; + }else{ + return true; + } + } + + public Object next() { + return get(pos); + } + + public Object remove(){ //? + return MyArrayList.this.remove(this.pos); + } + + } } diff --git a/group15/1517_279137987/src/my/collection/linear/MyBinaryTreeNode.java b/group15/1517_279137987/src/my/collection/linear/MyBinaryTreeNode.java new file mode 100644 index 0000000000..8b52c6f838 --- /dev/null +++ b/group15/1517_279137987/src/my/collection/linear/MyBinaryTreeNode.java @@ -0,0 +1,83 @@ +package my.collection.linear; + +public class MyBinaryTreeNode implements Comparable{ + + private Object data; + private MyBinaryTreeNode left; + private MyBinaryTreeNode right; + + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public MyBinaryTreeNode getLeft() { + return left; + } + public void setLeft(MyBinaryTreeNode left) { + this.left = left; + } + public MyBinaryTreeNode getRight() { + return right; + } + public void setRight(MyBinaryTreeNode right) { + this.right = right; + } + + public MyBinaryTreeNode insert(Object o){ + //cast to MyBinaryTreeNode + MyBinaryTreeNode newNode = new MyBinaryTreeNode(); + newNode.setData(o); + newNode.setLeft(null); + newNode.setRight(null); + + //insert to current node + if(data == null){ + this.setData(o); + this.setLeft(null); + this.setRight(null); + }else{ + //insert to left child + if(compareTo(o) == -1){ + if(this.getLeft() == null){ + this.setLeft(newNode); + }else{ + this.data = this.getLeft().data; + this.setLeft(this.getLeft().getLeft()); + this.setRight(this.getRight().getRight()); + insert(o); + } + //insert to right child + }else if(compareTo(o) == 1){ + if(this.getRight() == null){ + this.setRight(newNode); + }else{ + this.data = this.getLeft().data; + this.setLeft(this.getLeft().getLeft()); + this.setRight(this.getRight().getRight()); + insert(o); + } + //can't insert node which has same data. + }else{ + + } + } + return newNode; + } + + public int compareTo(Object o) { + int compareFlag = 0; + if(o instanceof Integer){ + if(Integer.valueOf(o.toString()) < Integer.valueOf(data.toString())){ + compareFlag = -1; + }else if(Integer.valueOf(o.toString()) > Integer.valueOf(data.toString())){ + compareFlag = 1; + }else{ + compareFlag = 0; + } + } + return compareFlag; + } + +} diff --git a/group15/1517_279137987/my/collection/linear/MyIterator.java b/group15/1517_279137987/src/my/collection/linear/MyIterator.java similarity index 100% rename from group15/1517_279137987/my/collection/linear/MyIterator.java rename to group15/1517_279137987/src/my/collection/linear/MyIterator.java diff --git a/group15/1517_279137987/my/collection/linear/MyLinkedList.java b/group15/1517_279137987/src/my/collection/linear/MyLinkedList.java similarity index 100% rename from group15/1517_279137987/my/collection/linear/MyLinkedList.java rename to group15/1517_279137987/src/my/collection/linear/MyLinkedList.java diff --git a/group15/1517_279137987/my/collection/linear/MyList.java b/group15/1517_279137987/src/my/collection/linear/MyList.java similarity index 100% rename from group15/1517_279137987/my/collection/linear/MyList.java rename to group15/1517_279137987/src/my/collection/linear/MyList.java diff --git a/group15/1517_279137987/my/collection/linear/MyQueue.java b/group15/1517_279137987/src/my/collection/linear/MyQueue.java similarity index 100% rename from group15/1517_279137987/my/collection/linear/MyQueue.java rename to group15/1517_279137987/src/my/collection/linear/MyQueue.java diff --git a/group15/1517_279137987/my/collection/linear/MyStack.java b/group15/1517_279137987/src/my/collection/linear/MyStack.java similarity index 100% rename from group15/1517_279137987/my/collection/linear/MyStack.java rename to group15/1517_279137987/src/my/collection/linear/MyStack.java diff --git a/group15/1517_279137987/my/collection/linearTest/MyArrayListTest.java b/group15/1517_279137987/src/my/collection/linearTest/MyArrayListTest.java similarity index 100% rename from group15/1517_279137987/my/collection/linearTest/MyArrayListTest.java rename to group15/1517_279137987/src/my/collection/linearTest/MyArrayListTest.java diff --git a/group15/1517_279137987/src/my/collection/linearTest/MyBinaryTreeNodeTest.java b/group15/1517_279137987/src/my/collection/linearTest/MyBinaryTreeNodeTest.java new file mode 100644 index 0000000000..17a6df5e5a --- /dev/null +++ b/group15/1517_279137987/src/my/collection/linearTest/MyBinaryTreeNodeTest.java @@ -0,0 +1,24 @@ +package my.collection.linearTest; + +import my.collection.linear.MyBinaryTreeNode; + +public class MyBinaryTreeNodeTest { + + public static void main(String[] args) { + MyBinaryTreeNode myTree = new MyBinaryTreeNode(); + + myTree.insert(new Integer(8)); + myTree.insert(new Integer(12)); + myTree.insert(new Integer(6)); + myTree.insert(new Integer(3)); + myTree.insert(new Integer(7)); + + System.out.println(myTree.getData().toString()); //8 + System.out.println(myTree.getLeft().getData().toString()); //6 + System.out.println(myTree.getLeft().getData().toString()); //3 + System.out.println(myTree.getRight().getData().toString()); //12 + + + } + +} diff --git a/group15/1517_279137987/my/collection/linearTest/MyLinkedListTest.java b/group15/1517_279137987/src/my/collection/linearTest/MyLinkedListTest.java similarity index 100% rename from group15/1517_279137987/my/collection/linearTest/MyLinkedListTest.java rename to group15/1517_279137987/src/my/collection/linearTest/MyLinkedListTest.java diff --git a/group15/1517_279137987/my/collection/linearTest/MyQueueTest.java b/group15/1517_279137987/src/my/collection/linearTest/MyQueueTest.java similarity index 100% rename from group15/1517_279137987/my/collection/linearTest/MyQueueTest.java rename to group15/1517_279137987/src/my/collection/linearTest/MyQueueTest.java diff --git a/group15/1517_279137987/my/collection/linearTest/MyStackTest.java b/group15/1517_279137987/src/my/collection/linearTest/MyStackTest.java similarity index 100% rename from group15/1517_279137987/my/collection/linearTest/MyStackTest.java rename to group15/1517_279137987/src/my/collection/linearTest/MyStackTest.java diff --git a/group15/1517_279137987/src/my/collection/linearTestJUnit/MyArrayListTest.java b/group15/1517_279137987/src/my/collection/linearTestJUnit/MyArrayListTest.java new file mode 100644 index 0000000000..2216d2c830 --- /dev/null +++ b/group15/1517_279137987/src/my/collection/linearTestJUnit/MyArrayListTest.java @@ -0,0 +1,109 @@ +package my.collection.linearTestJUnit; + +import my.collection.linear.MyArrayList; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class MyArrayListTest { + + MyArrayList mal = new MyArrayList(5); + + @Before + public void setUp() throws Exception { + for(int i=0; i0){ + for(int i=0;i=array1.length&&b=array2.length&&am)list.add(n); + } + int[] arr = new int[list.size()]; + for(int i=0;i + + + + + diff --git a/group15/1519_137845093/.gitignore b/group15/1519_137845093/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group15/1519_137845093/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group15/1500_369516660/.project b/group15/1519_137845093/.project similarity index 93% rename from group15/1500_369516660/.project rename to group15/1519_137845093/.project index a6666f301e..7371704aff 100644 --- a/group15/1500_369516660/.project +++ b/group15/1519_137845093/.project @@ -1,6 +1,6 @@ - coding + helloworld diff --git a/group15/1519_137845093/3.5_homework/array/ArrayUtil.java b/group15/1519_137845093/3.5_homework/array/ArrayUtil.java new file mode 100644 index 0000000000..e8660ed7ce --- /dev/null +++ b/group15/1519_137845093/3.5_homework/array/ArrayUtil.java @@ -0,0 +1,210 @@ +package com.coderising.array; +import java.util.*; +public class ArrayUtil { + + /** + * 缁欏畾涓涓暣褰㈡暟缁刟 , 瀵硅鏁扮粍鐨勫艰繘琛岀疆鎹 + 渚嬪锛 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){ + if(origin.length > 0 && origin != null){ + int temp; + for (int i = 0; i < origin.length / 2; i++) { + temp = origin[i]; + origin[i] = origin[origin.length-1 - i]; + origin[origin.length-1 - i] = temp; + } + } + else { + throw new IndexOutOfBoundsException("鍘熸暟缁勬湁閿" ); + } + } + + /** + * 鐜板湪鏈夊涓嬬殑涓涓暟缁勶細 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){ + if(oldArray.length == 0){ + return oldArray; + } + int index = 0; + for(int i =0; i< oldArray.length; i++){ + if(oldArray[index] != 0){ + oldArray[index] = oldArray[i]; + index++; + } + } + return Arrays.copyOf(oldArray, index); + } + + /** + * 缁欏畾涓や釜宸茬粡鎺掑簭濂界殑鏁村舰鏁扮粍锛 a1鍜宎2 , 鍒涘缓涓涓柊鐨勬暟缁刟3, 浣垮緱a3 鍖呭惈a1鍜宎2 鐨勬墍鏈夊厓绱狅紝 骞朵笖浠嶇劧鏄湁搴忕殑 + * 渚嬪 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){ + int length1 = array1.length; + int length2 = array2.length; + int newArrayLength = length1 + length2; + int[] result = new int[newArrayLength]; + int i = 0, j = 0, k = 0; //i:鐢ㄤ簬鏍囩ず1鏁扮粍 j锛氱敤鏉ユ爣绀2鏁扮粍 k锛氱敤鏉ユ爣绀轰紶鍏ョ殑鏁扮粍 + + while (i < length1 && j < length2) { + /* 鍘婚噸澶嶅厓绱 */ + if (array1[i] < array2[j]) { + result[k++] = array1[i++]; + } else if (array1[i] == array2[j]) { + result[k++] = array1[i]; + //鍦ㄦ煇涓綅缃笂2涓肩浉绛夌殑璇濓紝鍙栧摢涓兘涓鏍凤紝 + // 鐒跺悗杩欎釜鐩哥瓑鐨勪綅缃殑2涓奸兘鐩存帴鍚戝悗绉诲姩1锛岀户缁瘮杈 + j++; + i++; + } else { + result[k++] = array2[j++]; + } + } + /* 鍚庨潰while寰幆鏄敤鏉ヤ繚璇佷袱涓暟缁勬瘮杈冨畬涔嬪悗鍓╀笅鐨勪竴涓暟缁勯噷鐨勫厓绱犺兘椤哄埄浼犲叆缁撴灉鏁扮粍 */ + while (i < length1) { + result[k++] = array1[i++]; + } + + while (j < length2) { + result[k++] = array2[j++]; + } + return Arrays.copyOf(result, k); + } + + + /** + * 鎶婁竴涓凡缁忓瓨婊℃暟鎹殑鏁扮粍 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){ + int[] newArr = new int[oldArray.length + size]; + System.arraycopy(oldArray, 0, newArr, 0, oldArray.length); + return newArr; + } + + /** + * 鏂愭尝閭e鏁板垪涓猴細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){ + int[] array = new int[]{}; + for(int i=1; getfb(i) k) { + if (i % k == 0) + break; + k++; + } + //鎵╁ + prime = grow(prime, 1); + prime[j++] = i; + } + return prime; + } + + /** + * 鎵璋撯滃畬鏁扳濓紝 鏄寚杩欎釜鏁版伆濂界瓑浜庡畠鐨勫洜瀛愪箣鍜岋紝渚嬪6=1+2+3 + * 缁欏畾涓涓渶澶у糾ax锛 杩斿洖涓涓暟缁勶紝 鏁扮粍涓槸灏忎簬max 鐨勬墍鏈夊畬鏁 + * @param max + * @return + */ + public int[] getPerfectNumbers(int max){ + int[] array = new int[0]; + int j = 0; + for (int i = 1; i < max; i++) { + if (isPerfect(i)) { + //鍔犲叆鍒版暟缁勪腑 + array = grow(array, 1); + array[j] = i; + j++; + } + } + return array; + } + + //鍒ゆ柇涓涓暟鏄惁鏄滃畬鏁扳 + private static boolean isPerfect(int max) { + int i = 1; + int n = 0; + while (i < max) { + if (max % i == 0) { + n += i; + } + i++; + } + if (n == max) + return true; + return false; + } + + + /** + * 鐢╯eperator 鎶婃暟缁 array缁欒繛鎺ヨ捣鏉 + * 渚嬪array= [3,8,9], seperator = "-" + * 鍒欒繑鍥炲间负"3-8-9" + * @param array + * @param s + * @return + */ + public String join(int[] array, String seperator){ + if (array == null) + return null; + String s = ""; + for (int i = 0; i < array.length; i++) { + s += array[i]; + if (i != array.length - 1) + s += seperator; + } + return s; + } + +} + + diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/ArrayList.java b/group15/1519_137845093/src_1st_homework_1519_137845093/ArrayList.java new file mode 100644 index 0000000000..e0ef246f9b --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/ArrayList.java @@ -0,0 +1,117 @@ +package com.coding.basic; + +import java.util.NoSuchElementException; + +public class ArrayList implements List { + //元素个数 + private int size = 0; + //初始长度设为10 + private Object[] elementData = new Object[10]; + + public void add(Object o) { + int len = size + 1; + // 判断list的长度是否大于数组长度 + if (len > elementData.length) { + // 创建新容器 + Object[] newElemData = new Object[elementData.length + 1]; + // 复制旧容器所有元素到新容器 + System.arraycopy(elementData, 0, newElemData, 0, elementData.length); + elementData = newElemData; + } + elementData[size] = o; + size++; + } + + public void add(int index, Object o) { + // 检查下标是否越界 + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException("index:" + index + "越界;" ); + } + // 插入元素到数组的末尾直接调用add方法 + if (index == size) { + add(o); + } else { + // 创建新容器 + Object[] newElemData = new Object[elementData.length + 1]; + // 复制index以前的所有元素到新容器 + System.arraycopy(elementData, 0, newElemData, 0, index); + newElemData[index] = o; + // 复制index 及以后的元素到新容器 + System.arraycopy(elementData, index, newElemData, index + 1, size - index); + + elementData = newElemData; + size++; + } + } + + public Object get(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException("index:" + index + "越界;"); + } + return elementData[index]; + } + + public Object remove(int index) { + //下标大于数组长度的,抛出异常 + if (index >= size) { + throw new IndexOutOfBoundsException("index:" + index + "越界;"); + } + //index不是最后一个元素的索引值才需要删除操作 + if(index != (size-1)){ + // 创建新容器 + Object[] newElemData = new Object[elementData.length]; + // 复制index以前的所有元素到新容器 + System.arraycopy(elementData, 0, newElemData, 0, index); + // 复制index 以后的元素到新容器 + System.arraycopy(elementData, index+1, newElemData, index, size - index -1); + } + Object removeElement = elementData[index]; + //减小数组的长度 + size--; + return removeElement; + } + + public int size() { + return size; + } + + public Iterator iterator() { + return new MyItr(this); + } + + private class MyItr implements Iterator { + private int l = -1; + private ArrayList array = null; + + private MyItr(ArrayList array) { + this.array = array; + } + + @Override + public boolean hasNext() { + return (l + 1) < array.size; + } + + @Override + public Object next() { + l++; + if (l >= array.size) { + l = array.size - 1 ; + throw new IndexOutOfBoundsException(); + } + + return array.get(l); + } + + @Override + public Object remove() { + if (l < 0) { + throw new NoSuchElementException(); + } + Object val = array.remove(l); + l--; + return val; + } + + } +} \ No newline at end of file diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/BinaryTreeNode.java b/group15/1519_137845093/src_1st_homework_1519_137845093/BinaryTreeNode.java new file mode 100644 index 0000000000..d7ac820192 --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/BinaryTreeNode.java @@ -0,0 +1,32 @@ +package com.coding.basic; + +public class BinaryTreeNode { + + private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public BinaryTreeNode getLeft() { + return left; + } + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + public BinaryTreeNode getRight() { + return right; + } + public void setRight(BinaryTreeNode right) { + this.right = right; + } + + public BinaryTreeNode insert(Object o){ + return null; + } + +} diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/Iterator.java b/group15/1519_137845093/src_1st_homework_1519_137845093/Iterator.java new file mode 100644 index 0000000000..2d4150183f --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/Iterator.java @@ -0,0 +1,8 @@ +package com.coding.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + public Object remove(); + +} diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/LinkedList.java b/group15/1519_137845093/src_1st_homework_1519_137845093/LinkedList.java new file mode 100644 index 0000000000..7f06138ec1 --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/LinkedList.java @@ -0,0 +1,180 @@ +package com.coding.basic; + +import java.util.NoSuchElementException; + +public class LinkedList implements List { + + private Node head; + private int size; + + public void add(Object o){ + //判断有没有头结点 + if(head == null) + head = new Node(o,null); + else { + Node newNode = head; + while(newNode.next != null){ + newNode = newNode.next; + } + newNode.next = new Node(o,null); + + } + + } + public void add(int index , Object o){ + //检查下标是否越界 + if(index < 0 || index > size){ + throw new IndexOutOfBoundsException("index:" + index + "越界;"); + } + Node node = head; + //插入的是第一个头结点 + if(index == 0){ + Node newNode = new Node(o,head); + head = newNode; + size ++; + } + else{ + for(int i = 1; i < index; i++){ + node = node.next; + } + //在index处插入o,并且将o的next节点设为node.next + Node newNode = new Node(o, node.next); + node.next = newNode; + size++; + } +} + + public Object get(int index){ + //检查下标是否越界 + if(index < 0 || index > size){ + throw new IndexOutOfBoundsException("index:" + index + "越界;"); + } + Node node = head; + for (int i = 1; i <= index; i++) { + node = node.next; + } + return node.data; + } + + public Object remove(int index){ + //检查下标是否越界 + if(index < 0 || index > size){ + throw new IndexOutOfBoundsException("index:" + index + "越界;"); + } + Node node = head; + Node removeNode; + if (index == 0) { + //第一个节点直接将头节点指向下一个节点 + removeNode = head; + head = head.next; + } + else { + //找到索引值的前一个节点 + for (int i = 1; i < index; i++) { + node = node.next; + } + removeNode = node.next; + //前一个节点指针,指向被删除节点所指向的节点 + node.next = removeNode.next; + } + size--; + return removeNode.data; + } + + + public int size(){ + return size; + } + + public void addFirst(Object o){ + Node newNode = new Node(o, head.next); + head.next = newNode; + size++; + } + + public void addLast(Object o){ + add(o); + } + + public Object removeFirst(){ + if(size <= 0){ + throw new IndexOutOfBoundsException("没有元素;"); + } + Node node = head; + head = head.next; + size--; + return node.data; + } + + public Object removeLast(){ + if(size <= 0){ + throw new IndexOutOfBoundsException("没有元素;"); + } + Node node = head; + while(node.next != null){ + node = node.next; + } + Object val = node.data; + node = null; + size--; + return val; + } + private static class Node{ + Object data; + Node next; + + Node(Object data, Node next) { + this.data = data; + this.next = next; + + } + } + + + + + public Iterator iterator(){ + return new Itr(this); + } + + private class Itr implements Iterator{ + private int l = -1; + private LinkedList list; + private Itr(LinkedList linkedList) { + // TODO Auto-generated constructor stub + this.list = list; + + } + + @Override + public boolean hasNext() { + // TODO Auto-generated method stub + return l < list.size - 1; + } + + @Override + public Object next() { + // TODO Auto-generated method stub + l++; + if (l >= list.size) { + l--; + throw new IndexOutOfBoundsException(); + } + + return list.get(l); + } + + @Override + public Object remove() { + // TODO Auto-generated method stub + if (l < 0) { + throw new NoSuchElementException(); + } + Object val = list.removeLast(); + l--; + return val; + } + + } + + } diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/List.java b/group15/1519_137845093/src_1st_homework_1519_137845093/List.java new file mode 100644 index 0000000000..10d13b5832 --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/List.java @@ -0,0 +1,9 @@ +package com.coding.basic; + +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/Queue.java b/group15/1519_137845093/src_1st_homework_1519_137845093/Queue.java new file mode 100644 index 0000000000..3433125a8b --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/Queue.java @@ -0,0 +1,29 @@ +package com.coding.basic; +import java.util.NoSuchElementException; + +public class Queue { + private int size; + private LinkedList list = new LinkedList(); + + public void enQueue(Object o){ + list.addLast(o); + size++; + } + + public Object deQueue(){ + if(size<=0){ + throw new NoSuchElementException(); + } + Object deQueue = list.removeLast(); + size--; + return deQueue; + } + + public boolean isEmpty(){ + return (size>=0); + } + + public int size(){ + return size; + } +} diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/Stack.java b/group15/1519_137845093/src_1st_homework_1519_137845093/Stack.java new file mode 100644 index 0000000000..036baafc73 --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/Stack.java @@ -0,0 +1,39 @@ +package com.coding.basic; + +import java.util.NoSuchElementException; + +public class Stack { + private ArrayList elementData = new ArrayList(); + private int size; + private Object removeElement; + public void push(Object o){ + elementData.add(o); + size++; + } + + public Object pop(){ + if(size<=0){ + throw new NoSuchElementException(); + } + int l = size - 1; + removeElement = elementData.remove(l); + size--; + return removeElement; + } + + public Object peek(){ + if(size<=0){ + throw new NoSuchElementException(); + } + int len = size-1; + return elementData.get(len); + } + + public boolean isEmpty(){ + return (size>=0); + } + + public int size(){ + return size; + } +}