static RowColumnVector get(final RowColumnVector[] cacheArray, final int pos) { if (cacheArray==STREAMED) return new RowColumnVector(pos); int low=0; int high=cacheArray.length-1; while (true) { int mid=(low+high) >> 1; final RowColumnVector rowColumnVector=cacheArray[mid]; if (rowColumnVector.pos<pos) { if (mid==high) return new RowColumnVector(rowColumnVector.row,pos-rowColumnVector.pos+1,pos); low=mid+1; } else if (rowColumnVector.pos>pos) { high=mid-1; } else { return rowColumnVector; } } } }
static RowColumnVector[] getCacheArray(final Source source) { if (source.isStreamed()) return STREAMED; final int lastSourcePos=source.end-1; final ArrayList<RowColumnVector> list=new ArrayList<RowColumnVector>(); int pos=0; list.add(FIRST); int row=1; while (pos<=lastSourcePos) { final char ch=source.charAt(pos); if (ch=='\n' || (ch=='\r' && (pos==lastSourcePos || source.charAt(pos+1)!='\n'))) list.add(new RowColumnVector(++row,1,pos+1)); pos++; } return list.toArray(new RowColumnVector[list.size()]); }