-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from onlyliuxin/master
20170729合并
- Loading branch information
Showing
111 changed files
with
4,031 additions
and
11 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/bridge/GraphicLibrary1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.coderising.dp.bridge; | ||
|
||
public class GraphicLibrary1 { | ||
public void draw_a_line(int x1,int y1,int x2,int y2){ | ||
|
||
} | ||
public void draw_a_circle(int x,int y, int r){ | ||
|
||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/bridge/GraphicLibrary2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.coderising.dp.bridge; | ||
|
||
public class GraphicLibrary2 { | ||
public void drawLine(int x1,int x2,int y1,int y2){ | ||
|
||
} | ||
public void drawCircle(int x,int y, int r){ | ||
|
||
} | ||
|
||
} |
29 changes: 18 additions & 11 deletions
29
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/builder/TagBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
package com.coderising.dp.builder; | ||
|
||
public class TagBuilder { | ||
|
||
private TagNode rootNode; | ||
private TagNode currentNode; | ||
private TagNode parentNode; | ||
public TagBuilder(String rootTagName){ | ||
|
||
rootNode = new TagNode(rootTagName); | ||
currentNode = rootNode; | ||
parentNode = null; | ||
} | ||
|
||
public TagBuilder addChild(String childTagName){ | ||
|
||
return null; | ||
parentNode = this.currentNode; | ||
this.currentNode = new TagNode(childTagName); | ||
parentNode.add(currentNode); | ||
return this; | ||
} | ||
public TagBuilder addSibling(String siblingTagName){ | ||
|
||
|
||
return null; | ||
this.currentNode = new TagNode(siblingTagName); | ||
parentNode.add(this.currentNode); | ||
return this; | ||
|
||
} | ||
public TagBuilder setAttribute(String name, String value){ | ||
|
||
return null; | ||
this.currentNode.setAttribute(name, value); | ||
return this; | ||
} | ||
public TagBuilder setText(String value){ | ||
|
||
return null; | ||
this.currentNode.setValue(value); | ||
return this; | ||
} | ||
public String toXML(){ | ||
return null; | ||
return this.rootNode.toXML(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/composite/Line.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.coderising.dp.composite; | ||
|
||
public class Line implements Shape { | ||
|
||
@Override | ||
public void draw() { | ||
|
||
|
||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/composite/Rectangle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.coderising.dp.composite; | ||
|
||
public class Rectangle implements Shape { | ||
|
||
@Override | ||
public void draw() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/composite/Shape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.coderising.dp.composite; | ||
|
||
public interface Shape { | ||
public void draw(); | ||
} |
11 changes: 11 additions & 0 deletions
11
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/composite/Square.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.coderising.dp.composite; | ||
|
||
public class Square implements Shape { | ||
|
||
@Override | ||
public void draw() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/composite/Text.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.coderising.dp.composite; | ||
|
||
public class Text implements Shape { | ||
|
||
@Override | ||
public void draw() { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
students/1158154002/src/main/java/com/coderising/dp/builder/TagBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.coderising.dp.builder; | ||
|
||
import java.util.List; | ||
|
||
public class TagBuilder { | ||
private TagNode root; | ||
private TagNode now; | ||
private TagNode prev; | ||
public TagBuilder(String rootTagName) { | ||
root=new TagNode(rootTagName); | ||
now=root; | ||
} | ||
|
||
public TagBuilder addChild(String childTagName) { | ||
prev=now; | ||
now=new TagNode(childTagName); | ||
prev.add(now); | ||
|
||
return this; | ||
} | ||
|
||
public TagBuilder addSibling(String siblingTagName) { | ||
List<TagNode> children=prev.getChildren(); | ||
now=new TagNode(siblingTagName); | ||
children.add(now); | ||
return this; | ||
|
||
} | ||
|
||
public TagBuilder setAttribute(String name, String value) { | ||
now.setAttribute(name, value); | ||
return this; | ||
} | ||
|
||
public TagBuilder setText(String value) { | ||
|
||
return this; | ||
} | ||
|
||
public String toXML() { | ||
return root.toXML(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
students/1158154002/src/main/java/com/coderising/dp/builder/TagBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.coderising.dp.builder; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
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") | ||
.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); | ||
|
||
// com.oracle.nio.BufferSecrets | ||
// | ||
// com.sun.corba.se.spi.extension.ServantCachingPolicy | ||
// | ||
// java.net.ProxySelector | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
students/1158154002/src/main/java/com/coderising/dp/builder/TagNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.coderising.dp.builder; | ||
|
||
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 + "\""; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ents/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.coderings.dp.builder; | ||
|
||
public class TagBuilder { | ||
|
||
final TagNode rootNode; | ||
|
||
TagNode iteratorNode; | ||
|
||
TagNode prevIteratorNode; | ||
|
||
public TagBuilder(String rootTagName) { | ||
rootNode = new TagNode(rootTagName); | ||
iteratorNode = rootNode; | ||
prevIteratorNode = rootNode; | ||
} | ||
|
||
public TagBuilder addChild(String childTagName) { | ||
TagNode tagNode = new TagNode(childTagName); | ||
iteratorNode.add(tagNode); | ||
|
||
prevIteratorNode = iteratorNode; | ||
iteratorNode = tagNode; | ||
|
||
return this; | ||
} | ||
|
||
public TagBuilder addSibling(String siblingTagName) { | ||
TagNode tagNode = new TagNode(siblingTagName); | ||
prevIteratorNode.add(tagNode); | ||
|
||
iteratorNode = tagNode; | ||
|
||
return this; | ||
} | ||
|
||
public TagBuilder setAttribute(String name, String value) { | ||
iteratorNode.setAttribute(name, value); | ||
return this; | ||
} | ||
|
||
public TagBuilder setText(String value) { | ||
iteratorNode.setValue(value); | ||
return this; | ||
} | ||
|
||
public String toXML() { | ||
return rootNode.toXML(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.coderings.dp.builder; | ||
|
||
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") | ||
.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); | ||
} | ||
|
||
} |
Oops, something went wrong.