Class Tree

  • All Implemented Interfaces:
    CachingAwareObject

    public class Tree
    extends Item
    Folder Item that also contains it's children.
    Author:
    Sumer Jabri, Alfonso Vásquez
    • Field Detail

      • children

        protected List<Item> children
        The folder's children. Children can be both Items or other Trees.
    • Constructor Detail

      • Tree

        public Tree()
        Default no-arg constructor. Sets folder to true, since a tree is always a folder.
      • Tree

        public Tree​(Item item)
        Copy constructor that takes an item and calls the Item(Item). Sets folder to true, since a tree is always a folder.
      • Tree

        public Tree​(Item item,
                    boolean deepCopy)
        Copy constructor that takes an item and calls the Item(Item, boolean). Sets folder to true, since a tree is always a folder.
      • Tree

        public Tree​(Tree tree)
        Copy constructor that takes another tree. Performs a deep copy (calls Item(Item, boolean) with true).
      • Tree

        public Tree​(Tree tree,
                    boolean deepCopy)
        Copy constructor that takes another tree. Performs a deep copy depending on the value of the deepCopy flag. In a deep copy, a deep copy of each child is done (by calling Item(Item, boolean) and Tree(Tree, boolean)).
    • Method Detail

      • setFolder

        public void setFolder​(boolean folder)
        Overrides Item.setFolder(boolean), by checking that the flag is never set to false, since a tree is always a folder.
        Overrides:
        setFolder in class Item
        Throws:
        IllegalArgumentException - if the method was called with false (the folder flag should never being set to false).
      • getChildren

        public List<Item> getChildren()
        Returns the tree's children. Children can be both Items or other Trees.
      • setChildren

        public void setChildren​(List<Item> children)
        Sets the tree's children. Children can be both Items or other Trees.
        Parameters:
        children -
      • addChild

        public void addChild​(Item child)
        Adds a child. The child can be both Items or another Trees.
      • removeChild

        public boolean removeChild​(Item child)
        Removes a child.
      • equals

        public boolean equals​(Object o)
        Returns true if Item.equals(Object) returns true and if the specified Tree's and this instance's children are equal.
        Overrides:
        equals in class Item
      • hashCode

        public int hashCode()
        Returns the hash code, which is a combination of Item.hashCode() and the list of children's hash code.
        Overrides:
        hashCode in class Item