当前位置: 首页>>代码示例>>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;未经允许,请勿转载。