diff --git a/src/regions/Octree.java b/src/regions/Octree.java index cda960a..b409c8a 100644 --- a/src/regions/Octree.java +++ b/src/regions/Octree.java @@ -1,44 +1,11 @@ package regions; -public class Octree +public class Octree extends Tree { //STATIC //================================================================== - public static class Node - { - public final boolean full; - public final Node[] nodes; - - public Node(boolean full) - { - this.full = full; - this.nodes = new Node[0]; - } - - public Node(Node[] nodes) - { - this.full = false; - this.nodes = nodes; - } - - } - - - - private static class IntReference - { - int ref; - - IntReference(int i) - { - this.ref = i; - } - } - - - - private static Node parseBytes(IntReference index, byte[] bytes, int parentByte) + Node parseBytes(IntReference index, byte[] bytes, int parentByte) { if (parentByte == 0b00000010) return new Node(true); if (parentByte == 0b00000001) return new Node(false); @@ -63,26 +30,11 @@ public class Octree }); } - - - public static Node parseBytes(int startAtIndex, byte[] bytes) - { - return parseBytes ( new IntReference(startAtIndex), bytes, 0 ); - } - public static Node parseBytes(byte[] bytes) - { - return parseBytes ( new IntReference(0), bytes, 0 ); - } - //INSTANCE //================================================================== - public final Owner owner; - public final Node root; - public Octree(Owner owner, byte[] bytes) { - this.owner = owner; - this.root = parseBytes(bytes); + super(owner, bytes); } } diff --git a/src/regions/Owner.java b/src/regions/Owner.java index 3440fb6..0bbecfd 100644 --- a/src/regions/Owner.java +++ b/src/regions/Owner.java @@ -1,13 +1,15 @@ package regions; +import java.util.List; + public class Owner { - public final String name; - public final Owner parent; - public final Owner[] children; - public final Octree[] trees; + public final String name; + public final Owner parent; + public final List children; + public final List trees; - public Owner(String name, Owner parent, Owner[] children, Octree[] trees) + public Owner(String name, Owner parent, List children, List trees) { this.name = name; this.parent = parent; diff --git a/src/regions/Quadtree.java b/src/regions/Quadtree.java index c276aa9..28238ca 100644 --- a/src/regions/Quadtree.java +++ b/src/regions/Quadtree.java @@ -1,44 +1,11 @@ package regions; -public class Quadtree +public class Quadtree extends Tree { //STATIC //================================================================== - public static class Node - { - public final boolean full; - public final Node[] nodes; - - public Node(boolean full) - { - this.full = full; - this.nodes = new Node[0]; - } - - public Node(Node[] nodes) - { - this.full = false; - this.nodes = nodes; - } - - } - - - - private static class IntReference - { - int ref; - - IntReference(int i) - { - this.ref = i; - } - } - - - - private static Node parseBytes(IntReference index, byte[] bytes, int parentByte) + Node parseBytes(IntReference index, byte[] bytes, int parentByte) { if (parentByte == 0b00000010) return new Node(true); if (parentByte == 0b00000001) return new Node(false); @@ -57,26 +24,11 @@ public class Quadtree }); } - - - public static Node parseBytes(int startAtIndex, byte[] bytes) - { - return parseBytes ( new IntReference(startAtIndex), bytes, 0 ); - } - public static Node parseBytes(byte[] bytes) - { - return parseBytes ( new IntReference(0), bytes, 0 ); - } - //INSTANCE //================================================================== - public final Owner owner; - public final Node root; - public Quadtree(Owner owner, byte[] bytes) { - this.owner = owner; - this.root = parseBytes(bytes); + super(owner, bytes); } } diff --git a/src/regions/Tree.java b/src/regions/Tree.java new file mode 100644 index 0000000..e463698 --- /dev/null +++ b/src/regions/Tree.java @@ -0,0 +1,65 @@ +package regions; + +public abstract class Tree +{ + public static class Node + { + public boolean full; + public Node parent; + public Node[] children; + + public Node(boolean full) + { + this.full = full; + this.children = new Node[0]; + } + + public Node(Node[] nodes) + { + this.full = false; + this.children = nodes; + } + + } + + + + static class IntReference + { + int ref; + + IntReference(int i) + { + this.ref = i; + } + } + + + + abstract Node parseBytes(IntReference index, byte[] bytes, int parentByte); + + + + public Node parseBytes(int startAtIndex, byte[] bytes) + { + return parseBytes ( new IntReference(startAtIndex), bytes, 0 ); + } + + + + public Node parseBytes(byte[] bytes) + { + return parseBytes ( new IntReference(0), bytes, 0 ); + } + + + + public final Owner owner; + public final Node root; + + public Tree(Owner owner, byte[] bytes) + { + this.owner = owner; + this.root = parseBytes(bytes); + } +}