simplefilter.java

来自「7个J2ME例子」· Java 代码 · 共 52 行

JAVA
52
字号
/* * Copyright (c) 2000-2001 Sun Microsystems, Inc. All Rights Reserved. */package examples.addressbook;import java.lang.*;import java.io.*;import java.util.*;import javax.microedition.rms.*;/** * This class implements the RecordFilter interface. * It works on the records created by SimpleRecord. * It filters on first name and/or last name. */public class SimpleFilter implements RecordFilter {    // first and last names on which to filter    private String first;    private String last;    /**     * Public constructor: stores the first and last     * names on which to filter. Stores first/last     * names as lower case so that filters are     * are case-insensitive.     */    public SimpleFilter(String f, String l) {        first = f.toLowerCase();        last = l.toLowerCase();    }    /**     * Takes a record, (r), and checks to see if it matches     * the first and last name set in our constructor.     *     * Extracts the first and last names from the record,     * converts them to lower case, then compares them     * with the values extracted from the record.     *     * return true if record matches, false otherwise    */    public boolean matches(byte[] r) {        String f = SimpleRecord.getFirstName(r).toLowerCase();        String l = SimpleRecord.getLastName(r).toLowerCase();        return f.startsWith(first) && l.startsWith(last);    }}

⌨️ 快捷键说明

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