1 package net.sf.saxon.tree; 2 3 10 11 public class LineNumberMap { 12 13 private int[] sequenceNumbers; 14 private int[] lineNumbers; 15 private int allocated; 16 17 public LineNumberMap() { 18 sequenceNumbers = new int[1000]; 19 lineNumbers = new int[1000]; 20 allocated = 0; 21 } 22 23 26 27 public void setLineNumber(int sequence, int line) { 28 if (sequenceNumbers.length <= allocated + 1) { 29 int[] s = new int[allocated * 2]; 30 int[] l = new int[allocated * 2]; 31 System.arraycopy(sequenceNumbers, 0, s, 0, allocated); 32 System.arraycopy(lineNumbers, 0, l, 0, allocated); 33 sequenceNumbers = s; 34 lineNumbers = l; 35 } 36 sequenceNumbers[allocated] = sequence; 37 lineNumbers[allocated] = line; 38 allocated++; 39 } 40 41 44 45 public int getLineNumber(int sequence) { 46 for (int i=1; i<allocated; i++) { 48 if (sequenceNumbers[i] > sequence) { 49 return lineNumbers[i-1]; 50 } 51 } 52 return lineNumbers[allocated-1]; 53 } 54 55 56 } 57 58 | Popular Tags |