⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findfilter.java

📁 J2ME程序设计实例教程的源码
💻 JAVA
字号:
import java.io.IOException;
import javax.microedition.rms.*;

/**
 * 课程对象过滤器,用于设置查找条件
 */
class FindFilter implements RecordFilter {
    private String name = null; //课程名
    private int week = -1;      //上课日期
    private int jie = -1;       //上课时间
    private Curriculum curr;
    
    public FindFilter() {
        curr = new Curriculum(null);
    }
    
    //设置过滤条件
    public void setCondition(String name) {
        this.name = name;
        week = -1;
        jie = -1;
    }
    
    //设置过滤条件
    public void setCondition(int week) {
        this.week = week;
        name = null;
        jie = -1;
    }
    
    //设置过滤条件
    public void setCondition(int week, int jie) {
        this.week = week;
        this.jie = jie;
        name = null;
    }
    
    //接口RecordFilter中的方法,当记录存储获取记录的枚举时,
    //该接口方法不断将被回调。data为记录存储中的每一条记录。
    public boolean matches(byte[] data) {
        boolean suited = true;
        try {
            curr.setData(data);
            if(name != null && !name.equals(curr.getName())) {
                suited = false;
            }
            else if(week != -1 && jie == -1 && curr.getDay() != week) {
                suited = false;
            }
            else if(week != -1 && jie != -1 && (curr.getDay() != week || curr.getTime() != jie)) {
                suited = false;
            }
        }
        catch(IOException ioe) {
            suited = false;
        }
        
        return suited;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -