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
public class TreeNode { | |
private final String name; | |
private final Collection<TreeNode> children; | |
public TreeNode(String name) { | |
this.name = name; | |
children = new HashSet<TreeNode>(); | |
} | |
public String getName() { |
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
final TreeNode shape = new TreeNode("shape"); | |
final TreeNode ellipse = new TreeNode("ellipse"); | |
shape.addChild(ellipse); | |
ellipse.addChild(new TreeNode("circle")); | |
final TreeNode polygon = new TreeNode("polygon"); | |
shape.addChild(polygon); | |
final TreeNode triangle = new TreeNode("triangle"); | |
polygon.addChild(triangle); | |
triangle.addChild(new TreeNode("equilateral")); | |
triangle.addChild(new TreeNode("isosceles")); |
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
shape { | |
ellipse { | |
circle | |
} | |
polygon { | |
petagon | |
triangle { | |
scalene | |
equilateral | |
isosceles |
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
import java.util.ArrayList; | |
import java.util.List; | |
public class abc { | |
public static void main(String[] args) { | |
List<String> abc = new ArrayList<String>(); | |
abc.add("a"); | |
abc.add("b"); | |
abc.add("c"); |
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
[:a,:b,:c].each do |s| | |
puts s | |
end |
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
require 'java' | |
require 'Trees.jar' | |
TreeNode = com.claymccoy.trees.TreeNode | |
class TreeNode | |
def to_s | |
puts to_string.gsub("\\r", "\\n") | |
end | |
end |
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
class TreeNode | |
def method_missing(methodname, *args, &block) | |
child = self.children().find { |child| methodname.to_s == child.name } | |
if child.nil? | |
child = TreeNode.new(methodname.to_s) | |
self.add_child(child) | |
end | |
child.instance_eval(&block) if block_given? | |
child | |
end |
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
TreeNode ellipse = null; | |
for (TreeNode treeNode : shape.getChildren()) { | |
if ("ellipse".equals(treeNode.getName())) { | |
ellipse = treeNode; | |
break; | |
} | |
} | |
if (null == ellipse) { | |
ellipse = new TreeNode("ellipse"); | |
shape.addChild(ellipse); |
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
shape { | |
ellipse.circle | |
polygon { | |
petagon | |
triangle { | |
scalene | |
equilateral | |
isosceles | |
} | |
hexagon |
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
Tree.create { | |
shape { | |
ellipse.circle | |
polygon { | |
petagon | |
triangle { | |
scalene | |
equilateral | |
isosceles | |
} |
OlderNewer