當前位置: 首頁>>代碼示例>>Java>>正文


Java UriMatcher.match方法代碼示例

本文整理匯總了Java中android.content.UriMatcher.match方法的典型用法代碼示例。如果您正苦於以下問題:Java UriMatcher.match方法的具體用法?Java UriMatcher.match怎麽用?Java UriMatcher.match使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.UriMatcher的用法示例。


在下文中一共展示了UriMatcher.match方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createFromContentProviderResults

import android.content.UriMatcher; //導入方法依賴的package包/類
@Nullable
public static DatabaseIdRange createFromContentProviderResults(ContentProviderResult[] results, String path){
    UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    sUriMatcher.addURI(MessengerContentProvider.AUTHORITY, path, MATCH_CODE);

    Integer f = null;
    Integer l = null;
    for(ContentProviderResult result : results){
        if(result.uri != null && !result.uri.toString().isEmpty()){
            if(sUriMatcher.match(result.uri) != MATCH_CODE){
                continue;
            }

            int dbid = Integer.parseInt(result.uri.getPathSegments().get(1));
            if(f == null || dbid < f){
                f = dbid;
            }

            if(l == null || dbid > l){
                l = dbid;
            }
        }
    }

    return nonNull(f) && nonNull(l) ? new DatabaseIdRange(f, l) : null;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:27,代碼來源:DatabaseIdRange.java

示例2: testUriMatcher

import android.content.UriMatcher; //導入方法依賴的package包/類
/**
 * This function tests that the UriMatcher returns the correct integer value for
 * each of the Uri types that the ContentProvider can handle. Uncomment this when you are
 * ready to test your UriMatcher.
 */
@Test
public void testUriMatcher() {

    /* Create a URI matcher that the TaskContentProvider uses */
    UriMatcher testMatcher = TaskContentProvider.buildUriMatcher();

    /* Test that the code returned from our matcher matches the expected TASKS int */
    String tasksUriDoesNotMatch = "Error: The TASKS URI was matched incorrectly.";
    int actualTasksMatchCode = testMatcher.match(TEST_TASKS);
    int expectedTasksMatchCode = TaskContentProvider.TASKS;
    assertEquals(tasksUriDoesNotMatch,
            actualTasksMatchCode,
            expectedTasksMatchCode);

    /* Test that the code returned from our matcher matches the expected TASK_WITH_ID */
    String taskWithIdDoesNotMatch =
            "Error: The TASK_WITH_ID URI was matched incorrectly.";
    int actualTaskWithIdCode = testMatcher.match(TEST_TASK_WITH_ID);
    int expectedTaskWithIdCode = TaskContentProvider.TASK_WITH_ID;
    assertEquals(taskWithIdDoesNotMatch,
            actualTaskWithIdCode,
            expectedTaskWithIdCode);
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:29,代碼來源:TestTaskContentProvider.java


注:本文中的android.content.UriMatcher.match方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。