Home | History | Annotate | Download | only in apicoverage
      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.cts.apicoverage;
     18 
     19 import java.util.Collection;
     20 import java.util.Collections;
     21 import java.util.HashMap;
     22 import java.util.Map;
     23 
     24 /** Representation of a package in the API containing classes. */
     25 class ApiPackage implements HasCoverage {
     26 
     27     private final String mName;
     28 
     29     private final Map<String, ApiClass> mApiClassMap = new HashMap<String, ApiClass>();
     30 
     31     ApiPackage(String name) {
     32         this.mName = name;
     33     }
     34 
     35     public String getName() {
     36         return mName;
     37     }
     38 
     39     public void addClass(ApiClass apiClass) {
     40         mApiClassMap.put(apiClass.getName(), apiClass);
     41     }
     42 
     43     public ApiClass getClass(String name) {
     44         return mApiClassMap.get(name);
     45     }
     46 
     47     public Collection<ApiClass> getClasses() {
     48         return Collections.unmodifiableCollection(mApiClassMap.values());
     49     }
     50 
     51     public int getNumCoveredMethods() {
     52         int covered = 0;
     53         for (ApiClass apiClass : mApiClassMap.values()) {
     54             covered += apiClass.getNumCoveredMethods();
     55         }
     56         return covered;
     57     }
     58 
     59     public int getTotalMethods() {
     60         int total = 0;
     61         for (ApiClass apiClass : mApiClassMap.values()) {
     62             total += apiClass.getTotalMethods();
     63         }
     64         return total;
     65     }
     66 
     67     public float getCoveragePercentage() {
     68         return (float) getNumCoveredMethods() / getTotalMethods() * 100;
     69     }
     70 }