Android Open Source - EBrowser Url Suggestion Item






From Project

Back to project page EBrowser.

License

The source code is released under:

GNU General Public License

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/*  ww w  . j  a  va  2  s  .  c  om*/
 * 
 * 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.
 */
public class UrlSuggestionItem {

  private static final float TITLE_COEFFICIENT = 2;
  private static final float URL_COEFFICIENT = 1;
  
  private static final float BOOKMARK_COEFFICIENT = 3;
  private static final float WEAVE_COEFFICIENT = 1;
  private static final float HISTORY_COEFFICIENT = 1;
  
  private String mPattern;
  private String mTitle;
  private String mUrl;
  private int mType;
  
  private float mNote;
  private boolean 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.
   */
  public int getType() {
    return mType;
  }
  
  /**
   * Get the note of this item. Compute it if not already done.
   * @return The note.
   */
  public float 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.
   */
  private void 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;
    }
    
  }
  
}




Java Source Code List

org.emergent.android.weave.client.Base32.java
org.emergent.android.weave.client.Base64Encoder.java
org.emergent.android.weave.client.Base64.java
org.emergent.android.weave.client.BulkKeyCouplet.java
org.emergent.android.weave.client.Dbg.java
org.emergent.android.weave.client.HexEncoder.java
org.emergent.android.weave.client.Hex.java
org.emergent.android.weave.client.QueryParams.java
org.emergent.android.weave.client.QueryResult.java
org.emergent.android.weave.client.UserWeave.java
org.emergent.android.weave.client.WeaveAccountInfo.java
org.emergent.android.weave.client.WeaveBasicObject.java
org.emergent.android.weave.client.WeaveConstants.java
org.emergent.android.weave.client.WeaveCryptoUtil.java
org.emergent.android.weave.client.WeaveException.java
org.emergent.android.weave.client.WeaveFactory.java
org.emergent.android.weave.client.WeaveHeader.java
org.emergent.android.weave.client.WeaveResponse.java
org.emergent.android.weave.client.WeaveSSLSocketFactory.java
org.emergent.android.weave.client.WeaveTransport.java
org.emergent.android.weave.client.WeaveUtil.java
org.greendroid.QuickActionGrid.java
org.greendroid.QuickActionWidget.java
org.greendroid.QuickAction.java
org.zirco.controllers.Controller.java
org.zirco.events.EventConstants.java
org.zirco.events.EventController.java
org.zirco.events.IDownloadEventsListener.java
org.zirco.model.DbAdapter.java
org.zirco.model.UrlSuggestionItemComparator.java
org.zirco.model.adapters.BookmarksCursorAdapter.java
org.zirco.model.adapters.DownloadListAdapter.java
org.zirco.model.adapters.HistoryExpandableListAdapter.java
org.zirco.model.adapters.UrlSuggestionCursorAdapter.java
org.zirco.model.adapters.WeaveBookmarksCursorAdapter.java
org.zirco.model.items.BookmarkItem.java
org.zirco.model.items.DownloadItem.java
org.zirco.model.items.HistoryItem.java
org.zirco.model.items.UrlSuggestionItem.java
org.zirco.model.items.WeaveBookmarkItem.java
org.zirco.providers.BookmarksProviderWrapper.java
org.zirco.providers.WeaveColumns.java
org.zirco.providers.WeaveContentProvider.java
org.zirco.providers.ZircoBookmarksContentProvider.java
org.zirco.sync.ISyncListener.java
org.zirco.sync.WeaveSyncTask.java
org.zirco.ui.activities.AboutActivity.java
org.zirco.ui.activities.AdBlockerWhiteListActivity.java
org.zirco.ui.activities.BookmarksHistoryActivity.java
org.zirco.ui.activities.BookmarksListActivity.java
org.zirco.ui.activities.ChangelogActivity.java
org.zirco.ui.activities.DownloadsListActivity.java
org.zirco.ui.activities.EditBookmarkActivity.java
org.zirco.ui.activities.HistoryListActivity.java
org.zirco.ui.activities.IToolbarsContainer.java
org.zirco.ui.activities.MainActivity.java
org.zirco.ui.activities.MobileViewListActivity.java
org.zirco.ui.activities.WeaveBookmarksListActivity.java
org.zirco.ui.activities.preferences.BaseSpinnerCustomPreferenceActivity.java
org.zirco.ui.activities.preferences.HomepagePreferenceActivity.java
org.zirco.ui.activities.preferences.PreferencesActivity.java
org.zirco.ui.activities.preferences.SearchUrlPreferenceActivity.java
org.zirco.ui.activities.preferences.UserAgentPreferenceActivity.java
org.zirco.ui.activities.preferences.WeavePreferencesActivity.java
org.zirco.ui.activities.preferences.WeaveServerPreferenceActivity.java
org.zirco.ui.components.CustomWebViewClient.java
org.zirco.ui.components.CustomWebView.java
org.zirco.ui.runnables.DownloadRunnable.java
org.zirco.ui.runnables.FaviconUpdaterRunnable.java
org.zirco.ui.runnables.HideToolbarsRunnable.java
org.zirco.ui.runnables.HistoryUpdater.java
org.zirco.ui.runnables.XmlHistoryBookmarksExporter.java
org.zirco.ui.runnables.XmlHistoryBookmarksImporter.java
org.zirco.utils.AnimationManager.java
org.zirco.utils.ApplicationUtils.java
org.zirco.utils.Constants.java
org.zirco.utils.DateUtils.java
org.zirco.utils.IOUtils.java
org.zirco.utils.ProxyChangeReceiver.java
org.zirco.utils.ProxySettings.java
org.zirco.utils.UrlUtils.java