EldiraSesto

ProductTreeNode

May 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package tree.node;
  2.  
  3. import rbvs.product.CompositeProduct;
  4. import rbvs.product.IProduct;
  5. import rbvs.product.Product;
  6.  
  7.  
  8.  
  9. public class ProductTreeNode extends GenericTreeNode<IProduct> { // Eldira 11815163
  10.     private ProductTreeNode(CompositeProduct value) {
  11.         super(value.getName(), value);
  12.     }
  13.  
  14.     public ProductTreeNode(IProduct value) {
  15.         this(value.getName(), value);
  16.     }
  17.  
  18.     public ProductTreeNode(String label, IProduct value) {
  19.         super(label, value);
  20.         initialize(value);
  21.     }
  22.  
  23.     private void initialize(IProduct item) {
  24.         if (item instanceof CompositeProduct) {
  25.             CompositeProduct compositeProduct = (CompositeProduct) item;
  26.             for (Product product : compositeProduct.getProducts()) {
  27.                 this.getChildren().add(new ProductTreeNode(product));
  28.             }
  29.         } else {
  30.             this.getChildren().clear();
  31.         }
  32.     }
  33.  
  34.     public ProductTreeNode deepCopy() {
  35.         return (ProductTreeNode) super.deepCopy();
  36.     }
  37. }
Add Comment
Please, Sign In to add comment