PRQuadTree / src / FlyWeightNode.java
FlyWeightNode.java
Raw
/**
 * Single empty leaf node that is created at compile-time of
 * the program. Empty child node point towards flyweight node.
 * Makes NULL logic much easier to deal with.
 * @author nickgrifasi
 * @version 10/15/21
 *
 */
public class FlyWeightNode implements BaseNode {
    
    private static FlyWeightNode flyNode = new FlyWeightNode();
    
    /**
     * Default constructor for FlyWeightNode
     */
    public FlyWeightNode()
    {
        //method left intentionally empty
    }
       
    /**
     * Insert method for FlyWeightNode
     */
    @Override
    public BaseNode insert(int x, int y, int width, Point point)
    {
        LeafNode leafNode = new LeafNode(point);
        return leafNode;
    }
    
    /**
     * Removal method for FlyWeightNode
     * @param x x coordinate
     * @param y y coordinate
     * @param width width
     * @param point point to be removed
     * @param skip flag for skipList name logic
     * @return Point removed from list, null for flyWeight
     */
    public Point remove(int x, int y, int width, Point point, boolean skip)
    {
        return null;
    }
    
    /**
     * MergeTree method for FlyWeightNode
     */
    @Override
    public BaseNode mergeTree(int x, int y, int width)
    {
        return this;
    }
    
    /**
     * findDuplicates method for FlyWeightNode
     */
    @Override
    public void findDuplicates()
    {
        //method left intentionally empty!
    }
    
    /**
     * returns data in FlyWeight, always null
     */
    @Override
    public LinkedList getPoint()
    {
        return null;
    }
    
    /**
     * returns number of nonDupe points,
     * flyWeight will always have zero.
     * @return int of nonDupe, 0 for flyWeight
     */
    public int getNonDupe()
    {
        return 0;
    }
    
    /**
     * getter method that retrieves a flyWeightNode
     * @return returns static flyWeightNode
     */
    public static FlyWeightNode getFlyWeight()
    {
        return flyNode;
    }
    
    /**
     * Dump method for FlyWeightNode
     * prints nodes preorder traversal order,
     * one node per line, each line indent 2 spaces by level
     * 
     */
    @Override
    public int dump(int x, int y, int width, int level)
    {
        String temp = "";
        int i = 0;
        //each level of the tree is 2 space indent
        while (i < level)
        {
            temp = temp + "  ";
            i++;
        }
        
        System.out.println(temp + "Node at " + x + ", "
                + y + ", " + width + ": Empty");
        return 1;
    }

}