1 19 20 package org.netbeans.lib.editor.util; 21 22 import org.netbeans.junit.NbTestCase; 23 24 29 public class FlyOffsetGapListTest extends NbTestCase { 30 31 public FlyOffsetGapListTest(java.lang.String testName) { 32 super(testName); 33 } 34 35 @SuppressWarnings ("unchecked") 36 public void test() throws Exception { 37 FOGL fogl = new FOGL(3); assertEquals(3, fogl.elementOrEndOffset(0)); 39 40 try { 41 fogl.elementOffset(0); 42 fail("Exception not thrown"); 43 } catch (IndexOutOfBoundsException e) { 44 } 46 try { 47 fogl.elementOrEndOffset(1); 48 fail("Exception not thrown"); 49 } catch (IndexOutOfBoundsException e) { 50 } 52 try { 53 fogl.elementOrEndOffset(-1); 54 fail("Exception not thrown"); 55 } catch (IndexOutOfBoundsException e) { 56 } 58 59 fogl.add(new Element(-1, 5)); 60 fogl.defaultInsertUpdate(3, 5); 61 assertEquals(3, fogl.elementOrEndOffset(0)); 62 assertEquals(8, fogl.elementOrEndOffset(1)); 63 } 64 65 private static final class FOGL extends FlyOffsetGapList<Element> { 66 67 private int startOffset; 68 69 FOGL(int startOffset) { 70 this.startOffset = startOffset; 71 } 72 73 @Override 74 protected int startOffset() { 75 return startOffset; 76 } 77 78 protected boolean isElementFlyweight(Element elem) { 79 return elem.isFlyweight(); 80 } 81 82 protected int elementLength(Element elem) { 83 return elem.length(); 84 } 85 86 protected int elementRawOffset(Element elem) { 87 return elem.rawOffset(); 88 } 89 90 protected void setElementRawOffset(Element elem, int rawOffset) { 91 elem.setRawOffset(rawOffset); 92 } 93 94 } 95 96 private static final class Element { 97 98 private int rawOffset; 99 100 private final int length; 101 102 public Element(int rawOffset, int length) { 103 this.rawOffset = rawOffset; 104 this.length = length; 105 } 106 107 public int rawOffset() { 108 return rawOffset; 109 } 110 111 public void setRawOffset(int rawOffset) { 112 this.rawOffset = rawOffset; 113 } 114 115 public int length() { 116 return length; 117 } 118 119 public boolean isFlyweight() { 120 return (rawOffset == -1); 121 } 122 123 } 124 125 } 126 | Popular Tags |