本文整理匯總了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);
}