1 11 package org.eclipse.compare.structuremergeviewer; 12 13 import java.util.ArrayList ; 14 15 21 public abstract class DiffContainer extends DiffElement implements IDiffContainer { 22 23 private static IDiffElement[] fgEmptyArray= new IDiffElement[0]; 24 private ArrayList fChildren; 25 26 32 public DiffContainer(IDiffContainer parent, int kind) { 33 super(parent, kind); 34 } 35 36 43 public IDiffElement findChild(String name) { 44 Object [] children= getChildren(); 45 for (int i= 0; i < children.length; i++) { 46 IDiffElement child= (IDiffElement) children[i]; 47 if (name.equals(child.getName())) 48 return child; 49 } 50 return null; 51 } 52 53 56 public void add(IDiffElement diff) { 57 if (fChildren == null) 58 fChildren= new ArrayList (); 59 fChildren.add(diff); 60 diff.setParent(this); 61 } 62 63 67 public void removeToRoot(IDiffElement child) { 68 if (fChildren != null) { 69 fChildren.remove(child); 70 child.setParent(null); 71 if (fChildren.size() == 0) { 72 IDiffContainer p= getParent(); 73 if (p != null) 74 p.removeToRoot(this); 75 } 76 } 77 } 78 79 84 public void remove(IDiffElement child) { 85 if (fChildren != null) { 86 fChildren.remove(child); 87 child.setParent(null); 88 } 89 } 90 91 94 public boolean hasChildren() { 95 return fChildren != null && fChildren.size() > 0; 96 } 97 98 101 public IDiffElement[] getChildren() { 102 if (fChildren != null) 103 return (IDiffElement[]) fChildren.toArray(fgEmptyArray); 104 return fgEmptyArray; 105 } 106 } 107 108 | Popular Tags |