diff --git a/exceptions/EmptyTreeException.java b/exceptions/EmptyTreeException.java new file mode 100644 index 0000000..ea3aa34 --- /dev/null +++ b/exceptions/EmptyTreeException.java @@ -0,0 +1,17 @@ +package exceptions; + +/** + * Created with MONSTER. + * User: xgiovio + * Date: 05/03/14 + * Time: 0.09 + */ +public class EmptyTreeException extends RuntimeException { + + public EmptyTreeException(){ + super("Empty Tree"); + } + public EmptyTreeException(String msg){ + super(msg); + } +} diff --git a/tree/LinkedTree.java b/tree/LinkedTree.java new file mode 100644 index 0000000..8163323 --- /dev/null +++ b/tree/LinkedTree.java @@ -0,0 +1,73 @@ +package tree; + +import exceptions.BoundaryViolationException; +import exceptions.EmptyTreeException; +import exceptions.InvalidPositionException; +import position.Position; + +import java.util.Iterator; + +/** + * Created with xgiovio.macbookair. + * User: xgiovio + * Date: 07/04/14 + * Time: 15:45 + */ +public class LinkedTree implements Tree { + + + @Override + public int size() { + return 0; + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public Iterable> positions() { + return null; + } + + @Override + public E replace(Position v, E e) throws InvalidPositionException { + return null; + } + + @Override + public Position root() throws EmptyTreeException { + return null; + } + + @Override + public Position parent(Position v) throws InvalidPositionException, BoundaryViolationException { + return null; + } + + @Override + public Iterable> children(Position v) throws InvalidPositionException { + return null; + } + + @Override + public boolean isInternal(Position v) throws InvalidPositionException { + return false; + } + + @Override + public boolean isExternal(Position v) throws InvalidPositionException { + return false; + } + + @Override + public boolean isRoot(Position v) throws InvalidPositionException { + return false; + } + + @Override + public Iterator iterator() { + return null; + } +} diff --git a/tree/Tree.java b/tree/Tree.java new file mode 100644 index 0000000..1805ae8 --- /dev/null +++ b/tree/Tree.java @@ -0,0 +1,33 @@ +package tree; + +import exceptions.BoundaryViolationException; +import exceptions.EmptyTreeException; +import exceptions.InvalidPositionException; +import position.Position; + +import java.util.Iterator; + +/** + * Created with xgiovio.macbookair. + * User: xgiovio + * Date: 07/04/14 + * Time: 15:17 + */ +public interface Tree extends Iterable { + + + public int size(); + public boolean isEmpty(); + + public Iterable> positions (); + public E replace (Position v, E e) throws InvalidPositionException; + public Position root () throws EmptyTreeException; + public Position parent (Position v) throws InvalidPositionException, BoundaryViolationException; + public Iterable > children (Position v) throws InvalidPositionException; // anche se e' foglia + + public boolean isInternal (Position v) throws InvalidPositionException; + public boolean isExternal (Position v) throws InvalidPositionException; + public boolean isRoot (Position v) throws InvalidPositionException; + + +} diff --git a/tree/TreeNode.java b/tree/TreeNode.java new file mode 100644 index 0000000..9c2c1d5 --- /dev/null +++ b/tree/TreeNode.java @@ -0,0 +1,55 @@ +package tree; + +import position.Position; +import position.PositionList; + +/** + * Created with xgiovio.macbookair. + * User: xgiovio + * Date: 07/04/14 + * Time: 15:30 + */ +public class TreeNode implements TreePosition { + + private E element = null; + private TreePosition parent = null; + private PositionList> children= null; + + + public TreeNode(E in_element, TreePosition in_parent, PositionList> in_children ){ + element = in_element; + parent = in_parent; + children = in_children; + } + + + @Override + public void setElement(E o) { + element = o; + } + + @Override + public PositionList> getChildren() { + return children; + } + + @Override + public void setChildren(PositionList> c) { + children = c; + } + + @Override + public TreePosition getParent() { + return parent; + } + + @Override + public void setParent(TreePosition v) { + parent = v; + } + + @Override + public E element() { + return element; + } +} diff --git a/tree/TreePosition.java b/tree/TreePosition.java new file mode 100644 index 0000000..37695f1 --- /dev/null +++ b/tree/TreePosition.java @@ -0,0 +1,20 @@ +package tree; + +import position.Position; +import position.PositionList; + +/** + * Created with xgiovio.macbookair. + * User: xgiovio + * Date: 07/04/14 + * Time: 15:31 + */ +public interface TreePosition extends Position { + + public void setElement(E o); + public PositionList> getChildren (); + public void setChildren (PositionList> c); + public TreePosition getParent(); + public void setParent (TreePosition v); + +}