本文整理汇总了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;
}
示例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);
}