Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4a5a017
Merge pull request #1 from onlyliuxin/master
250103158 Jun 12, 2017
876cf64
提交准备代码
Jun 12, 2017
ce292c5
Merge remote-tracking branch 'upstream/master'
Jun 19, 2017
2e79208
Merge remote-tracking branch 'upstream/master'
Jun 23, 2017
159f3d7
Merge remote-tracking branch 'upstream/master'
Aug 6, 2017
2171412
1241588932:设计模式第一次作业
Aug 6, 2017
3a70043
Merge pull request #8 from onlyliuxin/master
lorcx Aug 9, 2017
6d95c23
add project of responsibility chain pattern and command pattern
Aug 10, 2017
93c5373
2017年8月10日23:00:56
Aug 10, 2017
f39df1c
chain and command design homework
Aug 11, 2017
e1eb52b
Add Command&Chain pattern homework
jjyyjjyy Aug 12, 2017
1cc9400
作业提交
lorcx Aug 12, 2017
7cdd0cf
assignment 0806
mingming-lu Aug 13, 2017
9e9c144
Merge pull request #9 from onlyliuxin/master
lorcx Aug 15, 2017
61d566a
Merge pull request #2 from onlyliuxin/master
250103158 Aug 17, 2017
4b02dc5
add project of LiteJUnit
Aug 18, 2017
e3e452b
Merge pull request #10 from onlyliuxin/master
lorcx Aug 26, 2017
bc0d3b3
Merge pull request #562 from 250103158/master
honokaBiu Aug 26, 2017
0a69288
Merge pull request #546 from Enan01/master
honokaBiu Aug 26, 2017
221c295
Merge pull request #559 from akinaru-lu/master
honokaBiu Aug 26, 2017
2ecc679
Merge pull request #558 from miniyk2012/master
honokaBiu Aug 26, 2017
976b0f7
Merge pull request #556 from lorcx/master
honokaBiu Aug 26, 2017
a2c9fec
Merge pull request #554 from jy97799/master
honokaBiu Aug 26, 2017
0530dfe
Merge pull request #553 from starlight0405/master
honokaBiu Aug 26, 2017
dddbc14
Merge pull request #551 from yangzhm/master
honokaBiu Aug 26, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions students/1241588932/design-patterns-enan/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.coderising</groupId>
<artifactId>design-patterns-enan</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>design-patterns-enan</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<optional>true</optional>
</dependency>

</dependencies>
<repositories>
<repository>
<id>aliyunmaven</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package first;

public class TagBuilder {

private TagNode tagNode;
private TagNode currentTagNode;
private TagNode superTagNode;

public TagBuilder(String tagName) {
this.tagNode = new TagNode(tagName);
this.currentTagNode = this.tagNode;
this.superTagNode = null;
}

public TagBuilder addChild(String childTagName) {
this.superTagNode = this.currentTagNode;
TagNode tagNode = new TagNode(childTagName);
this.currentTagNode.add(tagNode);
this.currentTagNode = tagNode;
return this;
}

public TagBuilder setAttribute(String key, String value) {
this.currentTagNode.setAttribute(key, value);
return this;
}

public TagBuilder addSibling(String siblingTagName) {
TagNode tagNode = new TagNode(siblingTagName);
this.superTagNode.add(tagNode);
this.currentTagNode = tagNode;
return this;
}

public TagNode build() {
return tagNode;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package first;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TagBuilderTest {

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void testToXML() {

TagBuilder builder = new TagBuilder("order");

String xml = builder.addChild("line-items")
.addChild("line-item").setAttribute("pid", "P3677").setAttribute("qty", "3")
.addSibling("line-item").setAttribute("pid", "P9877").setAttribute("qty", "10")
.build()
.toXML();

String expected = "<order>"
+ "<line-items>"
+ "<line-item pid=\"P3677\" qty=\"3\"/>"
+ "<line-item pid=\"P9877\" qty=\"10\"/>"
+ "</line-items>"
+ "</order>";

System.out.println(xml);
assertEquals(expected, xml);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package first;

import java.util.ArrayList;
import java.util.List;

public class TagNode {
private String tagName;
private String tagValue;
private List<TagNode> children = new ArrayList<>();
private List<Attribute> attributes = new ArrayList<>();

public TagNode(String name){
this.tagName = name;
}
public void add(TagNode child){
this.children.add(child);
}
public void setAttribute(String name, String value) {
Attribute attr = findAttribute(name);
if(attr != null){
attr.value = value;
return;
}

attributes.add(new Attribute(name,value));
}
private Attribute findAttribute(String name){
for(Attribute attr : attributes){
if(attr.name.equals(name)){
return attr;
}
}
return null;
}
public void setValue(String value) {
this.tagValue = value;

}
public String getTagName() {
return tagName;
}
public List<TagNode> getChildren() {
return children;
}

private static class Attribute{
public Attribute(String name, String value) {
this.name = name;
this.value = value;
}
String name;
String value;

}
public String toXML(){
return toXML(this);
}
private String toXML(TagNode node){
StringBuilder buffer = new StringBuilder();
buffer.append("<").append(node.tagName);
if(node.attributes.size()> 0){
for(int i=0;i<node.attributes.size();i++){
Attribute attr = node.attributes.get(i);
buffer.append(" ").append(toXML(attr));
}
}
if(node.children.size()== 0){
buffer.append("/>");
return buffer.toString();
}
buffer.append(">");
for(TagNode childNode : node.children){
buffer.append(toXML(childNode));
}
buffer.append("</").append(node.tagName).append(">");


return buffer.toString();
}
private String toXML(Attribute attr){
return attr.name+"=\""+attr.value + "\"";
}
}
32 changes: 32 additions & 0 deletions students/250103158/data-structure/answer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.coderising</groupId>
<artifactId>ds-answer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ds-answer</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

</dependencies>
<repositories>
<repository>
<id>aliyunmaven</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.coderising.download;

import com.coderising.download.api.Connection;

public class DownloadThread extends Thread{

Connection conn;
int startPos;
int endPos;

public DownloadThread( Connection conn, int startPos, int endPos){

this.conn = conn;
this.startPos = startPos;
this.endPos = endPos;
}
public void run(){

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

import com.coderising.download.api.Connection;
import com.coderising.download.api.ConnectionException;
import com.coderising.download.api.ConnectionManager;
import com.coderising.download.api.DownloadListener;


public class FileDownloader {

String url;

DownloadListener listener;

ConnectionManager cm;


public FileDownloader(String _url) {
this.url = _url;

}

public void execute(){
// 在这里实现你的代码, 注意: 需要用多线程实现下载
// 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
// (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
// (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
// 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
// 具体的实现思路:
// 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
// 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
// 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
// 3. 把byte数组写入到文件中
// 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法

// 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
Connection conn = null;
try {

conn = cm.open(this.url);

int length = conn.getContentLength();

new DownloadThread(conn,0,length-1).start();

} catch (ConnectionException e) {
e.printStackTrace();
}finally{
if(conn != null){
conn.close();
}
}




}

public void setListener(DownloadListener listener) {
this.listener = listener;
}



public void setConnectionManager(ConnectionManager ucm){
this.cm = ucm;
}

public DownloadListener getListener(){
return this.listener;
}

}
Loading