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

📄 fulltextsearchalgorithm.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
字号:
//#condition MUJMAIL_SEARCH/*MujMail - Simple mail client for J2MECopyright (C) 2008 David Hauzar <david.hauzar.mujmail@gmail.com>This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package mujmail.search;/** * Represents search algorithm that do search of substring in string. * * The instance of object implementing this interface is used in {@link mujmail.search.FulltextSearcher} * that instance returned by method {@link mujmail.search.SearchCore#getFulltextSearcher} * is used in all fulltext searching. * search. * * To implement new algorithm for fulltext searching, implement this interface. * To make new search algorithm used while searching, create instance of class * {@link mujmail.search.FulltextSearcher} with new search algorithm as the * parameter and make method {@link mujmail.search.SearchCore#getFulltextSearcher} * to return this instance. *  * @author David Hauzar */interface FulltextSearchAlgorithm {        /**     * Finds first occurrence of the searchPhrase in the string searchedString.     *     * Classes implementing this interface can implement searching with various     * wildcards, etc.     *      * @param searchedString the stirng that will be searched      * @param searchPhrase the phrase to be searched.     * @return the first location of the searchPhrase in the searchedString.     *  SubstringLocation.NO_LOCATION if the searchPhrase is not in the     *  searchedString     */    SubstringLocation findInStringFirstMatch(String searchedString, String searchPhrase);        /**     * Represents location of some substring in some string.     */    static class SubstringLocation {        /** If the substring is not located in given string. */        public static final SubstringLocation NO_LOCATION = new SubstringLocation(-1, -1);                /** The first letter of the substring in string. */        final int firstLetter;        /** The last letter of the substring in string. */        final int lastLetter;                SubstringLocation(int firstLetter, int lastLetter) {            this.firstLetter = firstLetter;            this.lastLetter = lastLetter;        }    }        /**     * Implementation of FulltextSearchAlgorithm that uses standard Java     * String.indexOf method.     * Does not use any wildcards.     */    class DefaultFulltextSearchAlgorithm implements FulltextSearchAlgorithm {        public SubstringLocation findInStringFirstMatch(String searchedString, String searchPhrase) {            // ignore case            searchedString = searchedString.toLowerCase();            searchPhrase = searchPhrase.toLowerCase();                        // find the match            int startLetter = searchedString.indexOf(searchPhrase);            if (startLetter == -1) {                return SubstringLocation.NO_LOCATION;            }            int lastLetter = startLetter + searchPhrase.length() - 1;            // return the occurrence            return new SubstringLocation(startLetter, lastLetter);        }            }}

⌨️ 快捷键说明

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