资源简介
KWIC java 观察者模式 实现 体系结构课程作业
代码片段和文件信息
// -*- Java -*-
/*
*
*
* Copyright (c) 2002
* Institute for Information Processing and Computer Supported New Media (IICM)
* Graz University of Technology Austria.
*
*
*
*
*
* Name: Alphabetizer.java
*
* Purpose: Sorts circular shifts alphabetically
*
* Created: 05 Nov 2002
*
* $Id$
*
* Description:
* Sorts circular shifts alphabetically
*
*/
package kwic.es;
/*
* $Log$
*/
import java.util.Observable;
import java.util.Observer;
/**
* Similarly to CircularShifter class Alphabetizer class implemets the “Observer“
* part of the standard “Observable“-“Observer“ mechanism. However an object
* of Alphabetizer class “observes“ a LineStorageWrapper object which keeps
* circular shifts whereas an object of CircularShifter class “observes“ a LineStorageWrapper
* object which keeps original lines from a KWIC input file. Any event produced and sent
* by the observed LineStorageWrapper object (e.g. whenever a new circular shift
* has been added) is catched by Alphabetizer object. In turn this leads to
* sorting the circular shifts alphabetically.
* @author dhelic
* @version $Id$
*/
public class Alphabetizer implements Observer{
//----------------------------------------------------------------------
/**
* Fields
*
*/
//----------------------------------------------------------------------
//----------------------------------------------------------------------
/**
* Constructors
*
*/
//----------------------------------------------------------------------
//----------------------------------------------------------------------
/**
* Methods
*
*/
//----------------------------------------------------------------------
//----------------------------------------------------------------------
/**
*/
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;
}
}
//----------------------------------------------------------------------
/**
* Inner classes
*
*/
//----------------------------------------------------------------------
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2784 2009-11-24 07:50 es\Alphabetizer.java
文件 4292 2009-11-24 07:50 es\CircularShifter.java
文件 3658 2009-11-24 07:50 es\Input.java
文件 7350 2009-11-24 07:50 es\KWIC.java
文件 15166 2009-11-24 07:50 es\LineStorage.java
文件 3847 2009-11-24 07:50 es\LineStorageChangeEvent.java
文件 5215 2009-11-24 07:50 es\LineStorageWrapper.java
文件 2059 2009-11-24 07:50 es\Output.java
文件 2016 2009-11-24 08:05 es\WordsIndex.java
目录 0 2009-11-27 16:02 es
----------- --------- ---------- ----- ----
46387 10
- 上一篇:读取LCM的日志文件
- 下一篇:Android tab 栏居中滚动
评论
共有 条评论