private String getDocIdForFile(File file) throws FileNotFoundException { String path = file.getAbsolutePath(); // Find the most-specific root path String mostSpecificId = null; String mostSpecificPath = null; synchronized (mRootsLock) { for (int i = 0; i < mRoots.size(); i++) { final String rootId = mRoots.keyAt(i); final String rootPath = mRoots.valueAt(i).path.getAbsolutePath(); if (path.startsWith(rootPath) && (mostSpecificPath == null || rootPath.length() > mostSpecificPath.length())) { mostSpecificId = rootId; mostSpecificPath = rootPath; } } } if (mostSpecificPath == null) { throw new FileNotFoundException("Failed to find root that contains " + path); } // Start at first char of path under root final String rootPath = mostSpecificPath; if (rootPath.equals(path)) { path = ""; } else if (rootPath.endsWith("/")) { path = path.substring(rootPath.length()); } else { path = path.substring(rootPath.length() + 1); } return mostSpecificId + ':' + path; }
/** * Perform a {@link #put(Object, Object)} of all key/value pairs in <var>array</var> * * @param array The array whose contents are to be retrieved. */ public void putAll(ArrayMap<? extends K, ? extends V> array) { final int N = array.mSize; ensureCapacity(mSize + N); if (mSize == 0) { if (N > 0) { System.arraycopy(array.mHashes, 0, mHashes, 0, N); System.arraycopy(array.mArray, 0, mArray, 0, N << 1); mSize = N; } } else { for (int i = 0; i < N; i++) { put(array.keyAt(i), array.valueAt(i)); } } }
boolean dumpMap( PrintWriter out, String titlePrefix, String title, String prefix, ArrayMap<String, F[]> map, String packageName, boolean printFilter, boolean collapseDuplicates) { final String eprefix = prefix + " "; final String fprefix = prefix + " "; final ArrayMap<Object, MutableInt> found = new ArrayMap<>(); boolean printedSomething = false; Printer printer = null; for (int mapi = 0; mapi < map.size(); mapi++) { F[] a = map.valueAt(mapi); final int N = a.length; boolean printedHeader = false; F filter; if (collapseDuplicates && !printFilter) { found.clear(); for (int i = 0; i < N && (filter = a[i]) != null; i++) { if (packageName != null && !isPackageForFilter(packageName, filter)) { continue; } Object label = filterToLabel(filter); int index = found.indexOfKey(label); if (index < 0) { found.put(label, new MutableInt(1)); } else { found.valueAt(index).value++; } } for (int i = 0; i < found.size(); i++) { if (title != null) { out.print(titlePrefix); out.println(title); title = null; } if (!printedHeader) { out.print(eprefix); out.print(map.keyAt(mapi)); out.println(":"); printedHeader = true; } printedSomething = true; dumpFilterLabel(out, fprefix, found.keyAt(i), found.valueAt(i).value); } } else { for (int i = 0; i < N && (filter = a[i]) != null; i++) { if (packageName != null && !isPackageForFilter(packageName, filter)) { continue; } if (title != null) { out.print(titlePrefix); out.println(title); title = null; } if (!printedHeader) { out.print(eprefix); out.print(map.keyAt(mapi)); out.println(":"); printedHeader = true; } printedSomething = true; dumpFilter(out, fprefix, filter); if (printFilter) { if (printer == null) { printer = new PrintWriterPrinter(out); } filter.dump(printer, fprefix + " "); } } } } return printedSomething; }