Home | History | Annotate | Download | only in apkcheck
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.apkcheck;
     18 
     19 import java.util.HashMap;
     20 import java.util.Iterator;
     21 
     22 /**
     23  * Holds a list of API members, including classes, fields, and methods.
     24  */
     25 public class ApiList {
     26     private HashMap<String,PackageInfo> mPackageList;
     27     private String mDebugString;
     28     private int mWarnings, mErrors;
     29 
     30     /**
     31      * Constructs an ApiList.
     32      *
     33      * @param debugString Identification string useful for debugging.
     34      */
     35     public ApiList(String debugString) {
     36         mPackageList = new HashMap<String,PackageInfo>();
     37         mDebugString = debugString;
     38     }
     39 
     40     /**
     41      * Returns the source filename.  Useful for debug messages only.
     42      */
     43     public String getDebugString() {
     44         return mDebugString;
     45     }
     46 
     47     /**
     48      * Increment the number of warnings associated with this API list.
     49      */
     50     public void incrWarnings() {
     51         mWarnings++;
     52     }
     53 
     54     /**
     55      * Increment the errors of warnings associated with this API list.
     56      */
     57     public void incrErrors() {
     58         mErrors++;
     59     }
     60 
     61     /**
     62      * Returns the number of warnings associated with this API list.
     63      */
     64     public int getWarningCount() {
     65         return mWarnings;
     66     }
     67 
     68     /**
     69      * Returns the number of errors associated with this API list.
     70      */
     71     public int getErrorCount() {
     72         return mErrors;
     73     }
     74 
     75     /**
     76      * Retrieves the named package.
     77      *
     78      * @return the package, or null if no match was found
     79      */
     80     public PackageInfo getPackage(String name) {
     81         return mPackageList.get(name);
     82     }
     83 
     84     /**
     85      * Retrieves the named package, creating it if it doesn't already
     86      * exist.
     87      */
     88     public PackageInfo getOrCreatePackage(String name) {
     89         PackageInfo pkgInfo = mPackageList.get(name);
     90         if (pkgInfo == null) {
     91             pkgInfo = new PackageInfo(name);
     92             mPackageList.put(name, pkgInfo);
     93         }
     94         return pkgInfo;
     95     }
     96 
     97     /**
     98      * Returns an iterator for the set of known packages.
     99      */
    100     public Iterator<PackageInfo> getPackageIterator() {
    101         return mPackageList.values().iterator();
    102     }
    103 }
    104 
    105