1 11 package org.eclipse.jdt.internal.ui.packageview; 12 13 import org.eclipse.jface.util.Assert; 14 import org.eclipse.jface.viewers.IElementComparer; 15 16 22 public final class TreePath { 23 private Object [] fSegments; 24 private int fHash; 25 26 public TreePath(Object [] segments) { 27 Assert.isNotNull(segments); 28 for (int i= 0; i < segments.length; i++) { 29 Assert.isNotNull(segments[i]); 30 } 31 fSegments= segments; 32 } 33 34 public Object getSegment(int index) { 35 return fSegments[index]; 36 } 37 38 public int getSegmentCount() { 39 return fSegments.length; 40 } 41 42 public Object getFirstSegment() { 43 if (fSegments.length == 0) 44 return null; 45 return fSegments[0]; 46 } 47 48 public Object getLastSegment() { 49 if (fSegments.length == 0) 50 return null; 51 return fSegments[fSegments.length - 1]; 52 } 53 54 public boolean equals(Object other) { 55 if (!(other instanceof TreePath)) 56 return false; 57 TreePath otherPath= (TreePath)other; 58 if (fSegments.length != otherPath.fSegments.length) 59 return false; 60 for (int i= 0; i < fSegments.length; i++) { 61 if (!fSegments[i].equals(otherPath.fSegments[i])) 62 return false; 63 } 64 return true; 65 } 66 67 public int hashCode() { 68 if (fHash != 0) 69 return fHash; 70 for (int i= 0; i < fSegments.length; i++) { 71 fHash= fHash + fSegments[i].hashCode(); 72 } 73 return fHash; 74 } 75 76 public boolean equals(TreePath otherPath, IElementComparer comparer) { 77 if (comparer == null) 78 comparer= DefaultElementComparer.INSTANCE; 79 if (otherPath == null) 80 return false; 81 if (fSegments.length != otherPath.fSegments.length) 82 return false; 83 for (int i= 0; i < fSegments.length; i++) { 84 if (!comparer.equals(fSegments[i], otherPath.fSegments[i])) 85 return false; 86 } 87 return true; 88 } 89 } 90 | Popular Tags |