package kwic.es;
import java.util.Observable;
import java.util.Observer;
//排序器,将所有字符串按照字典序排序
//监听拆解后字符串集
public class Alphabetizer implements Observer{
public void update(Observable observable, Object arg){
LineStorageWrapper shifts = (LineStorageWrapper) observable;
LineStorageChangeEvent event = (LineStorageChangeEvent) arg;
//在这里由于删除后原序列中余留的行的顺序并不会改变,所以不用再添加删除情况了
switch(event.getType()){
case LineStorageChangeEvent.ADD:
int count = shifts.getLineCount();
String shift = shifts.getLineAsString(count - 1);
for(int i = 0; i < (count - 1); i++){
if(shift.compareTo(shifts.getLineAsString(i)) <= 0){
shifts.insertLine(shifts.getLine(count - 1), i);
shifts.deleteLine(count);
break;
}
}
break;
default:
break;
}
}
}
package kwic.es;
import java.util.Observable;
import java.util.Observer;
import java.util.ArrayList;
import java.util.StringTokenizer;
//拆分器,按规则将字符串拆分为多个字符串,将拆分后的所有字符串添加到已拆解字符串库中
//监听拆解前字符串库,也就是主程序KWIC中的lines集合
public class CircularShifter implements Observer{
private LineStorageWrapper shifts_;
public CircularShi