1 11 package org.eclipse.jface.text.reconciler; 12 13 import java.util.List ; 14 import java.util.ArrayList ; 15 16 17 25 class DirtyRegionQueue { 26 27 28 private List fDirtyRegions= new ArrayList (); 29 30 33 public DirtyRegionQueue() { 34 super(); 35 } 36 37 42 public void addDirtyRegion(DirtyRegion dr) { 43 DirtyRegion lastDR= getLastDirtyRegion(); 46 boolean wasMerged= false; 47 if (lastDR != null) 48 if (lastDR.getType() == dr.getType()) 49 if (lastDR.getType() == DirtyRegion.INSERT) { 50 if (lastDR.getOffset() + lastDR.getLength() == dr.getOffset()) { 51 lastDR.mergeWith(dr); 52 wasMerged= true; 53 } 54 } else if (lastDR.getType() == DirtyRegion.REMOVE) { 55 if (dr.getOffset() + dr.getLength() == lastDR.getOffset()) { 56 lastDR.mergeWith(dr); 57 wasMerged= true; 58 } 59 } 60 61 if (!wasMerged) 62 fDirtyRegions.add(dr); 64 } 65 66 71 private DirtyRegion getLastDirtyRegion() { 72 int size= fDirtyRegions.size(); 73 return (size == 0 ? null : (DirtyRegion) fDirtyRegions.get(size - 1)); 74 } 75 76 81 public int getSize() { 82 return fDirtyRegions.size(); 83 } 84 85 88 public void purgeQueue() { 89 fDirtyRegions.clear(); 90 } 91 92 97 public DirtyRegion removeNextDirtyRegion() { 98 if (fDirtyRegions.size() == 0) 99 return null; 100 DirtyRegion dr= (DirtyRegion) fDirtyRegions.get(0); 101 fDirtyRegions.remove(0); 102 return dr; 103 } 104 } 105 | Popular Tags |