If you think the Android project sqlite-provider 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
package novoda.lib.sqliteprovider.util;
//www.java2s.comimport android.net.Uri;
import java.util.*;
publicclass UriUtils {
privatestatic Map<String, String> mappedIds = new HashMap<String, String>();
publicstatic UriUtils from(Uri uri) {
UriUtils utils = new UriUtils();
final List<String> segs = uri.getPathSegments();
String parent = "";
for (int i = 0; i < segs.size(); i++) {
String currentSeg = segs.get(i);
if (isNumeric(currentSeg)) {
finalint children = Integer.parseInt(currentSeg);
for (int l = 0; l < children; l++) {
mappedIds.put(parent, currentSeg);
}
} else {
parent = currentSeg;
}
}
return utils;
}
publicstaticboolean isNumeric(String numericChar) {
try {
Integer.parseInt(numericChar);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
publicstaticboolean isNumberedEntryWithinCollection(final Uri uri) {
return isNumeric(uri.getLastPathSegment());
}
publicstaticboolean isDir(final Uri uri) {
return isDir("", uri);
}
publicstaticboolean isDir(final String rootPath, final Uri uri) {
return !isItem(rootPath, uri);
}
publicstaticboolean isItem(final Uri uri) {
return isItem("", uri);
}
publicstaticboolean isItem(final String rootPath, final Uri uri) {
final List<String> segments = uri.getPathSegments();
if (rootPath != null && !"".equals(rootPath)) {
return (((segments.size() - rootPath.split("/").length + 1) % 2) == 1);
}
return ((segments.size() % 2) == 0);
}
publicstatic String getItemDirID(final Uri uri) {
return getItemDirID("", uri);
}
publicstatic String getItemDirID(final String rootPath, final Uri uri) {
final List<String> segments = uri.getPathSegments();
if (isItem(rootPath, uri)) {
return segments.get(segments.size() - 2);
}
return uri.getLastPathSegment();
}
publicstaticboolean hasParent(Uri uri) {
if (uri.getPathSegments().size() > 2) {
return true;
}
return false;
}
publicstatic String getParentColumnName(Uri uri) {
if (hasParent(uri)) {
if (!isNumberedEntryWithinCollection(uri)) {
return uri.getPathSegments().get((uri.getPathSegments().size() - 1) - 2);
}
return uri.getPathSegments().get((uri.getPathSegments().size() - 1) - 3);
}
return"";
}
publicstatic String getParentId(Uri uri) {
if (hasParent(uri)) {
if (!isNumberedEntryWithinCollection(uri)) {
return uri.getPathSegments().get((uri.getPathSegments().size() - 1) - 1);
}
return uri.getPathSegments().get((uri.getPathSegments().size() - 1) - 2);
}
return"";
}
public Map<String, String> getMappedIds() {
return mappedIds;
}
}