Example usage for android.util ArrayMap remove

List of usage examples for android.util ArrayMap remove

Introduction

In this page you can find the example usage for android.util ArrayMap remove.

Prototype

@Override
public V remove(Object key) 

Source Link

Document

Remove an existing key from the array map.

Usage

From source file:android.content.pm.PackageParser.java

private static PackageLite parseClusterPackageLite(File packageDir, int flags) throws PackageParserException {
    final File[] files = packageDir.listFiles();
    if (ArrayUtils.isEmpty(files)) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, "No packages found in split");
    }/*  w w  w. j ava2 s  .c  o  m*/

    String packageName = null;
    int versionCode = 0;

    final ArrayMap<String, ApkLite> apks = new ArrayMap<>();
    for (File file : files) {
        if (isApkFile(file)) {
            final ApkLite lite = parseApkLite(file, flags);

            // Assert that all package names and version codes are
            // consistent with the first one we encounter.
            if (packageName == null) {
                packageName = lite.packageName;
                versionCode = lite.versionCode;
            } else {
                if (!packageName.equals(lite.packageName)) {
                    throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, "Inconsistent package "
                            + lite.packageName + " in " + file + "; expected " + packageName);
                }
                if (versionCode != lite.versionCode) {
                    throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST, "Inconsistent version "
                            + lite.versionCode + " in " + file + "; expected " + versionCode);
                }
            }

            // Assert that each split is defined only once
            if (apks.put(lite.splitName, lite) != null) {
                throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST,
                        "Split name " + lite.splitName + " defined more than once; most recent was " + file);
            }
        }
    }

    final ApkLite baseApk = apks.remove(null);
    if (baseApk == null) {
        throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST,
                "Missing base APK in " + packageDir);
    }

    // Always apply deterministic ordering based on splitName
    final int size = apks.size();

    String[] splitNames = null;
    String[] splitCodePaths = null;
    int[] splitRevisionCodes = null;
    if (size > 0) {
        splitNames = new String[size];
        splitCodePaths = new String[size];
        splitRevisionCodes = new int[size];

        splitNames = apks.keySet().toArray(splitNames);
        Arrays.sort(splitNames, sSplitNameComparator);

        for (int i = 0; i < size; i++) {
            splitCodePaths[i] = apks.get(splitNames[i]).codePath;
            splitRevisionCodes[i] = apks.get(splitNames[i]).revisionCode;
        }
    }

    final String codePath = packageDir.getAbsolutePath();
    return new PackageLite(codePath, baseApk, splitNames, splitCodePaths, splitRevisionCodes);
}