/////// OrderedLines.java /////// import java.io.*; class OrderedLines extends OrderedSeq { // public section public OrderedLines(int pos, // key position int size, // initial no. of lines String dlm) // delimeter string { sk = new SortKey(pos, dlm); // (1) tl = new TextLines(size); // (2) } public OrderedLines(int pos) { sk = new SortKey(pos); tl = new TextLines(); } public OrderedLines() { sk = new SortKey(); tl = new TextLines(); } public String get(int i) { if ( ! sorted() ) sort(); return tl.getLine(i).toString(); } public void remove(int i) // delete entry i { if ( ! sorted() ) sort(); tl.delLine(i); } public int capacity() { return -1; } // no capacity restriction public int length() { return tl.length(); } public int input(InputStream in) // returns no of lines read or -1 { return tl.input(in); } public void display(OutputStream out) { if ( ! sorted() ) sort(); tl.output(out); } // protected section protected boolean append(Object line) // append entry at end { tl.addLine((String) line); return true; } protected void swap(int i, int j) // interchange lines { tl.swap(i,j); } protected int cmp(int i, int j) { return sk.cmp(tl.getLine(i).toString(), tl.getLine(j).toString()); } protected int cmp(Object k, int j) { return ((String) k).compareTo(sk.key(tl.getLine(j).toString())); } // private section private TextLines tl; private SortKey sk; }