If you think the Android project EBrowser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Zirco Browser for Android/*www.java2s.com*/
*
* Copyright (C) 2010 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/package org.zirco.model.items;
/**
* Store a suggestion item.
*/publicclass UrlSuggestionItem {
privatestaticfinalfloat TITLE_COEFFICIENT = 2;
privatestaticfinalfloat URL_COEFFICIENT = 1;
privatestaticfinalfloat BOOKMARK_COEFFICIENT = 3;
privatestaticfinalfloat WEAVE_COEFFICIENT = 1;
privatestaticfinalfloat HISTORY_COEFFICIENT = 1;
private String mPattern;
private String mTitle;
private String mUrl;
privateint mType;
privatefloat mNote;
privateboolean mNoteComputed = false;
/**
* Constructor.
* @param pattern The parent pattern.
* @param title The item's title.
* @param url The item's url.
* @param type The item's type (1 -> history, 2 -> bookmark).
*/public UrlSuggestionItem(String pattern, String title, String url, int type) {
mPattern = pattern;
mTitle = title;
mUrl = url;
mType = type;
}
/**
* Get the item's title.
* @return The title.
*/public String getTitle() {
return mTitle;
}
/**
* Get the item's url.
* @return The url.
*/public String getUrl() {
return mUrl;
}
/**
* Get the item's type.
* @return The type.
*/publicint getType() {
return mType;
}
/**
* Get the note of this item. Compute it if not already done.
* @return The note.
*/publicfloat getNote() {
if (!mNoteComputed) {
computeNote();
mNoteComputed = true;
}
return mNote;
}
/**
* Compute the note of the current item.
* The principle is to count the number of occurence of the pattern in the title and in the url, and to do a weighted sum.
* A match in title weight more than a match in url, and a match in bookmark weight more than a match in history.
*/privatevoid computeNote() {
String pattern = mPattern.toLowerCase();
// Count the number of match in a string, did not find a cleaner way.
int titleMatchCount;
String title = mTitle.toLowerCase();
if (title.equals(pattern)) {
titleMatchCount = 1;
} else {
titleMatchCount = title.split(pattern).length - 1;
}
String url = mUrl.toLowerCase();
int urlMatchCount = url.split("\\Q" + pattern + "\\E").length - 1;
mNote = (titleMatchCount * TITLE_COEFFICIENT) + (urlMatchCount * URL_COEFFICIENT);
switch(mType) {
case 1: mNote = mNote * HISTORY_COEFFICIENT; break;
case 2: mNote = mNote * BOOKMARK_COEFFICIENT; break;
case 3: mNote = mNote * WEAVE_COEFFICIENT; break;
default: break;
}
}
}